Commit 8d6ef4bf by Rémi Duraffort

index: fix potential memory leaks

parent 9146f1e5
......@@ -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;
......
......@@ -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));
......
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