diff options
author | Arthur Schreiber <schreiber.arthur@googlemail.com> | 2014-01-14 19:08:58 +0100 |
---|---|---|
committer | Arthur Schreiber <schreiber.arthur@googlemail.com> | 2014-01-14 19:08:58 +0100 |
commit | 249537573b8509fc8ed0ae8e51835d084af7c3d2 (patch) | |
tree | 22b35c74328fac452fcc2531ebccc53f9adf167e | |
parent | ac44b3d2447f06f4022bb4b58a160244e24c039c (diff) | |
download | libgit2-249537573b8509fc8ed0ae8e51835d084af7c3d2.tar.gz |
Incorporate @arrbee's suggestions.
-rw-r--r-- | src/indexer.c | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/indexer.c b/src/indexer.c index 6290ea6cc..bcca2eb6c 100644 --- a/src/indexer.c +++ b/src/indexer.c @@ -644,19 +644,17 @@ 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) { - git__free(entry); + if (git_odb_read(&obj, idx->odb, id) < 0) return -1; - } 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 */ @@ -666,7 +664,7 @@ static int inject_object(git_indexer *idx, git_oid *id) entry->crc = crc32(entry->crc, hdr, hdr_len); if ((error = git__compress(&buf, data, len)) < 0) - goto error; + goto cleanup; /* And then the compressed object */ git_filebuf_write(&idx->pack_file, buf.ptr, buf.size); @@ -676,7 +674,7 @@ static int inject_object(git_indexer *idx, git_oid *id) /* Write a fake trailer so the pack functions play ball */ if ((error = git_filebuf_write(&idx->pack_file, &foo, GIT_OID_RAWSZ)) < 0) - goto error; + goto cleanup; idx->pack->mwf.size += GIT_OID_RAWSZ; @@ -687,14 +685,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))) - goto done; + error = save_entry(idx, entry, pentry, entry_start); -error: - git__free(entry); - git__free(pentry); +cleanup: + if (error) { + git__free(entry); + git__free(pentry); + } -done: git_odb_object_free(obj); return error; } |