From patchwork Sun Aug 25 05:18:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Hommey X-Patchwork-Id: 11113235 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E979514F7 for ; Sun, 25 Aug 2019 05:21:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C39C62173E for ; Sun, 25 Aug 2019 05:21:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725972AbfHYFSX (ORCPT ); Sun, 25 Aug 2019 01:18:23 -0400 Received: from ns332406.ip-37-187-123.eu ([37.187.123.207]:33160 "EHLO glandium.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725792AbfHYFSX (ORCPT ); Sun, 25 Aug 2019 01:18:23 -0400 Received: from glandium by mitsuha.glandium.org with local (Exim 4.92) (envelope-from ) id 1i1kuw-0002Vw-Mc; Sun, 25 Aug 2019 14:18:18 +0900 From: Mike Hommey To: git@vger.kernel.org Cc: gitster@pobox.com Subject: [PATCH] notes: avoid leaking duplicate entries Date: Sun, 25 Aug 2019 14:18:18 +0900 Message-Id: <20190825051818.9621-1-mh@glandium.org> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When add_note is called multiple times with the same key/value pair, the leaf_node it creates is leaked by notes_tree_insert. Signed-off-by: Mike Hommey --- notes.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/notes.c b/notes.c index 75c028b300..ec35f5b551 100644 --- a/notes.c +++ b/notes.c @@ -269,8 +269,10 @@ static int note_tree_insert(struct notes_tree *t, struct int_node *tree, case PTR_TYPE_NOTE: if (oideq(&l->key_oid, &entry->key_oid)) { /* skip concatenation if l == entry */ - if (oideq(&l->val_oid, &entry->val_oid)) + if (oideq(&l->val_oid, &entry->val_oid)) { + free(entry); return 0; + } ret = combine_notes(&l->val_oid, &entry->val_oid);