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
This commit is contained in:
Junio C Hamano 2014-07-28 11:30:41 -07:00
commit ad524f834a
7 changed files with 16 additions and 13 deletions

View File

@ -1075,7 +1075,7 @@ static int gitdiff_index(const char *line, struct patch *patch)
line = ptr + 2; line = ptr + 2;
ptr = strchr(line, ' '); ptr = strchr(line, ' ');
eol = strchr(line, '\n'); eol = strchrnul(line, '\n');
if (!ptr || eol < ptr) if (!ptr || eol < ptr)
ptr = eol; ptr = eol;

View File

@ -1122,7 +1122,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
int advertise_refs = 0; int advertise_refs = 0;
int stateless_rpc = 0; int stateless_rpc = 0;
int i; int i;
char *dir = NULL; const char *dir = NULL;
struct command *commands; struct command *commands;
struct sha1_array shallow = SHA1_ARRAY_INIT; struct sha1_array shallow = SHA1_ARRAY_INIT;
struct sha1_array ref = SHA1_ARRAY_INIT; struct sha1_array ref = SHA1_ARRAY_INIT;
@ -1157,7 +1157,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
} }
if (dir) if (dir)
usage(receive_pack_usage); usage(receive_pack_usage);
dir = xstrdup(arg); dir = arg;
} }
if (!dir) if (!dir)
usage(receive_pack_usage); usage(receive_pack_usage);

View File

@ -151,6 +151,7 @@ static void show_rev(int type, const unsigned char *sha1, const char *name)
error("refname '%s' is ambiguous", name); error("refname '%s' is ambiguous", name);
break; break;
} }
free(full);
} else { } else {
show_with_type(type, name); show_with_type(type, name);
} }

View File

@ -777,6 +777,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
sprintf(nth_desc, "%s@{%d}", *av, base+i); sprintf(nth_desc, "%s@{%d}", *av, base+i);
append_ref(nth_desc, sha1, 1); append_ref(nth_desc, sha1, 1);
} }
free(ref);
} }
else if (all_heads + all_remotes) else if (all_heads + all_remotes)
snarf_refs(all_heads, all_remotes); snarf_refs(all_heads, all_remotes);

View File

@ -817,14 +817,12 @@ static int git_default_core_config(const char *var, const char *value)
return git_config_string(&editor_program, var, value); return git_config_string(&editor_program, var, value);
if (!strcmp(var, "core.commentchar")) { if (!strcmp(var, "core.commentchar")) {
const char *comment; if (!value)
int ret = git_config_string(&comment, var, value); return config_error_nonbool(var);
if (ret) else if (!strcasecmp(value, "auto"))
return ret;
else if (!strcasecmp(comment, "auto"))
auto_comment_line_char = 1; auto_comment_line_char = 1;
else if (comment[0] && !comment[1]) { else if (value[0] && !value[1]) {
comment_line_char = comment[0]; comment_line_char = value[0];
auto_comment_line_char = 0; auto_comment_line_char = 0;
} else } else
return error("core.commentChar should only be one character"); return error("core.commentChar should only be one character");

View File

@ -540,9 +540,11 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
char *tmp = xstrndup(str + at + 2, reflog_len); char *tmp = xstrndup(str + at + 2, reflog_len);
at_time = approxidate_careful(tmp, &errors); at_time = approxidate_careful(tmp, &errors);
free(tmp); free(tmp);
if (errors) if (errors) {
free(real_ref);
return -1; return -1;
} }
}
if (read_ref_at(real_ref, at_time, nth, sha1, NULL, if (read_ref_at(real_ref, at_time, nth, sha1, NULL,
&co_time, &co_tz, &co_cnt)) { &co_time, &co_tz, &co_cnt)) {
if (!len) { if (!len) {

View File

@ -1357,11 +1357,11 @@ static int refs_from_alternate_cb(struct alternate_object_database *e,
while (other[len-1] == '/') while (other[len-1] == '/')
other[--len] = '\0'; other[--len] = '\0';
if (len < 8 || memcmp(other + len - 8, "/objects", 8)) if (len < 8 || memcmp(other + len - 8, "/objects", 8))
return 0; goto out;
/* Is this a git repository with refs? */ /* Is this a git repository with refs? */
memcpy(other + len - 8, "/refs", 6); memcpy(other + len - 8, "/refs", 6);
if (!is_directory(other)) if (!is_directory(other))
return 0; goto out;
other[len - 8] = '\0'; other[len - 8] = '\0';
remote = remote_get(other); remote = remote_get(other);
transport = transport_get(remote, other); transport = transport_get(remote, other);
@ -1370,6 +1370,7 @@ static int refs_from_alternate_cb(struct alternate_object_database *e,
extra = extra->next) extra = extra->next)
cb->fn(extra, cb->data); cb->fn(extra, cb->data);
transport_disconnect(transport); transport_disconnect(transport);
out:
free(other); free(other);
return 0; return 0;
} }