Skip to content

Commit 6b3730d

Browse files
committed
Fix a memory leak in odb_otype_fast()
This change frees a copy of a cached object in odb_otype_fast().
1 parent 12c6e1f commit 6b3730d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/odb.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,7 @@ static int odb_otype_fast(git_object_t *type_p, git_odb *db, const git_oid *id)
11281128

11291129
if ((object = git_cache_get_raw(odb_cache(db), id)) != NULL) {
11301130
*type_p = object->cached.type;
1131+
git_odb_object_free(object);
11311132
return 0;
11321133
}
11331134

tests/odb/mixed.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,24 @@ void test_odb_mixed__expand_ids(void)
263263
git__free(ids);
264264
}
265265

266+
void test_odb_mixed__expand_ids_cached(void)
267+
{
268+
git_odb_expand_id *ids;
269+
size_t i, num;
270+
271+
/* test looking for the actual (correct) types after accessing the object */
272+
273+
setup_prefix_query(&ids, &num);
274+
275+
for (i = 0; i < num; i++) {
276+
git_odb_object *obj;
277+
if (ids[i].type == GIT_OBJECT_ANY)
278+
continue;
279+
cl_git_pass(git_odb_read_prefix(&obj, _odb, &ids[i].id, ids[i].length));
280+
git_odb_object_free(obj);
281+
}
282+
283+
cl_git_pass(git_odb_expand_ids(_odb, ids, num));
284+
assert_found_objects(ids);
285+
git__free(ids);
286+
}

0 commit comments

Comments
 (0)