Fix a few issues in leaDBSearchForTech()

Always call closedir() after a successful opendir(), and always return
a value from function.
This commit is contained in:
Anton Blanchard 2023-01-16 15:56:02 +11:00 committed by Anton Blanchard
parent e4e115b23e
commit c89b0c1ff3
1 changed files with 10 additions and 3 deletions

View File

@ -194,7 +194,10 @@ DBSearchForTech(techname, pathroot, level)
if (tdent->d_type != DT_DIR)
{
if (!strcmp(tdent->d_name, techname))
{
closedir(tdir);
return pathroot;
}
}
else if (strcmp(tdent->d_name, ".") && strcmp(tdent->d_name, ".."))
{
@ -202,13 +205,17 @@ DBSearchForTech(techname, pathroot, level)
sprintf(newpath, "%s/%s", pathroot, tdent->d_name);
found = DBSearchForTech(techname, newpath, level + 1);
if (found != newpath) freeMagic(newpath);
if (found) return found;
if (found)
{
closedir(tdir);
return found;
}
}
}
closedir(tdir);
}
else
return NULL;
return NULL;
}
/*