From e54cfb9b544eeac2924f45fc7752c2a7be709a03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Mon, 12 Aug 2013 11:50:27 +0200 Subject: [PATCH] odb: free object data when id is ambiguous By the time we recognise this as an ambiguous id, the object's data has been loaded into memory. Free it when returning EABMIGUOUS. --- src/odb.c | 4 +++- tests-clar/odb/mixed.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/odb.c b/src/odb.c index 23eb4e12e..6969cf772 100644 --- a/src/odb.c +++ b/src/odb.c @@ -786,8 +786,10 @@ attempt_lookup: git__free(data); data = raw.data; - if (found && git_oid__cmp(&full_oid, &found_full_oid)) + if (found && git_oid__cmp(&full_oid, &found_full_oid)) { + git__free(raw.data); return git_odb__error_ambiguous("multiple matches for prefix"); + } found_full_oid = full_oid; found = true; diff --git a/tests-clar/odb/mixed.c b/tests-clar/odb/mixed.c index dd4587831..51970ceec 100644 --- a/tests-clar/odb/mixed.c +++ b/tests-clar/odb/mixed.c @@ -22,6 +22,7 @@ void test_odb_mixed__dup_oid(void) { cl_git_pass(git_oid_fromstr(&oid, hex)); cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, GIT_OID_HEXSZ)); + git_odb_object_free(obj); cl_git_pass(git_oid_fromstrn(&oid, short_hex, sizeof(short_hex) - 1)); cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, sizeof(short_hex) - 1)); git_odb_object_free(obj);