ldconfig: Fix memory leaks

Coverity discovered that paths allocated by chroot_canon are not freed
in a couple of routines in ldconfig.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
This commit is contained in:
Siddhesh Poyarekar 2021-05-18 09:29:02 +05:30
parent c8c3c5e89a
commit 468d772e81
1 changed files with 14 additions and 6 deletions

View File

@ -709,16 +709,14 @@ manual_link (char *library)
if (lstat64 (real_library, &stat_buf)) if (lstat64 (real_library, &stat_buf))
{ {
error (0, errno, _("Cannot lstat %s"), library); error (0, errno, _("Cannot lstat %s"), library);
free (path); goto out;
return;
} }
/* We don't want links here! */ /* We don't want links here! */
else if (!S_ISREG (stat_buf.st_mode)) else if (!S_ISREG (stat_buf.st_mode))
{ {
error (0, 0, _("Ignored file %s since it is not a regular file."), error (0, 0, _("Ignored file %s since it is not a regular file."),
library); library);
free (path); goto out;
return;
} }
if (process_file (real_library, library, libname, &flag, &osversion, if (process_file (real_library, library, libname, &flag, &osversion,
@ -726,14 +724,16 @@ manual_link (char *library)
{ {
error (0, 0, _("No link created since soname could not be found for %s"), error (0, 0, _("No link created since soname could not be found for %s"),
library); library);
free (path); goto out;
return;
} }
if (soname == NULL) if (soname == NULL)
soname = implicit_soname (libname, flag); soname = implicit_soname (libname, flag);
create_links (real_path, path, libname, soname); create_links (real_path, path, libname, soname);
free (soname); free (soname);
out:
free (path); free (path);
if (path != real_path)
free (real_path);
} }
@ -920,8 +920,16 @@ search_dir (const struct dir_entry *entry)
/* Remove stale symlinks. */ /* Remove stale symlinks. */
if (opt_link && strstr (direntry->d_name, ".so.")) if (opt_link && strstr (direntry->d_name, ".so."))
unlink (real_file_name); unlink (real_file_name);
if (opt_chroot != NULL)
free (target_name);
continue; continue;
} }
if (opt_chroot != NULL)
free (target_name);
is_dir = S_ISDIR (stat_buf.st_mode); is_dir = S_ISDIR (stat_buf.st_mode);
/* lstat_buf is later stored, update contents. */ /* lstat_buf is later stored, update contents. */