]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Another ldelf_before_allocation leak
authorAlan Modra <amodra@gmail.com>
Tue, 21 Jan 2025 21:09:53 +0000 (07:39 +1030)
committerAlan Modra <amodra@gmail.com>
Thu, 23 Jan 2025 01:10:40 +0000 (11:40 +1030)
This fixes an even more obvious leak.

* ldelf.c (ldelf_before_allocation): Free copied elf_dt_audit.
Simplify loop.

ld/ldelf.c

index f56a62780f066220db4ffad8167c1380adc3fc40..dbc3d77d47b0c54c694fe6c410a76b443b621639 100644 (file)
@@ -1821,24 +1821,22 @@ ldelf_before_allocation (char **audit, char **depaudit,
           a dep audit entry.  */
        if (audit_libs && *audit_libs != '\0')
          {
-           char *cp = xstrdup (audit_libs);
+           char *copy_audit_libs = xstrdup (audit_libs);
+           char *cp = copy_audit_libs;
            do
              {
-               int more = 0;
                char *cp2 = strchr (cp, config.rpath_separator);
 
                if (cp2)
-                 {
-                   *cp2 = '\0';
-                   more = 1;
-                 }
+                 *cp2++ = '\0';
 
-               if (cp != NULL && *cp != '\0')
+               if (*cp != '\0')
                  ldelf_append_to_separated_string (depaudit, cp);
 
-               cp = more ? ++cp2 : NULL;
+               cp = cp2;
              }
            while (cp != NULL);
+           free (copy_audit_libs);
          }
       }