Merge branch 'sb/misc-cleanups' into HEAD

* sb/misc-cleanups:
  submodule-config: don't shadow `cache`
  config.c: drop local variable
  credential-cache, send_request: close fd when done
  bundle: don't leak an fd in case of early return
  abbrev_sha1_in_line: don't leak memory
  notes: don't leak memory in git_config_get_notes_strategy
This commit is contained in:
Junio C Hamano
2016-05-18 14:40:15 -07:00
6 changed files with 29 additions and 21 deletions

View File

@ -744,13 +744,14 @@ static int merge_commit(struct notes_merge_options *o)
static int git_config_get_notes_strategy(const char *key, static int git_config_get_notes_strategy(const char *key,
enum notes_merge_strategy *strategy) enum notes_merge_strategy *strategy)
{ {
const char *value; char *value;
if (git_config_get_string_const(key, &value)) if (git_config_get_string(key, &value))
return 1; return 1;
if (parse_notes_merge_strategy(value, strategy)) if (parse_notes_merge_strategy(value, strategy))
git_die_config(key, "unknown notes merge strategy %s", value); git_die_config(key, "unknown notes merge strategy %s", value);
free(value);
return 0; return 0;
} }

View File

@ -435,12 +435,14 @@ int create_bundle(struct bundle_header *header, const char *path,
/* write prerequisites */ /* write prerequisites */
if (compute_and_write_prerequisites(bundle_fd, &revs, argc, argv)) if (compute_and_write_prerequisites(bundle_fd, &revs, argc, argv))
return -1; goto err;
argc = setup_revisions(argc, argv, &revs, NULL); argc = setup_revisions(argc, argv, &revs, NULL);
if (argc > 1) if (argc > 1) {
return error(_("unrecognized argument: %s"), argv[1]); error(_("unrecognized argument: %s"), argv[1]);
goto err;
}
object_array_remove_duplicates(&revs.pending); object_array_remove_duplicates(&revs.pending);
@ -448,17 +450,26 @@ int create_bundle(struct bundle_header *header, const char *path,
if (!ref_count) if (!ref_count)
die(_("Refusing to create empty bundle.")); die(_("Refusing to create empty bundle."));
else if (ref_count < 0) else if (ref_count < 0)
return -1; goto err;
/* write pack */ /* write pack */
if (write_pack_data(bundle_fd, &revs)) if (write_pack_data(bundle_fd, &revs)) {
return -1; bundle_fd = -1; /* already closed by the above call */
goto err;
}
if (!bundle_to_stdout) { if (!bundle_to_stdout) {
if (commit_lock_file(&lock)) if (commit_lock_file(&lock))
die_errno(_("cannot create '%s'"), path); die_errno(_("cannot create '%s'"), path);
} }
return 0; return 0;
err:
if (!bundle_to_stdout) {
if (0 <= bundle_fd)
close(bundle_fd);
rollback_lock_file(&lock);
}
return -1;
} }
int unbundle(struct bundle_header *header, int bundle_fd, int flags) int unbundle(struct bundle_header *header, int bundle_fd, int flags)

View File

@ -1309,14 +1309,11 @@ static struct config_set_element *configset_find_element(struct config_set *cs,
struct config_set_element k; struct config_set_element k;
struct config_set_element *found_entry; struct config_set_element *found_entry;
char *normalized_key; char *normalized_key;
int ret;
/* /*
* `key` may come from the user, so normalize it before using it * `key` may come from the user, so normalize it before using it
* for querying entries from the hashmap. * for querying entries from the hashmap.
*/ */
ret = git_config_parse_key(key, &normalized_key, NULL); if (git_config_parse_key(key, &normalized_key, NULL))
if (ret)
return NULL; return NULL;
hashmap_entry_init(&k, strhash(normalized_key)); hashmap_entry_init(&k, strhash(normalized_key));

View File

@ -32,6 +32,7 @@ static int send_request(const char *socket, const struct strbuf *out)
write_or_die(1, in, r); write_or_die(1, in, r);
got_data = 1; got_data = 1;
} }
close(fd);
return got_data; return got_data;
} }

View File

@ -30,7 +30,7 @@ enum lookup_type {
lookup_path lookup_path
}; };
static struct submodule_cache cache; static struct submodule_cache the_submodule_cache;
static int is_cache_init; static int is_cache_init;
static int config_path_cmp(const struct submodule_entry *a, static int config_path_cmp(const struct submodule_entry *a,
@ -457,14 +457,14 @@ static void ensure_cache_init(void)
if (is_cache_init) if (is_cache_init)
return; return;
cache_init(&cache); cache_init(&the_submodule_cache);
is_cache_init = 1; is_cache_init = 1;
} }
int parse_submodule_config_option(const char *var, const char *value) int parse_submodule_config_option(const char *var, const char *value)
{ {
struct parse_config_parameter parameter; struct parse_config_parameter parameter;
parameter.cache = &cache; parameter.cache = &the_submodule_cache;
parameter.commit_sha1 = NULL; parameter.commit_sha1 = NULL;
parameter.gitmodules_sha1 = null_sha1; parameter.gitmodules_sha1 = null_sha1;
parameter.overwrite = 1; parameter.overwrite = 1;
@ -477,18 +477,18 @@ const struct submodule *submodule_from_name(const unsigned char *commit_sha1,
const char *name) const char *name)
{ {
ensure_cache_init(); ensure_cache_init();
return config_from_name(&cache, commit_sha1, name); return config_from_name(&the_submodule_cache, commit_sha1, name);
} }
const struct submodule *submodule_from_path(const unsigned char *commit_sha1, const struct submodule *submodule_from_path(const unsigned char *commit_sha1,
const char *path) const char *path)
{ {
ensure_cache_init(); ensure_cache_init();
return config_from_path(&cache, commit_sha1, path); return config_from_path(&the_submodule_cache, commit_sha1, path);
} }
void submodule_free(void) void submodule_free(void)
{ {
cache_free(&cache); cache_free(&the_submodule_cache);
is_cache_init = 0; is_cache_init = 0;
} }

View File

@ -1063,9 +1063,7 @@ static void abbrev_sha1_in_line(struct strbuf *line)
strbuf_addf(line, "%s", split[i]->buf); strbuf_addf(line, "%s", split[i]->buf);
} }
} }
for (i = 0; split[i]; i++) strbuf_list_free(split);
strbuf_release(split[i]);
} }
static void read_rebase_todolist(const char *fname, struct string_list *lines) static void read_rebase_todolist(const char *fname, struct string_list *lines)