Commit 557bd1f4 by Vicent Marti

Merge pull request #2043 from arthurschreiber/arthur/fix-memory-leaks

Fix a bunch of memory leaks.
parents 0d5d0ea8 24953757
...@@ -121,7 +121,6 @@ git_blame* git_blame__alloc( ...@@ -121,7 +121,6 @@ git_blame* git_blame__alloc(
git_vector_insert(&gbr->paths, git__strdup(path)) < 0) git_vector_insert(&gbr->paths, git__strdup(path)) < 0)
{ {
git_blame_free(gbr); git_blame_free(gbr);
git__free(gbr);
return NULL; return NULL;
} }
......
...@@ -458,6 +458,7 @@ int git_config_iterator_glob_new(git_config_iterator **out, const git_config *cf ...@@ -458,6 +458,7 @@ int git_config_iterator_glob_new(git_config_iterator **out, const git_config *cf
if ((result = regcomp(&iter->regex, regexp, REG_EXTENDED)) < 0) { if ((result = regcomp(&iter->regex, regexp, REG_EXTENDED)) < 0) {
giterr_set_regex(&iter->regex, result); giterr_set_regex(&iter->regex, result);
regfree(&iter->regex); regfree(&iter->regex);
git__free(iter);
return -1; return -1;
} }
......
...@@ -1072,8 +1072,10 @@ static int config_parse(diskfile_backend *cfg_file, struct reader *reader, git_c ...@@ -1072,8 +1072,10 @@ static int config_parse(diskfile_backend *cfg_file, struct reader *reader, git_c
git_buf_printf(&buf, "%s.%s", current_section, var_name); git_buf_printf(&buf, "%s.%s", current_section, var_name);
git__free(var_name); git__free(var_name);
if (git_buf_oom(&buf)) if (git_buf_oom(&buf)) {
git__free(var_value);
return -1; return -1;
}
var->entry->name = git_buf_detach(&buf); var->entry->name = git_buf_detach(&buf);
var->entry->value = var_value; var->entry->value = var_value;
......
...@@ -353,7 +353,7 @@ static int hash_and_save(git_indexer *idx, git_rawobj *obj, git_off_t entry_star ...@@ -353,7 +353,7 @@ static int hash_and_save(git_indexer *idx, git_rawobj *obj, git_off_t entry_star
git_oid oid; git_oid oid;
size_t entry_size; size_t entry_size;
struct entry *entry; struct entry *entry;
struct git_pack_entry *pentry; struct git_pack_entry *pentry = NULL;
entry = git__calloc(1, sizeof(*entry)); entry = git__calloc(1, sizeof(*entry));
GITERR_CHECK_ALLOC(entry); GITERR_CHECK_ALLOC(entry);
...@@ -377,6 +377,7 @@ static int hash_and_save(git_indexer *idx, git_rawobj *obj, git_off_t entry_star ...@@ -377,6 +377,7 @@ static int hash_and_save(git_indexer *idx, git_rawobj *obj, git_off_t entry_star
return save_entry(idx, entry, pentry, entry_start); return save_entry(idx, entry, pentry, entry_start);
on_error: on_error:
git__free(pentry);
git__free(entry); git__free(entry);
git__free(obj->data); git__free(obj->data);
return -1; return -1;
...@@ -632,7 +633,7 @@ static int inject_object(git_indexer *idx, git_oid *id) ...@@ -632,7 +633,7 @@ static int inject_object(git_indexer *idx, git_oid *id)
{ {
git_odb_object *obj; git_odb_object *obj;
struct entry *entry; struct entry *entry;
struct git_pack_entry *pentry; struct git_pack_entry *pentry = NULL;
git_oid foo = {{0}}; git_oid foo = {{0}};
unsigned char hdr[64]; unsigned char hdr[64];
git_buf buf = GIT_BUF_INIT; git_buf buf = GIT_BUF_INIT;
...@@ -641,9 +642,6 @@ static int inject_object(git_indexer *idx, git_oid *id) ...@@ -641,9 +642,6 @@ static int inject_object(git_indexer *idx, git_oid *id)
size_t len, hdr_len; size_t len, hdr_len;
int error; int error;
entry = git__calloc(1, sizeof(*entry));
GITERR_CHECK_ALLOC(entry);
entry_start = seek_back_trailer(idx); entry_start = seek_back_trailer(idx);
if (git_odb_read(&obj, idx->odb, id) < 0) if (git_odb_read(&obj, idx->odb, id) < 0)
...@@ -652,6 +650,9 @@ static int inject_object(git_indexer *idx, git_oid *id) ...@@ -652,6 +650,9 @@ static int inject_object(git_indexer *idx, git_oid *id)
data = git_odb_object_data(obj); data = git_odb_object_data(obj);
len = git_odb_object_size(obj); len = git_odb_object_size(obj);
entry = git__calloc(1, sizeof(*entry));
GITERR_CHECK_ALLOC(entry);
entry->crc = crc32(0L, Z_NULL, 0); entry->crc = crc32(0L, Z_NULL, 0);
/* Write out the object header */ /* Write out the object header */
...@@ -682,10 +683,14 @@ static int inject_object(git_indexer *idx, git_oid *id) ...@@ -682,10 +683,14 @@ static int inject_object(git_indexer *idx, git_oid *id)
git_oid_cpy(&entry->oid, id); git_oid_cpy(&entry->oid, id);
idx->off = entry_start + hdr_len + len; idx->off = entry_start + hdr_len + len;
if ((error = save_entry(idx, entry, pentry, entry_start)) < 0) error = save_entry(idx, entry, pentry, entry_start);
git__free(pentry);
cleanup: cleanup:
if (error) {
git__free(entry);
git__free(pentry);
}
git_odb_object_free(obj); git_odb_object_free(obj);
return error; return error;
} }
......
...@@ -89,8 +89,10 @@ int git_pathspec__vinit( ...@@ -89,8 +89,10 @@ int git_pathspec__vinit(
if (ret == GIT_ENOTFOUND) { if (ret == GIT_ENOTFOUND) {
git__free(match); git__free(match);
continue; continue;
} else if (ret < 0) } else if (ret < 0) {
git__free(match);
return ret; return ret;
}
if (git_vector_insert(vspec, match) < 0) if (git_vector_insert(vspec, match) < 0)
return -1; return -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment