From patchwork Thu Oct 7 10:01:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12541471 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 381FBC433F5 for ; Thu, 7 Oct 2021 10:01:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 15A7C60F5B for ; Thu, 7 Oct 2021 10:01:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240768AbhJGKDn (ORCPT ); Thu, 7 Oct 2021 06:03:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232642AbhJGKDl (ORCPT ); Thu, 7 Oct 2021 06:03:41 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B74DC061746 for ; Thu, 7 Oct 2021 03:01:47 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id v25so17268442wra.2 for ; Thu, 07 Oct 2021 03:01:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LEfwCf43QO1pqRoSXsotu02cyLzxMw2j6ARgGPFOoQs=; b=NUAqo3rAqTMRZTBL/xpNfkqpwcUjWNT406yGA6ofXRGd82hOkiUirG/+ZMJY3iDK+A XMPlLHLcOlqtcWHFloRDXWJLC4V8wttnTEAvIH/tbgQ0JuuY5afppwTyLKZNdvzZCuIt /tz8Oi1MC2DjIdkOPNOPOvDyQHBzdKJ1CTEltBtduwynNIOLTe0fYNplwqOoiChGlfjM HvLwpLX/oSVaF5YITT8n0g9D66gg4dquu7comlq8ykwJtbbGOzq7MI7WdtdpHOvlsbWm +r/UdtadkcfX8ioyV0Y9vRGbs6ZYOXaGIJcaDBg5zojTu1Zy1+EVU0iIyTd/cZ/sOZbs kAJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LEfwCf43QO1pqRoSXsotu02cyLzxMw2j6ARgGPFOoQs=; b=JUNOE3mapQ4lfU4YDvucQTAZ0RmVGaB64NBgVRpUmADkc1/z7nY6OOHQ4Dh70T0VVH HHv1oZglsg7MT8CdpBslggxsSNC8h+p60ltSyIn+W0PYyqEktDYN/Ng49ubBfghmkvjk i53NN+Db1P1HtpvrV6b/469j4gEAKZZ7z+P/fpOM4ME8UyWthDmNYDIl2ju44KWJQFW0 r6N2n/sdLir0j1/zMuHccSnh66GKj4roZMSCIcAAyZ85dTXOCZceLQuQbuQoiDiPDn1M adlwuIYYNRvlafwWS3vJ2TOHqop0NXiObwDIt0+SdXgJv1CAyfnQ8SX5vXzmVnzqyeYw kSyg== X-Gm-Message-State: AOAM530HEBJwHoVbpLaUs0/ChsQzfsbcwAf+ezmHJGLQyebLyObrA9Kh 4dsiaENwLGq9jUEDvy8S4dNidAqwkxixQg== X-Google-Smtp-Source: ABdhPJzB02JW1TEz8VFwTlNAHbkhecxE/GM5onQNK81FF8HPsxcIph1cU0l7uWv+/ctMP/qpFu4QmA== X-Received: by 2002:a5d:6d86:: with SMTP id l6mr4182008wrs.293.1633600905635; Thu, 07 Oct 2021 03:01:45 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f16sm628559wrr.53.2021.10.07.03.01.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 03:01:45 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?q?Martin_=C3=85gren?= , Andrzej Hunt , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 1/7] tests: fix a memory leak in test-prio-queue.c Date: Thu, 7 Oct 2021 12:01:31 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1446.g6af949f83bd In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a memory leak in t/helper/test-prio-queue.c, the lack of freeing the memory with clear_prio_queue() has been there ever since this code was originally added in b4b594a3154 (prio-queue: priority queue of pointers to structs, 2013-06-06). By fixing this leak we can cleanly run t0009-prio-queue.sh under SANITIZE=leak, so annotate it as such with TEST_PASSES_SANITIZE_LEAK=true. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/helper/test-prio-queue.c | 2 ++ t/t0009-prio-queue.sh | 2 ++ 2 files changed, 4 insertions(+) diff --git a/t/helper/test-prio-queue.c b/t/helper/test-prio-queue.c index f4028442e37..133b5e6f4ae 100644 --- a/t/helper/test-prio-queue.c +++ b/t/helper/test-prio-queue.c @@ -46,5 +46,7 @@ int cmd__prio_queue(int argc, const char **argv) } } + clear_prio_queue(&pq); + return 0; } diff --git a/t/t0009-prio-queue.sh b/t/t0009-prio-queue.sh index 3941ad25286..eea99107a48 100755 --- a/t/t0009-prio-queue.sh +++ b/t/t0009-prio-queue.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='basic tests for priority queue implementation' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh cat >expect <<'EOF' From patchwork Thu Oct 7 10:01:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12541473 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9183C433EF for ; Thu, 7 Oct 2021 10:01:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BE2B56103C for ; Thu, 7 Oct 2021 10:01:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240777AbhJGKDq (ORCPT ); Thu, 7 Oct 2021 06:03:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240638AbhJGKDm (ORCPT ); Thu, 7 Oct 2021 06:03:42 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8A0AC061755 for ; Thu, 7 Oct 2021 03:01:48 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id i12so4706956wrb.7 for ; Thu, 07 Oct 2021 03:01:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IlCgU/+Frw7bDLoWbF42QwVh6eVg/dySfZWR2m3lXhg=; b=n1kWlS0PagOnV6mS3H3hEj05b0kf6TlBwElpWd+BhOv7WbxddwAMVyIQbT4/+NAO/m YBnuwwQwl5Saabh/JJrt+t3zRwsVcU0MhzUcwINqxy4eekA/oFn6QhiDAnWrSvuxLURx hKWh90hN8h/FFwOP1Aqbq0g0TsDINfgmuKLRzg3OX6z9upV7npS98TdcgKiEOUq8PS6S G2xUUfhHfWqe9swD9amoLjUpG8rT+H/b8uCFvHTpNYCXQF7MX6Du3+oPCsuJrRDIa3Of j4acPLeg95xwYMXkVXtu7DlrqLdoXzhSimB2w0CXxcmTcjTGQ3RK2fw7h70cN7jt32fp PGmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IlCgU/+Frw7bDLoWbF42QwVh6eVg/dySfZWR2m3lXhg=; b=s5iCWpJi60E2L9tU4hXJZnyMs3pzqCnaXb6GK4FOOodGnhb3HD9z2SYlHcND7DzUSh wRlvR1oIMDZBZyWroAXpGQAPaQifnoVUw4CXINKmJtZgL1mHEzr0zKZh0ZD7TkHBqqon aAUATz5kYhQPBEUzOeHRYRHsyXz2VeBCejEju18eFC0cK9KJWNtE3Wl4LCszqpwjxhMM hW4hj6SeaveBAsW8dJy38feVB7iXJoreBbOX/U172vLpn3ksCQzQVXtfllh16S5MiCVO k06FpHF5vGGt6Z3WzwOOklWM8EYyb2MjLMeCGqYmjM8YPQfukuz1s4rV8IhABGI6h+wJ hiHQ== X-Gm-Message-State: AOAM533L8tkaQHoX9R3pfuWJF9M+0Hw2MggzPjcpxGibYoYewVTpisdN 5CAhbfm7B9qKH5Mf6gLv87D9+eXRsbMKWg== X-Google-Smtp-Source: ABdhPJziDDMHpr5oUf/D/xkcjMojVNGHXnHaNEqdEFTFRIU8EAOwBYR/SsJUs+vVuYus3DZjsPbT6A== X-Received: by 2002:adf:f486:: with SMTP id l6mr4012813wro.375.1633600906670; Thu, 07 Oct 2021 03:01:46 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f16sm628559wrr.53.2021.10.07.03.01.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 03:01:45 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?q?Martin_=C3=85gren?= , Andrzej Hunt , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 2/7] tests: fix a memory leak in test-parse-options.c Date: Thu, 7 Oct 2021 12:01:32 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1446.g6af949f83bd In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a memory leak in t/helper/test-parse-options.c, we were not freeing the allocated "struct string_list" or its items. Let's move the declaration of the "list" variable into the cmd__parse_options() and release it at the end. In c8ba1639165 (parse-options: add OPT_STRING_LIST helper, 2011-06-09) the "list" variable was added, and later on in c8ba1639165 (parse-options: add OPT_STRING_LIST helper, 2011-06-09) the "expect" was added. The "list" variable was last touched in 2721ce21e43 (use string_list initializer consistently, 2016-06-13), but it was still left at the static scope, it's better to move it to the function for consistency. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/helper/test-parse-options.c | 7 ++++++- t/t0040-parse-options.sh | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/t/helper/test-parse-options.c b/t/helper/test-parse-options.c index a282b6ff13e..48d3cf6692d 100644 --- a/t/helper/test-parse-options.c +++ b/t/helper/test-parse-options.c @@ -14,7 +14,6 @@ static int dry_run = 0, quiet = 0; static char *string = NULL; static char *file = NULL; static int ambiguous; -static struct string_list list = STRING_LIST_INIT_NODUP; static struct { int called; @@ -107,6 +106,8 @@ int cmd__parse_options(int argc, const char **argv) NULL }; struct string_list expect = STRING_LIST_INIT_NODUP; + struct string_list list = STRING_LIST_INIT_NODUP; + struct option options[] = { OPT_BOOL(0, "yes", &boolean, "get a boolean"), OPT_BOOL('D', "no-doubt", &boolean, "begins with 'no-'"), @@ -185,5 +186,9 @@ int cmd__parse_options(int argc, const char **argv) for (i = 0; i < argc; i++) show(&expect, &ret, "arg %02d: %s", i, argv[i]); + expect.strdup_strings = 1; + string_list_clear(&expect, 0); + string_list_clear(&list, 0); + return ret; } diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh index da310ed29b1..ed422a1a616 100755 --- a/t/t0040-parse-options.sh +++ b/t/t0040-parse-options.sh @@ -5,6 +5,7 @@ test_description='our own option parser' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh cat >expect <<\EOF From patchwork Thu Oct 7 10:01:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12541475 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8959C433EF for ; Thu, 7 Oct 2021 10:01:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AFA7460F5B for ; Thu, 7 Oct 2021 10:01:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240783AbhJGKDt (ORCPT ); Thu, 7 Oct 2021 06:03:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240759AbhJGKDm (ORCPT ); Thu, 7 Oct 2021 06:03:42 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46147C061760 for ; Thu, 7 Oct 2021 03:01:49 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id u18so17343657wrg.5 for ; Thu, 07 Oct 2021 03:01:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=thKgVTFvvWsH/dbEPfxiuVm5rtByQeSEHqaFoI5ose8=; b=mzwicukIHmbW9qLL8oLzcVg+sxJZpn0J+kF5Tywve4aF2fRoe2E6nIrky3YBRPgMRT 8Lqb0IQ7Bb3acBLTW1OwMgoCyehb4kkVb3/nsGMZ0pODc7zoeGTNCEZJyAdQKyembrza d9Ys+lEZoWGQCQUI5y/MsCFDVC6wAhsZJEFaC/lyYJGjsVi4+ef+4tvfN/ZXAWWSHiGn nnrYiFEXUMxoTuiBlLAj4AZ5nP2wnQITmNyazNRz2oNYGQTT3pBz9J9HxFP9QQTLSefp 7pMntfFSixOwdTg4ubOzqj6QX/EikEKvUFNKK6k0B8FIytj2sBa2MhaUahZl4bdWpDJa BmQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=thKgVTFvvWsH/dbEPfxiuVm5rtByQeSEHqaFoI5ose8=; b=l3GBT7km0JCIzIkk4RelPQccWJOWtBXlLvV2HS0+0ZGtcz5LoUH9uzctJP26JaYnRH 03l8OaC6xGQM0D5NmvQduLc424ecn0gmU1f6WE+8OFOHAc3I0dLFBe9IYdyeLo9kAaXl HbnrDRMyFdhj4f5/EjU6CmB2crpXXi/2PapeWkjKgNDXtWflz3YxRFErk/y2zNHLub5R Co6xxysnpVNcL75aeBtyG894vKyXbAlM1P7zN69YVAlZwC0hj6YtzeSUJvnuehRvqO2D hnjZPDIt69cKbXW9sf2saTVOYiuziQ/eOzF453/5N1lv2VItTM1IV0T6p+LNsvJrPsZO VQHw== X-Gm-Message-State: AOAM532C362aUxLxWSRBYNsjyQbBkS1oL4wUtHEjIe1mqY6dEz9Yas6H HtU4Y5MKdxK4POVTHF6+XRy6uQFBDLfBPQ== X-Google-Smtp-Source: ABdhPJwBycVYmh9tRDinKUY6cJC2PP84GIu/C7OH320d0Gdkzr6UDt6LMGGDvbIzVLZK46wThs63hg== X-Received: by 2002:adf:e604:: with SMTP id p4mr4201209wrm.79.1633600907436; Thu, 07 Oct 2021 03:01:47 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f16sm628559wrr.53.2021.10.07.03.01.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 03:01:46 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?q?Martin_=C3=85gren?= , Andrzej Hunt , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 3/7] tests: fix a memory leak in test-oidtree.c Date: Thu, 7 Oct 2021 12:01:33 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1446.g6af949f83bd In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a memory leak in t/helper/test-oidtree.c, we were not freeing the "struct strbuf" we used for the stdin input we parsed. This leak has been here ever since 92d8ed8ac10 (oidtree: a crit-bit tree for odb_loose_cache, 2021-07-07). Now that it's fixed we can declare that t0069-oidtree.sh will pass under GIT_TEST_PASSING_SANITIZE_LEAK=true. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/helper/test-oidtree.c | 3 +++ t/t0069-oidtree.sh | 1 + 2 files changed, 4 insertions(+) diff --git a/t/helper/test-oidtree.c b/t/helper/test-oidtree.c index 180ee28dd93..d48a409f4e4 100644 --- a/t/helper/test-oidtree.c +++ b/t/helper/test-oidtree.c @@ -45,5 +45,8 @@ int cmd__oidtree(int argc, const char **argv) die("unknown command: %s", line.buf); } } + + strbuf_release(&line); + return 0; } diff --git a/t/t0069-oidtree.sh b/t/t0069-oidtree.sh index bfb1397d7b2..74cc59bf8a7 100755 --- a/t/t0069-oidtree.sh +++ b/t/t0069-oidtree.sh @@ -1,6 +1,7 @@ #!/bin/sh test_description='basic tests for the oidtree implementation' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh maxhexsz=$(test_oid hexsz) From patchwork Thu Oct 7 10:01:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12541477 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E86E5C433F5 for ; Thu, 7 Oct 2021 10:02:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CCB0F6117A for ; Thu, 7 Oct 2021 10:02:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240799AbhJGKDx (ORCPT ); Thu, 7 Oct 2021 06:03:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240763AbhJGKDn (ORCPT ); Thu, 7 Oct 2021 06:03:43 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 224D5C061746 for ; Thu, 7 Oct 2021 03:01:50 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id v25so17268830wra.2 for ; Thu, 07 Oct 2021 03:01:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=f6NQEeT/pN+bjaaPpeUiMoZ7ljb1rZNuzKqQeS7Gs3U=; b=NhQfsBWKZSrjtzXrIYNFBTaKuT6zlxsonGMhqM4xmVU2BUXnfQ2w2MshZ1xgufxlZ/ oQe8pN8QQASMtAA0ILP5OHHtcCPdLGrT/rcBLOIkkB2iHZMkz+NFpFct319+TDYi586K DlBHiv3LhppDcM5qRpwALHm/PLwSK6bBBXYwa08yt4LaymMxIG+aaTovOsrG7Wd8SXfV mkbCBOxQA6x1ppQm3KU3Whl+xAX3Gc2KXFrA0O0oy9Przg9pJS3IvPqhVP6MPiLkFU7z c28SJ50n50W+ysNsC7a0sDXdzPybnkV37bbAaztkZ/WGG6oDodPMVGysWaNYPKZzZhVE boLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=f6NQEeT/pN+bjaaPpeUiMoZ7ljb1rZNuzKqQeS7Gs3U=; b=boH7hJxwMcRFydXKS0fGkkCFkAA8UdJdgfKNJol6OATBF3fJ767sMg/bgrvJzB7pLA KNo8MXj/1A2YABk1vIpTxd9zSnxdd+yopfIyonYdc/HNn9Xt8YhU0JPpEMaeah2Bn1aR U1QJwcbChmZPBob6hcS6fkS/iiTYYBzUhvWIPl+S+LQ+6EHQg6J8cVQ2EcNWNzUTxW0T 92zZ8u3xIocM6e0VQSkNNAetF0hMz8bZ/xYIledlxXmDQEilEcvQfaBasKHoUAbNtDfT g0Xg7S5MVG9OL5vhNG+tvAEAF8MbxJs6Hf7vfnrXLSkcuDwopX3+SXjwHEXHJUyWQiF7 QZJg== X-Gm-Message-State: AOAM531/iDRoLgta/sxIE+EsqBYew71FtCKMmWA64BAt3VzsIO0rovft pjECEvCbK14ge7qCb6HjxGtmlfLwfPqxIA== X-Google-Smtp-Source: ABdhPJwPlu60XSkpAHNaZk1V7YQsK9OOlRzWUL6FPpI2PUNW7tdTQVH7A4ZZnjnJdsC09GoXXtlCPA== X-Received: by 2002:adf:c78d:: with SMTP id l13mr4170902wrg.134.1633600908453; Thu, 07 Oct 2021 03:01:48 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f16sm628559wrr.53.2021.10.07.03.01.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 03:01:47 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?q?Martin_=C3=85gren?= , Andrzej Hunt , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 4/7] tests: fix test-oid-array leak, test in SANITIZE=leak Date: Thu, 7 Oct 2021 12:01:34 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1446.g6af949f83bd In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a trivial memory leak present ever since 38d905bf585 (sha1-array: add test-sha1-array and basic tests, 2014-10-01), now that that's fixed we can test this under GIT_TEST_PASSING_SANITIZE_LEAK=true. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/helper/test-oid-array.c | 4 ++++ t/t0064-oid-array.sh | 2 ++ 2 files changed, 6 insertions(+) diff --git a/t/helper/test-oid-array.c b/t/helper/test-oid-array.c index b16cd0b11b1..d1324d086a2 100644 --- a/t/helper/test-oid-array.c +++ b/t/helper/test-oid-array.c @@ -35,5 +35,9 @@ int cmd__oid_array(int argc, const char **argv) else die("unknown command: %s", line.buf); } + + strbuf_release(&line); + oid_array_clear(&array); + return 0; } diff --git a/t/t0064-oid-array.sh b/t/t0064-oid-array.sh index 2e5438ccdac..88c89e8f48a 100755 --- a/t/t0064-oid-array.sh +++ b/t/t0064-oid-array.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='basic tests for the oid array implementation' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh echoid () { From patchwork Thu Oct 7 10:01:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12541483 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 260D5C433F5 for ; Thu, 7 Oct 2021 10:02:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0BA80610A2 for ; Thu, 7 Oct 2021 10:02:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240791AbhJGKEC (ORCPT ); Thu, 7 Oct 2021 06:04:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240770AbhJGKDr (ORCPT ); Thu, 7 Oct 2021 06:03:47 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9025C061746 for ; Thu, 7 Oct 2021 03:01:50 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id s15so17342946wrv.11 for ; Thu, 07 Oct 2021 03:01:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lLwdtBxAy3TuMS8O0Q2YjANTkopE8aeEZv9gddah1GU=; b=kk8G98L7p+5q4PoSyz4nqjsVWVl/C78qE1v7U1ORQrn4eAtSnflozfo4mkghfxq2Vr wgyy9Dc+8NxL5c7jzvZtIV+7AdHI4A9+RKCWudJgr3zNt8ZmoazrI1yLlHpLjfHIxhH6 m/j7N4xkAsuRo/WFvh1gJYIgaq3c+u36h5J1EW3WrZ3vA8VyWB8H2XzyPh6uDqCGI02p JQ6sBCWYJ7Xr7aqsklzSWr5Df8WxAZLdkkod2P4QzDUCs8gIlXS8MHXzXst43GTF018g 8g4btWQO1Mjp5p/QIK5DsqKofdHz6HVJ+W77HyC1Iy234XDa17ifa1+woLIaA4tMNzD0 yUIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lLwdtBxAy3TuMS8O0Q2YjANTkopE8aeEZv9gddah1GU=; b=hc36wTWiCxt7973nd5eHDXrJxjS8y3jn0wySbuL5BxXktLLTsX3loFEJUle6rvDPMq Jr5qRhsyIcMUuN7oFmBx1weztg4kZEdmsu6M5sB7Q1W2zqvLmAwqEDfvc1GM2h85eGDR boaZw3gp5Us5PGd90ghtAWtk6P5gm9tr+Ji29JNYL9/hvjyptyeEX+2Ah0Vp/WlVaFqg LC+QiICE1ZHqnOsNPiY/q6b1SXPbWI4He8I9zJygqQFMkiWmQScCfCVkee5zxykFwCfX yUlkFqZgbqkMNmwa+vy+Ql9ZGYasXxYkL/4826w9OTtE2P0jqiOxUXI/jj983UHY5gBd WHCg== X-Gm-Message-State: AOAM531X2yrhAMWPE7suat2AySEnfcKX9CIXH3sD1ar+vMJA9LhCvb4a Z94HtV/YSjWbMh2brzagTyEfzoMJmhq2Ow== X-Google-Smtp-Source: ABdhPJzi21+asQG2Ag5cnO8s5dbSPkdHFjwRMboZkKTrsBm6bIYdBEPz+VEqkq7Qlhy/iBB2peJqsA== X-Received: by 2002:a05:600c:296:: with SMTP id 22mr2815739wmk.113.1633600909285; Thu, 07 Oct 2021 03:01:49 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f16sm628559wrr.53.2021.10.07.03.01.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 03:01:48 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?q?Martin_=C3=85gren?= , Andrzej Hunt , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 5/7] ls-files: fix a trivial dir_clear() leak Date: Thu, 7 Oct 2021 12:01:35 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1446.g6af949f83bd In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix an edge case that was missed when the dir_clear() call was added in eceba532141 (dir: fix problematic API to avoid memory leaks, 2020-08-18), we need to also clean up when we're about to exit with non-zero. That commit says, on the topic of the dir_clear() API and UNLEAK(): [...]two of them clearly thought about leaks since they had an UNLEAK(dir) directive, which to me suggests that the method to free the data was too unclear. I think that 0e5bba53af7 (add UNLEAK annotation for reducing leak false positives, 2017-09-08) which added the UNLEAK() makes it clear that that wasn't the case, rather it was the desire to avoid the complexity of freeing the memory at the end of the program. This does add a bit of complexity, but I think it's worth it to just fix these leaks when it's easy in built-ins. It allows them to serve as canaries for underlying APIs that shouldn't be leaking, it encourages us to make those freeing APIs nicer for all their users, and it prevents other leaking regressions by being able to mark the entire test as TEST_PASSES_SANITIZE_LEAK=true. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/ls-files.c | 13 +++++-------- t/t3005-ls-files-relative.sh | 1 + t/t3020-ls-files-error-unmatch.sh | 2 ++ t/t3700-add.sh | 1 + t/t7104-reset-hard.sh | 1 + 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index a2000ed6bf2..fcc685947f9 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -672,6 +672,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) N_("suppress duplicate entries")), OPT_END() }; + int ret = 0; if (argc == 2 && !strcmp(argv[1], "-h")) usage_with_options(ls_files_usage, builtin_ls_files_options); @@ -775,16 +776,12 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) if (show_resolve_undo) show_ru_info(the_repository->index); - if (ps_matched) { - int bad; - bad = report_path_error(ps_matched, &pathspec); - if (bad) - fprintf(stderr, "Did you forget to 'git add'?\n"); - - return bad ? 1 : 0; + if (ps_matched && report_path_error(ps_matched, &pathspec)) { + fprintf(stderr, "Did you forget to 'git add'?\n"); + ret = 1; } dir_clear(&dir); free(max_prefix); - return 0; + return ret; } diff --git a/t/t3005-ls-files-relative.sh b/t/t3005-ls-files-relative.sh index 727e9ae1a44..6ba8b589cd0 100755 --- a/t/t3005-ls-files-relative.sh +++ b/t/t3005-ls-files-relative.sh @@ -5,6 +5,7 @@ test_description='ls-files tests with relative paths This test runs git ls-files with various relative path arguments. ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'prepare' ' diff --git a/t/t3020-ls-files-error-unmatch.sh b/t/t3020-ls-files-error-unmatch.sh index 124e73b8e60..2cbcbc0721b 100755 --- a/t/t3020-ls-files-error-unmatch.sh +++ b/t/t3020-ls-files-error-unmatch.sh @@ -9,6 +9,8 @@ This test runs git ls-files --error-unmatch to ensure it correctly returns an error when a non-existent path is provided on the command line. ' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t3700-add.sh b/t/t3700-add.sh index 4086e1ebbc9..283a66955d6 100755 --- a/t/t3700-add.sh +++ b/t/t3700-add.sh @@ -5,6 +5,7 @@ test_description='Test of git add, including the -- option.' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # Test the file mode "$1" of the file "$2" in the index. diff --git a/t/t7104-reset-hard.sh b/t/t7104-reset-hard.sh index 7948ec392b3..cf9697eba9a 100755 --- a/t/t7104-reset-hard.sh +++ b/t/t7104-reset-hard.sh @@ -2,6 +2,7 @@ test_description='reset --hard unmerged' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' From patchwork Thu Oct 7 10:01:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12541481 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34C52C433EF for ; Thu, 7 Oct 2021 10:02:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1E100610E6 for ; Thu, 7 Oct 2021 10:02:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240831AbhJGKD7 (ORCPT ); Thu, 7 Oct 2021 06:03:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240771AbhJGKDr (ORCPT ); Thu, 7 Oct 2021 06:03:47 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0134BC061755 for ; Thu, 7 Oct 2021 03:01:52 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id u18so17344050wrg.5 for ; Thu, 07 Oct 2021 03:01:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AN1AIWQCUFRhS3mKmfAn4+sELbMSyOhU+N4C2UODX8g=; b=CIL1L2z3y8/FiFN3wt7aHwUcJ60Zfpr+3B3MYIHYHijSjsBMAsITL5ekt+XWg4Lwjd 3r7lMU4GA3qr50Yke9xSBdF95ganM7bdTEblufwXrBtLdoYbqZG8XcknQunXrB1ofvtZ QVuBkLn2c9GhoCSBTX9fCp6+6u+1Kp5VU5E4QEf91FX/FO0CUmEXCnMTFLo17P9tUdi9 7Mx05cb/nJoRcdpA/iLTnY8gVN7JaDqP7HWeD0X35AgbiAdetyOnikWKKySy89yzZroL ZfCo3FN2bTpAUUQXPogaLQNUBwK7LHoXUyX9f3O1mT5ZSGQeLsNm32F0t09nkefXi17C C8gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AN1AIWQCUFRhS3mKmfAn4+sELbMSyOhU+N4C2UODX8g=; b=4kELXNBryz2HKVZw3W1dF7tI4gPP6e6Jzv7psrHJKmt2UtQ6Ah5HfyBJrTDYwVVn6y hOU9y0lxZoFQ3r92VYwdkzBC0zr+dPJ/kzmiu2h6735dvls2lyH3c/bTeJnUmtkA9ybJ 3uTVC6tXBny1MrucIKxlrX3bIaf/uJQgG31CL1fA+p9FnDgYh7trh8Fex2NwDrKoofv9 B94J2cOKhrNfwalZiZbnuMIxiOb8PzvVQjecpAPIve6PrmZORTe0iMs8J8HtCeqZ6hNK eru+BCVedxDRUGsliBrGk8SDzAdkugY/wNcX8Jvjm/ocVYoWLQm6lnwKklVK21fRIiCE p/Zw== X-Gm-Message-State: AOAM5305cmgtnlNuHAMxw90AD9RccxodxqC47ZCHLUUZno3cON97t/M1 3tR/LP5BVFDe8fErALbgr9ee6TRXUZYKzg== X-Google-Smtp-Source: ABdhPJxijtrteznNUzXi/nupej6PqwbAEK9tU9oF6UR1m3qRBs8Kb3xxxcs6Caipkvk5SIJlvoonkw== X-Received: by 2002:a1c:8054:: with SMTP id b81mr3617718wmd.87.1633600910344; Thu, 07 Oct 2021 03:01:50 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f16sm628559wrr.53.2021.10.07.03.01.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 03:01:49 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?q?Martin_=C3=85gren?= , Andrzej Hunt , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 6/7] ls-files: add missing string_list_clear() Date: Thu, 7 Oct 2021 12:01:36 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1446.g6af949f83bd In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a memory leak that's been here ever since 72aeb18772d (clean.c, ls-files.c: respect encapsulation of exclude_list_groups, 2013-01-16), we dup'd the argument in option_parse_exclude(), but never freed the string_list. This makes almost all of t3001-ls-files-others-exclude.sh pass (it had a lot of failures before). Let's mark it as passing with TEST_PASSES_SANITIZE_LEAK=true, and then exclude the tests that still failed with a !SANITIZE_LEAK prerequisite check until we fix those leaks. We can still see the failed tests under GIT_TEST_FAIL_PREREQS=true. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/ls-files.c | 1 + t/t3001-ls-files-others-exclude.sh | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index fcc685947f9..031fef1bcaa 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -781,6 +781,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) ret = 1; } + string_list_clear(&exclude_list, 0); dir_clear(&dir); free(max_prefix); return ret; diff --git a/t/t3001-ls-files-others-exclude.sh b/t/t3001-ls-files-others-exclude.sh index 516c95ea0e8..48cec4e5f88 100755 --- a/t/t3001-ls-files-others-exclude.sh +++ b/t/t3001-ls-files-others-exclude.sh @@ -8,6 +8,7 @@ test_description='git ls-files --others --exclude This test runs git ls-files --others and tests --exclude patterns. ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh rm -fr one three @@ -102,7 +103,7 @@ test_expect_success \ >output && test_cmp expect output' -test_expect_success 'restore gitignore' ' +test_expect_success !SANITIZE_LEAK 'restore gitignore' ' git checkout --ignore-skip-worktree-bits $allignores && rm .git/index ' @@ -125,7 +126,7 @@ cat > expect << EOF # three/ EOF -test_expect_success 'git status honors core.excludesfile' \ +test_expect_success !SANITIZE_LEAK 'git status honors core.excludesfile' \ 'test_cmp expect output' test_expect_success 'trailing slash in exclude allows directory match(1)' ' From patchwork Thu Oct 7 10:01:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12541479 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A632C433F5 for ; Thu, 7 Oct 2021 10:02:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B238610E6 for ; Thu, 7 Oct 2021 10:02:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240811AbhJGKD4 (ORCPT ); Thu, 7 Oct 2021 06:03:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240776AbhJGKDr (ORCPT ); Thu, 7 Oct 2021 06:03:47 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04E1FC061760 for ; Thu, 7 Oct 2021 03:01:53 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id v25so17269323wra.2 for ; Thu, 07 Oct 2021 03:01:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gzFMSQqzoAGFMNjVhcT35IuyMOWnSj3q4N2fPk6d8hQ=; b=GpQZFenS+MKhgHvkFdyHbF8kKwfGgq2AwOJXQADl6qjNlrlro8tSheGyC7AGIwp3OG D8sjD6I53+1unoZh8a7CawsdogxaRargMEM6tTvtjWCfgdAPZXayT3Vns2Nus2w1C2hI WyBbLl/x1Ft6uRFQmTtozGNHd3csejjyavNGzlEHJFPF2Erk+G+Gjfe84+M1itNpmY+I 0UYrjpodrHwCgBfx0kxtCPR4nMOK0taTuG9bOfcTAmCL/KnEniXRLxYetBjfXM0vXmq4 Jm2al7tlMxMgTg+qWfFALfvWJB3nCK616wQBXE48qqnfuZ9nTKpyvNlWHFBdNzZ+JV2r bPRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gzFMSQqzoAGFMNjVhcT35IuyMOWnSj3q4N2fPk6d8hQ=; b=AcTScl/c1WDnQVUJIv7N3gFsSxB57vRFKNPT5d+ak5bTs8zJ6rmpZYebN4THrCZn9B 3mPXOwdUByG1aCetyvcoo+g87gpKZnpvX4TmK0z1STlgJBaGeyr+8rzko0gIO3yRkQr8 iSoopVqnBx5ap1e4N5mVfBh/jxL1svMy1gbu6PA/ZB8E3pKCfmvs8ZeEbt3QOAvKWoRT spfB2iLepzKwIFse1NPDBMIof+nEu1GhNG5sR2kBUGZptzr8Ci3/9BQaKPriPNP41TK6 fwurcPhdfD7y2XxJsONHee2WNglt1vmZiagbO4mkFC6yWBDPSw45/2dSZSrgH2sLXa+M rGzA== X-Gm-Message-State: AOAM531fSQDbd1CO1CGjcqVPiKr3AUG2zjaeE8BHHQ7U/J0w6ncyzhcU dREchbwVA6liXtLd2Oc/SxEWn6erNT6ysQ== X-Google-Smtp-Source: ABdhPJxx13cBGM0csvj/pzxVvPbJikEI8lOOlCaXzQS8lI+TwxO6YsaTs/GSLQ8H1MITEUXpI4xEmg== X-Received: by 2002:adf:a34b:: with SMTP id d11mr4199016wrb.107.1633600911350; Thu, 07 Oct 2021 03:01:51 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id f16sm628559wrr.53.2021.10.07.03.01.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 03:01:50 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?q?Martin_=C3=85gren?= , Andrzej Hunt , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 7/7] merge: add missing strbuf_release() Date: Thu, 7 Oct 2021 12:01:37 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1446.g6af949f83bd In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We strbuf_reset() this "struct strbuf" in a loop earlier, but never freed it. Plugs a memory leak that's been here ever since this code got introduced in 1c7b76be7d6 (Build in merge, 2008-07-07). This takes us from 68 failed tests in "t7600-merge.sh" to 59 under SANITIZE=leak, and makes "t7604-merge-custom-message.sh" pass! Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/merge.c | 2 ++ t/t7604-merge-custom-message.sh | 1 + 2 files changed, 3 insertions(+) diff --git a/builtin/merge.c b/builtin/merge.c index 0ccd5e1ac83..84d76780f0d 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -1577,6 +1577,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) finish(head_commit, remoteheads, &commit->object.oid, msg.buf); remove_merge_branch_state(the_repository); + strbuf_release(&msg); goto done; } else if (!remoteheads->next && common->next) ; @@ -1747,6 +1748,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) ret = suggest_conflicts(); done: + strbuf_release(&buf); free(branch_to_free); return ret; } diff --git a/t/t7604-merge-custom-message.sh b/t/t7604-merge-custom-message.sh index cd4f9607dc1..eca75551016 100755 --- a/t/t7604-merge-custom-message.sh +++ b/t/t7604-merge-custom-message.sh @@ -4,6 +4,7 @@ test_description='git merge Testing merge when using a custom message for the merge commit.' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh create_merge_msgs() {