diff --git a/lib/util/util_paths.c b/lib/util/util_paths.c index ce93028d563..b35cc7f5863 100644 --- a/lib/util/util_paths.c +++ b/lib/util/util_paths.c @@ -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 ) {