]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib: Fix CID 1596761 Resource leak
authorVolker Lendecke <vl@samba.org>
Sun, 29 Sep 2024 07:58:13 +0000 (09:58 +0200)
committerVolker Lendecke <vl@samba.org>
Wed, 2 Oct 2024 13:12:30 +0000 (13:12 +0000)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
lib/util/util_paths.c

index ce93028d5630b078521de6836d2662b958458041..b35cc7f5863b7968965d758e4c7c7642ac2dd2da 100644 (file)
@@ -89,15 +89,17 @@ static char *get_user_home_dir(TALLOC_CTX *mem_ctx)
        rc = getpwuid_r(getuid(), &pwd, buf, len, &pwdbuf);
        while (rc == ERANGE) {
                size_t newlen = 2 * len;
+               char *tmp = NULL;
                if (newlen < len) {
                        /* Overflow */
                        goto done;
                }
                len = newlen;
-               buf = talloc_realloc_size(mem_ctx, buf, len);
-               if (buf == NULL) {
+               tmp = talloc_realloc_size(mem_ctx, buf, len);
+               if (tmp == NULL) {
                        goto done;
                }
+               buf = tmp;
                rc = getpwuid_r(getuid(), &pwd, buf, len, &pwdbuf);
        }
        if (rc != 0 || pwdbuf == NULL ) {