summaryrefslogtreecommitdiff
path: root/notes.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2017-08-26 08:28:06 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-08-26 16:21:01 (GMT)
commit4d589b87e857015b4f78e47353f87d4aa717b1a0 (patch)
tree852bf6b013f08f272d31657772012487a3124b7b /notes.c
parent98c9897d9e40f49cfb416801851656bac494ae40 (diff)
downloadgit-4d589b87e857015b4f78e47353f87d4aa717b1a0.zip
git-4d589b87e857015b4f78e47353f87d4aa717b1a0.tar.gz
git-4d589b87e857015b4f78e47353f87d4aa717b1a0.tar.bz2
load_subtree(): check earlier whether an internal node is a tree entry
If an entry is not a tree entry, then it cannot possibly be an internal node. But the old code checked this condition only after allocating a leaf_node object and therefore leaked that memory. Instead, check before even entering this branch of the code. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'notes.c')
-rw-r--r--notes.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/notes.c b/notes.c
index 5be570e..61a5001 100644
--- a/notes.c
+++ b/notes.c
@@ -449,6 +449,11 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
oidcpy(&l->val_oid, entry.oid);
} else if (path_len == 2) {
/* This is potentially an internal node */
+
+ if (!S_ISDIR(entry.mode))
+ /* internal nodes must be trees */
+ goto handle_non_note;
+
if (get_oid_hex_segment(entry.path, 2,
object_oid.hash + prefix_len,
GIT_SHA1_RAWSZ - prefix_len) < 0)
@@ -459,8 +464,6 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
xcalloc(1, sizeof(struct leaf_node));
oidcpy(&l->key_oid, &object_oid);
oidcpy(&l->val_oid, entry.oid);
- if (!S_ISDIR(entry.mode))
- goto handle_non_note; /* not subtree */
l->key_oid.hash[KEY_INDEX] = (unsigned char) (prefix_len + 1);
} else {
/* This can't be part of a note */