Skip to content

Commit ad524f8

Browse files
committed
Merge branch 'jk/misc-fixes-maint'
* jk/misc-fixes-maint: apply: avoid possible bogus pointer fix memory leak parsing core.commentchar transport: fix leaks in refs_from_alternate_cb free ref string returned by dwim_ref receive-pack: don't copy "dir" parameter
2 parents 919eb8a + 31bb6d3 commit ad524f8

File tree

7 files changed

+16
-13
lines changed

7 files changed

+16
-13
lines changed

builtin/apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ static int gitdiff_index(const char *line, struct patch *patch)
10751075

10761076
line = ptr + 2;
10771077
ptr = strchr(line, ' ');
1078-
eol = strchr(line, '\n');
1078+
eol = strchrnul(line, '\n');
10791079

10801080
if (!ptr || eol < ptr)
10811081
ptr = eol;

builtin/receive-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
11221122
int advertise_refs = 0;
11231123
int stateless_rpc = 0;
11241124
int i;
1125-
char *dir = NULL;
1125+
const char *dir = NULL;
11261126
struct command *commands;
11271127
struct sha1_array shallow = SHA1_ARRAY_INIT;
11281128
struct sha1_array ref = SHA1_ARRAY_INIT;
@@ -1157,7 +1157,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
11571157
}
11581158
if (dir)
11591159
usage(receive_pack_usage);
1160-
dir = xstrdup(arg);
1160+
dir = arg;
11611161
}
11621162
if (!dir)
11631163
usage(receive_pack_usage);

builtin/rev-parse.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)
151151
error("refname '%s' is ambiguous", name);
152152
break;
153153
}
154+
free(full);
154155
} else {
155156
show_with_type(type, name);
156157
}

builtin/show-branch.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
777777
sprintf(nth_desc, "%s@{%d}", *av, base+i);
778778
append_ref(nth_desc, sha1, 1);
779779
}
780+
free(ref);
780781
}
781782
else if (all_heads + all_remotes)
782783
snarf_refs(all_heads, all_remotes);

config.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -817,14 +817,12 @@ static int git_default_core_config(const char *var, const char *value)
817817
return git_config_string(&editor_program, var, value);
818818

819819
if (!strcmp(var, "core.commentchar")) {
820-
const char *comment;
821-
int ret = git_config_string(&comment, var, value);
822-
if (ret)
823-
return ret;
824-
else if (!strcasecmp(comment, "auto"))
820+
if (!value)
821+
return config_error_nonbool(var);
822+
else if (!strcasecmp(value, "auto"))
825823
auto_comment_line_char = 1;
826-
else if (comment[0] && !comment[1]) {
827-
comment_line_char = comment[0];
824+
else if (value[0] && !value[1]) {
825+
comment_line_char = value[0];
828826
auto_comment_line_char = 0;
829827
} else
830828
return error("core.commentChar should only be one character");

sha1_name.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,10 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
540540
char *tmp = xstrndup(str + at + 2, reflog_len);
541541
at_time = approxidate_careful(tmp, &errors);
542542
free(tmp);
543-
if (errors)
543+
if (errors) {
544+
free(real_ref);
544545
return -1;
546+
}
545547
}
546548
if (read_ref_at(real_ref, at_time, nth, sha1, NULL,
547549
&co_time, &co_tz, &co_cnt)) {

transport.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,11 +1357,11 @@ static int refs_from_alternate_cb(struct alternate_object_database *e,
13571357
while (other[len-1] == '/')
13581358
other[--len] = '\0';
13591359
if (len < 8 || memcmp(other + len - 8, "/objects", 8))
1360-
return 0;
1360+
goto out;
13611361
/* Is this a git repository with refs? */
13621362
memcpy(other + len - 8, "/refs", 6);
13631363
if (!is_directory(other))
1364-
return 0;
1364+
goto out;
13651365
other[len - 8] = '\0';
13661366
remote = remote_get(other);
13671367
transport = transport_get(remote, other);
@@ -1370,6 +1370,7 @@ static int refs_from_alternate_cb(struct alternate_object_database *e,
13701370
extra = extra->next)
13711371
cb->fn(extra, cb->data);
13721372
transport_disconnect(transport);
1373+
out:
13731374
free(other);
13741375
return 0;
13751376
}

0 commit comments

Comments
 (0)