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>
Michael Haggerty committed
Aug 26, 2017 at 10:28 UTC
4d589b87e857015b4f78e47353f87d4aa717b1a0
1 file changed
+5
-2
notes.c
+5
-2
@@ -449,6 +449,11 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
449
oidcpy(&l->val_oid, entry.oid);
450
} else if (path_len == 2) {
451
/* This is potentially an internal node */
452
+
453
+ if (!S_ISDIR(entry.mode))
454
+ /* internal nodes must be trees */
455
+ goto handle_non_note;
456
+
457
if (get_oid_hex_segment(entry.path, 2,
458
object_oid.hash + prefix_len,
459
GIT_SHA1_RAWSZ - prefix_len) < 0)
@@ -459,8 +464,6 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
464
xcalloc(1, sizeof(struct leaf_node));
465
oidcpy(&l->key_oid, &object_oid);
466
oidcpy(&l->val_oid, entry.oid);
462
- if (!S_ISDIR(entry.mode))
463
- goto handle_non_note; /* not subtree */
467
l->key_oid.hash[KEY_INDEX] = (unsigned char) (prefix_len + 1);
468
} else {
469
/* This can't be part of a note */