Skip to content

Commit

Permalink
Merge branch 'jk/misc-fixes-maint'
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Junio C Hamano committed Jul 28, 2014
2 parents 919eb8a + 31bb6d3 commit ad524f8
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion builtin/apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ static int gitdiff_index(const char *line, struct patch *patch)

line = ptr + 2;
ptr = strchr(line, ' ');
eol = strchr(line, '\n');
eol = strchrnul(line, '\n');

if (!ptr || eol < ptr)
ptr = eol;
Expand Down
4 changes: 2 additions & 2 deletions builtin/receive-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
int advertise_refs = 0;
int stateless_rpc = 0;
int i;
char *dir = NULL;
const char *dir = NULL;
struct command *commands;
struct sha1_array shallow = SHA1_ARRAY_INIT;
struct sha1_array ref = SHA1_ARRAY_INIT;
Expand Down Expand Up @@ -1157,7 +1157,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
}
if (dir)
usage(receive_pack_usage);
dir = xstrdup(arg);
dir = arg;
}
if (!dir)
usage(receive_pack_usage);
Expand Down
1 change: 1 addition & 0 deletions builtin/rev-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)
error("refname '%s' is ambiguous", name);
break;
}
free(full);
} else {
show_with_type(type, name);
}
Expand Down
1 change: 1 addition & 0 deletions builtin/show-branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
sprintf(nth_desc, "%s@{%d}", *av, base+i);
append_ref(nth_desc, sha1, 1);
}
free(ref);
}
else if (all_heads + all_remotes)
snarf_refs(all_heads, all_remotes);
Expand Down
12 changes: 5 additions & 7 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,14 +817,12 @@ static int git_default_core_config(const char *var, const char *value)
return git_config_string(&editor_program, var, value);

if (!strcmp(var, "core.commentchar")) {
const char *comment;
int ret = git_config_string(&comment, var, value);
if (ret)
return ret;
else if (!strcasecmp(comment, "auto"))
if (!value)
return config_error_nonbool(var);
else if (!strcasecmp(value, "auto"))
auto_comment_line_char = 1;
else if (comment[0] && !comment[1]) {
comment_line_char = comment[0];
else if (value[0] && !value[1]) {
comment_line_char = value[0];
auto_comment_line_char = 0;
} else
return error("core.commentChar should only be one character");
Expand Down
4 changes: 3 additions & 1 deletion sha1_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,10 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
char *tmp = xstrndup(str + at + 2, reflog_len);
at_time = approxidate_careful(tmp, &errors);
free(tmp);
if (errors)
if (errors) {
free(real_ref);
return -1;
}
}
if (read_ref_at(real_ref, at_time, nth, sha1, NULL,
&co_time, &co_tz, &co_cnt)) {
Expand Down
5 changes: 3 additions & 2 deletions transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -1357,11 +1357,11 @@ static int refs_from_alternate_cb(struct alternate_object_database *e,
while (other[len-1] == '/')
other[--len] = '\0';
if (len < 8 || memcmp(other + len - 8, "/objects", 8))
return 0;
goto out;
/* Is this a git repository with refs? */
memcpy(other + len - 8, "/refs", 6);
if (!is_directory(other))
return 0;
goto out;
other[len - 8] = '\0';
remote = remote_get(other);
transport = transport_get(remote, other);
Expand All @@ -1370,6 +1370,7 @@ static int refs_from_alternate_cb(struct alternate_object_database *e,
extra = extra->next)
cb->fn(extra, cb->data);
transport_disconnect(transport);
out:
free(other);
return 0;
}
Expand Down

0 comments on commit ad524f8

Please sign in to comment.