]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
src/useradd.c: set_defaults(): Do not free(3) the result of asprintf(3) if it failed
authorAlejandro Colomar <alx@kernel.org>
Fri, 17 May 2024 11:10:46 +0000 (13:10 +0200)
committerAlejandro Colomar <alx@kernel.org>
Fri, 17 May 2024 23:15:10 +0000 (01:15 +0200)
See asprintf(3):

RETURN VALUE
     When successful,  these  functions  return  the  number  of  bytes
     printed, just like sprintf(3).  If memory allocation wasn’t possi‐
     ble,  or  some other error occurs, these functions will return -1,
     and the contents of strp are undefined.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
src/useradd.c

index bc72e6bca4661f077135f5babe44b43739dd8dce..6a3edfe3b5b61a89332ee9ad03087c3b90de7620 100644 (file)
@@ -558,7 +558,7 @@ static int set_defaults (void)
                        fprintf(stderr,
                                _("%s: cannot create new defaults file: %s\n"),
                                Prog, strerror(errno));
-                       goto err_free_def;
+                       goto err_free_new;
                }
        }
 
@@ -749,6 +749,7 @@ static int set_defaults (void)
 err_free_def:
        if (prefix[0])
                free(default_file);
+err_free_new:
        free(new_file);
 
        return ret;