Skip to content

Commit

Permalink
common/common.c: nut_prepare_search_paths(): avoid an FD leak, and co…
Browse files Browse the repository at this point in the history
…mment what we do about "dirname" with and without realpath() support

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Jul 11, 2024
1 parent 1532831 commit 6cb572d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -3087,6 +3087,9 @@ void nut_prepare_search_paths(void) {
dupe = 1;
#if HAVE_DECL_REALPATH
free((char *)dirname);
/* Have some valid value, for kicks (likely
* to be ignored in the code path below) */
dirname = search_paths_builtin[i];
#endif
break;
}
Expand All @@ -3097,10 +3100,17 @@ void nut_prepare_search_paths(void) {
"existing unique directory: %s",
__func__, count_filtered, dirname);
#if !HAVE_DECL_REALPATH
/* Make a copy of table entry, else we have
* a dynamic result of realpath() made above.
*/
dirname = (const char *)xstrdup(dirname);
#endif
filtered_search_paths[count_filtered++] = dirname;
}
} /* else: dirname was freed above (for realpath)
* or is a reference to the table entry; no need
* to free() it either way */

closedir(dp);
}

/* If we mangled this before, forget the old result: */
Expand Down

0 comments on commit 6cb572d

Please sign in to comment.