index: fix potential memory leaks

This commit is contained in:
Rémi Duraffort 2013-07-15 15:59:35 +02:00
parent 9146f1e57e
commit 8d6ef4bf78
2 changed files with 10 additions and 4 deletions

View File

@ -1409,14 +1409,18 @@ static int read_reuc(git_index *index, const char *buffer, size_t size)
if (git__strtol32(&tmp, buffer, &endptr, 8) < 0 ||
!endptr || endptr == buffer || *endptr ||
(unsigned)tmp > UINT_MAX)
(unsigned)tmp > UINT_MAX) {
index_entry_reuc_free(lost);
return index_error_invalid("reading reuc entry stage");
}
lost->mode[i] = tmp;
len = (endptr + 1) - buffer;
if (size <= len)
if (size <= len) {
index_entry_reuc_free(lost);
return index_error_invalid("reading reuc entry stage");
}
size -= len;
buffer += len;
@ -1426,8 +1430,10 @@ static int read_reuc(git_index *index, const char *buffer, size_t size)
for (i = 0; i < 3; i++) {
if (!lost->mode[i])
continue;
if (size < 20)
if (size < 20) {
index_entry_reuc_free(lost);
return index_error_invalid("reading reuc entry oid");
}
git_oid_fromraw(&lost->oid[i], (const unsigned char *) buffer);
size -= 20;

View File

@ -325,7 +325,7 @@ static int hash_and_save(git_indexer_stream *idx, git_rawobj *obj, git_off_t ent
/* FIXME: Parse the object instead of hashing it */
if (git_odb__hashobj(&oid, obj) < 0) {
giterr_set(GITERR_INDEXER, "Failed to hash object");
return -1;
goto on_error;
}
pentry = git__calloc(1, sizeof(struct git_pack_entry));