mirror of
https://git.proxmox.com/git/libgit2
synced 2025-08-05 16:18:05 +00:00
Merge pull request #2043 from arthurschreiber/arthur/fix-memory-leaks
Fix a bunch of memory leaks.
This commit is contained in:
commit
557bd1f410
@ -121,7 +121,6 @@ git_blame* git_blame__alloc(
|
||||
git_vector_insert(&gbr->paths, git__strdup(path)) < 0)
|
||||
{
|
||||
git_blame_free(gbr);
|
||||
git__free(gbr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
giterr_set_regex(&iter->regex, result);
|
||||
regfree(&iter->regex);
|
||||
git__free(iter);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -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__free(var_name);
|
||||
|
||||
if (git_buf_oom(&buf))
|
||||
if (git_buf_oom(&buf)) {
|
||||
git__free(var_value);
|
||||
return -1;
|
||||
}
|
||||
|
||||
var->entry->name = git_buf_detach(&buf);
|
||||
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
|
||||
git_oid oid;
|
||||
size_t entry_size;
|
||||
struct entry *entry;
|
||||
struct git_pack_entry *pentry;
|
||||
struct git_pack_entry *pentry = NULL;
|
||||
|
||||
entry = git__calloc(1, sizeof(*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
|
||||
return save_entry(idx, entry, pentry, entry_start);
|
||||
|
||||
on_error:
|
||||
git__free(pentry);
|
||||
git__free(entry);
|
||||
git__free(obj->data);
|
||||
return -1;
|
||||
@ -632,7 +633,7 @@ static int inject_object(git_indexer *idx, git_oid *id)
|
||||
{
|
||||
git_odb_object *obj;
|
||||
struct entry *entry;
|
||||
struct git_pack_entry *pentry;
|
||||
struct git_pack_entry *pentry = NULL;
|
||||
git_oid foo = {{0}};
|
||||
unsigned char hdr[64];
|
||||
git_buf buf = GIT_BUF_INIT;
|
||||
@ -641,9 +642,6 @@ static int inject_object(git_indexer *idx, git_oid *id)
|
||||
size_t len, hdr_len;
|
||||
int error;
|
||||
|
||||
entry = git__calloc(1, sizeof(*entry));
|
||||
GITERR_CHECK_ALLOC(entry);
|
||||
|
||||
entry_start = seek_back_trailer(idx);
|
||||
|
||||
if (git_odb_read(&obj, idx->odb, id) < 0)
|
||||
@ -652,6 +650,9 @@ static int inject_object(git_indexer *idx, git_oid *id)
|
||||
data = git_odb_object_data(obj);
|
||||
len = git_odb_object_size(obj);
|
||||
|
||||
entry = git__calloc(1, sizeof(*entry));
|
||||
GITERR_CHECK_ALLOC(entry);
|
||||
|
||||
entry->crc = crc32(0L, Z_NULL, 0);
|
||||
|
||||
/* Write out the object header */
|
||||
@ -682,10 +683,14 @@ static int inject_object(git_indexer *idx, git_oid *id)
|
||||
git_oid_cpy(&entry->oid, id);
|
||||
idx->off = entry_start + hdr_len + len;
|
||||
|
||||
if ((error = save_entry(idx, entry, pentry, entry_start)) < 0)
|
||||
git__free(pentry);
|
||||
error = save_entry(idx, entry, pentry, entry_start);
|
||||
|
||||
cleanup:
|
||||
if (error) {
|
||||
git__free(entry);
|
||||
git__free(pentry);
|
||||
}
|
||||
|
||||
git_odb_object_free(obj);
|
||||
return error;
|
||||
}
|
||||
|
@ -89,8 +89,10 @@ int git_pathspec__vinit(
|
||||
if (ret == GIT_ENOTFOUND) {
|
||||
git__free(match);
|
||||
continue;
|
||||
} else if (ret < 0)
|
||||
} else if (ret < 0) {
|
||||
git__free(match);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (git_vector_insert(vspec, match) < 0)
|
||||
return -1;
|
||||
|
Loading…
Reference in New Issue
Block a user