Skip to content

Commit 5f338ea

Browse files
committed
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
2 parents 9d0e81e + 087740d commit 5f338ea

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

scalar.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ void load_builtin_commands(const char *prefix UNUSED,
409409
static int cmd_clone(int argc, const char **argv)
410410
{
411411
const char *branch = NULL;
412+
char *branch_to_free = NULL;
412413
int full_clone = 0, single_branch = 0, show_progress = isatty(2);
413414
int src = 1, tags = 1;
414415
struct option clone_options[] = {
@@ -490,7 +491,7 @@ static int cmd_clone(int argc, const char **argv)
490491
/* common-main already logs `argv` */
491492
trace2_def_repo(the_repository);
492493

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

554555
cleanup:
556+
free(branch_to_free);
555557
free(enlistment);
556558
free(dir);
557559
strbuf_release(&buf);

unix-socket.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ static int unix_sockaddr_init(struct sockaddr_un *sa, const char *path,
6565
if (strbuf_getcwd(&cwd))
6666
return -1;
6767
ctx->orig_dir = strbuf_detach(&cwd, NULL);
68-
if (chdir_len(dir, slash - dir) < 0)
68+
if (chdir_len(dir, slash - dir) < 0) {
69+
FREE_AND_NULL(ctx->orig_dir);
6970
return -1;
71+
}
7072
}
7173

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

0 commit comments

Comments
 (0)