Merge branch 'ps/leakfixes-0129'

A few more leakfixes.

* ps/leakfixes-0129:
  scalar: free result of `remote_default_branch()`
  unix-socket: fix memory leak when chdir(3p) fails
maint
Junio C Hamano 2025-02-06 14:56:45 -08:00
commit 5f338eae76
2 changed files with 6 additions and 2 deletions

View File

@ -409,6 +409,7 @@ void load_builtin_commands(const char *prefix UNUSED,
static int cmd_clone(int argc, const char **argv)
{
const char *branch = NULL;
char *branch_to_free = NULL;
int full_clone = 0, single_branch = 0, show_progress = isatty(2);
int src = 1, tags = 1;
struct option clone_options[] = {
@ -490,7 +491,7 @@ static int cmd_clone(int argc, const char **argv)
/* common-main already logs `argv` */
trace2_def_repo(the_repository);

if (!branch && !(branch = remote_default_branch(url))) {
if (!branch && !(branch = branch_to_free = remote_default_branch(url))) {
res = error(_("failed to get default branch for '%s'"), url);
goto cleanup;
}
@ -552,6 +553,7 @@ static int cmd_clone(int argc, const char **argv)
res = register_dir();

cleanup:
free(branch_to_free);
free(enlistment);
free(dir);
strbuf_release(&buf);

View File

@ -65,8 +65,10 @@ static int unix_sockaddr_init(struct sockaddr_un *sa, const char *path,
if (strbuf_getcwd(&cwd))
return -1;
ctx->orig_dir = strbuf_detach(&cwd, NULL);
if (chdir_len(dir, slash - dir) < 0)
if (chdir_len(dir, slash - dir) < 0) {
FREE_AND_NULL(ctx->orig_dir);
return -1;
}
}

memset(sa, 0, sizeof(*sa));