From patchwork Sun Jun 11 18:49:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13275322 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26453C77B7A for ; Sun, 11 Jun 2023 18:49:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229630AbjFKStY (ORCPT ); Sun, 11 Jun 2023 14:49:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229477AbjFKStW (ORCPT ); Sun, 11 Jun 2023 14:49:22 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49B08D9 for ; Sun, 11 Jun 2023 11:49:20 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3f7353993cbso25940155e9.0 for ; Sun, 11 Jun 2023 11:49:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686509358; x=1689101358; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:to:from:subject:from:to:cc :subject:date:message-id:reply-to; bh=uqfV/yI+rQCqCP70IhiZY98Juk3QM9QJsjHdmg+ibEY=; b=FXbOFonSulOvEv38KL+OEKFQ31NX1+5o9LyCqDq9EeDAdPrKm/gJV/SiiK46pHUAFo 4xjkk+8n5SFZsytzofMKciWyuP327ARWGnOnrECwXQI9BC5PLjM3fkuS0lrgSkB/O8Dh P8ePZugWdn9c0IEIlmrgpi216gaQRCGMeRxqTV3P7NEI1CYqdmEkXuSCg5wXtS+OPC2l /jfnU7z9abmosNF9TgDRuWK+7NkkG91e695FZ59ksVuQCBO7f2U3KY2N+ftrqMAjjE6N J6W6UHgGdurmwB4vX0uBnHOD0fnM35zB4YNwU+RNwtDq67itfvX/dOktHXwKFavMhIJ2 oalA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686509358; x=1689101358; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:to:from:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=uqfV/yI+rQCqCP70IhiZY98Juk3QM9QJsjHdmg+ibEY=; b=MOwFjzGbHCX9kOUJc67nT10ctIdut9s38N/2+uAmmJYygM4BEpLgXZcGQ/kB8o2JA/ gt/mKjZQz4TB34UVwnO8KCTSEv+ge6TkFoYfdA+wqtkvbaG9nspWLXvG/g0Qr6j6FMt+ yco082gUhNYUVioK0oqAPqPDOZKCYonbj5guT457HpzRPiURFyw9Euq/CnTgqjre1YlI rUld95ZD4SG+G40cOvZ0lVBFPMkE0sWORZMvZl6lXU8xNK1z4hQXa+jU/hrrCj4c/HjK qUljI/D03xH8R7eOfWFZyfLfisknZ4404uxFATGA5Bsa6cNJcPu47waeRssMOg+3Ka+a NX6Q== X-Gm-Message-State: AC+VfDwJrSFgxwFTWLzIz60euPYztSmvxhPJusFRBDvCuQrCnVoOUpzC gpKFx6SET/Rmvv/msSDSTLiFY0iwPMI= X-Google-Smtp-Source: ACHHUZ6tQr6XoZ9fLcYvBt5SFdwOHSXDw9zPc9NlLv6eeSpX5VOPDcFeNMffWZ0HraCzBzZOdiwKXg== X-Received: by 2002:a05:600c:218:b0:3f7:367a:bd28 with SMTP id 24-20020a05600c021800b003f7367abd28mr5956004wmi.4.1686509358447; Sun, 11 Jun 2023 11:49:18 -0700 (PDT) Received: from [192.168.2.52] (151.red-88-14-53.dynamicip.rima-tde.net. [88.14.53.151]) by smtp.gmail.com with ESMTPSA id t11-20020a7bc3cb000000b003f7ed463954sm9077868wmj.25.2023.06.11.11.49.17 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 11 Jun 2023 11:49:18 -0700 (PDT) Subject: [PATCH 01/11] rev-parse: fix a leak with --abbrev-ref From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> Message-ID: Date: Sun, 11 Jun 2023 20:49:17 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org To handle "--abbrev-ref" we use shorten_unambiguous_ref(). This function takes a refname and returns a shortened refname, which is a newly allocated string that needs to be freed. Unfortunately, the refname variable is reused to receive the shortened one. Therefore, we lose the original refname, which needs to be freed as well, producing a leak. This leak can be reviewed with: $ for a in {1..10}; do git branch foo_${a}; done $ git rev-parse --abbrev-ref refs/heads/foo_{1..10} Direct leak of 171 byte(s) in 10 object(s) allocated from: ... in xstrdup wrapper.c ... in expand_ref refs.c ... in repo_dwim_ref refs.c ... in show_rev builtin/rev-parse.c ... in cmd_rev_parse builtin/rev-parse.c ... in run_builtin git.c We have this leak since a45d34691e (rev-parse: --abbrev-ref option to shorten ref name, 2009-04-13) when "--abbrev-ref" was introduced. Let's fix it. Signed-off-by: Rubén Justo --- builtin/rev-parse.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 852e49e340..9fd7095431 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -141,7 +141,7 @@ static void show_rev(int type, const struct object_id *oid, const char *name) if ((symbolic || abbrev_ref) && name) { if (symbolic == SHOW_SYMBOLIC_FULL || abbrev_ref) { struct object_id discard; - char *full; + char *full, *to_free = NULL; switch (repo_dwim_ref(the_repository, name, strlen(name), &discard, &full, @@ -156,9 +156,11 @@ static void show_rev(int type, const struct object_id *oid, const char *name) */ break; case 1: /* happy */ - if (abbrev_ref) + if (abbrev_ref) { + to_free = full; full = shorten_unambiguous_ref(full, abbrev_ref_strict); + } show_with_type(type, full); break; default: /* ambiguous */ @@ -166,6 +168,7 @@ static void show_rev(int type, const struct object_id *oid, const char *name) break; } free(full); + free(to_free); } else { show_with_type(type, name); } From patchwork Sun Jun 11 18:49:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13275323 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF8B5C7EE2E for ; Sun, 11 Jun 2023 18:49:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229989AbjFKStd (ORCPT ); Sun, 11 Jun 2023 14:49:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229477AbjFKStb (ORCPT ); Sun, 11 Jun 2023 14:49:31 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E57FD9 for ; Sun, 11 Jun 2023 11:49:30 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3f6d7abe9a4so25259195e9.2 for ; Sun, 11 Jun 2023 11:49:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686509369; x=1689101369; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:to:from:subject:from:to:cc :subject:date:message-id:reply-to; bh=XXEJOulljTjJ99ishYgib4Weo3Vy06cpAuDJtQSY0lA=; b=Ua5rpms/cljqNDv2VO8sx6cz+ODmNu6M2VOtbewjQKiNkaoYLuBgomHKJ4j5zsVvoL /FrvYh5q5Uvf8LTjE6DFQw4DS8A6xCrb0viUct1GuUv64FQLcYAITGdwNIwM3BCPRFbZ Qk3kdTK9o9SEZd2MUuPfL1JZqKR8AJQPoHX4RNrDirIuUilrlyK9gol2grGw2Z4SArIx 4J7u079JQ9aqrJBiMBZCIZJgKgIVEOrx1kHbIFe6/nk+Mpz7VNZ8sXTu5Bu8vqLUV6h0 B3C+1x5ZAzvvXpSKw7FDPSPUKxLBYzwq3n7Q/mSyfvY1+ODgrDvc6UuKkcsju75WXQAr +Zcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686509369; x=1689101369; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:to:from:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XXEJOulljTjJ99ishYgib4Weo3Vy06cpAuDJtQSY0lA=; b=M+Mi8d3QC2Giv4RxOUkBi1PgqsOOMVFCEsjZ0HDwMhBaaHUh9pB4b0yCImL1/YzgEt 0sB1xY2z4cVp+3VBggEw6glC2p0ww6WxRIcWm44FCfO1ODIYB9daLVL/q9AlTf2XbQVi SxNTUqxjP1Iead82dlqTHQW6dh+8RoVmAJCWBEwpzGnFlwLrRLFQXi5tYL3EGvt4xFKx HVtqHaozBpo6DMREzl2A+V3Cn8iDf6MiXRgs4nTeOeJFII5YJYUM/HXCz3108GQPBeU1 6nLyztULokDyWL2rsS7w0h84lBJ2DFoP7AfhV0uRbxTCH8cm22+oK5/M6YLdM/t4cwD0 vYbw== X-Gm-Message-State: AC+VfDzBPeWeB1RZMICHyEKQnf5dfto1w3EkqHbmxmMRz5yYvbfoYXns s1XMoumJhzcSlGnQJFnf6jOayzBPqr8= X-Google-Smtp-Source: ACHHUZ6B9IECVZ/KCS3Qi3oExpn1Vye5N1kTBEwK9FTFCiGR9NxqqYmP99yuQYfsCMkRQGmfYfEP1w== X-Received: by 2002:a7b:c7d8:0:b0:3f4:2365:e5ac with SMTP id z24-20020a7bc7d8000000b003f42365e5acmr4581326wmk.13.1686509369049; Sun, 11 Jun 2023 11:49:29 -0700 (PDT) Received: from [192.168.2.52] (151.red-88-14-53.dynamicip.rima-tde.net. [88.14.53.151]) by smtp.gmail.com with ESMTPSA id v16-20020adfe4d0000000b00307a83ea722sm10357392wrm.58.2023.06.11.11.49.28 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 11 Jun 2023 11:49:28 -0700 (PDT) Subject: [PATCH 02/11] config: fix a leak in git_config_copy_or_rename_section_in_file From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> Message-ID: <2ce6f067-9d02-2a10-5eb9-6820e66f0b84@gmail.com> Date: Sun, 11 Jun 2023 20:49:28 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In 52d59cc645 (branch: add a --copy (-c) option to go with --move (-m), 2017-06-18) a new strbuf variable was introduced, but not released. Thus, when copying a branch that has any configuration, we have a leak. $ git branch foo $ git config branch.foo.some-key some_value $ git branch -c foo bar Direct leak of 65 byte(s) in 1 object(s) allocated from: ... in xrealloc wrapper.c ... in strbuf_grow strbuf.c ... in strbuf_vaddf strbuf.c ... in strbuf_addf strbuf.c ... in store_create_section config.c ... in git_config_copy_or_rename_section_in_file config.c ... in git_config_copy_section_in_file config.c ... in git_config_copy_section config.c ... in copy_or_rename_branch builtin/branch.c ... in cmd_branch builtin/branch.c ... in run_builtin git.c Let's fix that leak. Signed-off-by: Rubén Justo --- config.c | 1 + 1 file changed, 1 insertion(+) diff --git a/config.c b/config.c index b79baf83e3..39a7d7422c 100644 --- a/config.c +++ b/config.c @@ -3879,6 +3879,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename free(filename_buf); config_store_data_clear(&store); strbuf_release(&buf); + strbuf_release(©str); return ret; } From patchwork Sun Jun 11 18:49:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13275324 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2800DC7EE2E for ; Sun, 11 Jun 2023 18:49:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229845AbjFKStm (ORCPT ); Sun, 11 Jun 2023 14:49:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231646AbjFKStk (ORCPT ); Sun, 11 Jun 2023 14:49:40 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FA07E6E for ; Sun, 11 Jun 2023 11:49:38 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3f6e1393f13so25962755e9.0 for ; Sun, 11 Jun 2023 11:49:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686509376; x=1689101376; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:to:from:subject:from:to:cc :subject:date:message-id:reply-to; bh=/jswaJzFsfNmadhlvtYRZBt2F7YSdIOMjRD6N3am+Ag=; b=T5zMnts7QW9uVptURb9ac732Y0QTqQt92PF7CUQae8aZSER9MlpfVabgGREDZ12Sb6 c+u3dfwNIGCJ6wVfcAnoxwaugDfBlauAIIh83VxNegt0weP7vXZJDMDgSOmGccL/JfK+ 5//zco8HXB5imjvkCCaNZosWUVTDFXQ3GfP0Bagw1YFYQ2jDH2J9GeuFCrcO0ZV2bpiV deR8mDd/WTc7CPO0BOEq3uWQZAvzlLioSRXbcUgi9fyh8I1istDQJeSyGC7QVpq0egHE b0xNVl9Dld4GUz8LkwqckKcoWm74e2J+TP2gFvY0bWw8b666xnzAs7nwYsJcSiyLu2Mc DhqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686509376; x=1689101376; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:to:from:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/jswaJzFsfNmadhlvtYRZBt2F7YSdIOMjRD6N3am+Ag=; b=I7cC1zR8U1pJ7zQ+v2V+F9CUU5q8QvfKoKtKqux+vvsY32lveXUt26l1zfb6REVuSn pmtQO8Li/uMyGatd4sDnrT/gEmRRboAzdt7LcRVY+CwKex1wnYVwWZnUS4SEsG9f3cMa r0PxhR4kUE19vm7WH3dzm9lDo/SmLYXgpQW1C0vtPYmT4VtKUPv9G7sRyn9CrQdP9GtM BWk88OPX7BUbvOpsK1NfQ14Mrjqhe11SM0upNcM/GLZNELOjK4rHQ9DqV8klfjmzaiya rPwOAu4OE7UTAirVbCYzZYsTbFOqPar/ReRqhxa1inxMhv1dUvhrxX8IpAWz2zWSxRaI ilKw== X-Gm-Message-State: AC+VfDxGLKrVt9TJgC9ovUywlWMi0jY0qb11A1Q/Ulf7Lz2WUCcuvS6f tUv/UfIMybeQbNS07cuzBY3rNu143Rs= X-Google-Smtp-Source: ACHHUZ6JT7tVR7Ky9sROMo6TOiVjjBcqWbR/hiQf7GSoAn1XRQSBPmfDrzmXoqkGPdeFZIg9ouUdiw== X-Received: by 2002:a1c:4b07:0:b0:3f8:1729:f876 with SMTP id y7-20020a1c4b07000000b003f81729f876mr1516100wma.33.1686509376321; Sun, 11 Jun 2023 11:49:36 -0700 (PDT) Received: from [192.168.2.52] (151.red-88-14-53.dynamicip.rima-tde.net. [88.14.53.151]) by smtp.gmail.com with ESMTPSA id x22-20020a05600c21d600b003f70a7b4537sm9124030wmj.36.2023.06.11.11.49.35 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 11 Jun 2023 11:49:36 -0700 (PDT) Subject: [PATCH 03/11] remote: fix a leak in query_matches_negative_refspec From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> Message-ID: Date: Sun, 11 Jun 2023 20:49:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In c0192df630 (refspec: add support for negative refspecs, 2020-09-30) query_matches_negative_refspec() was introduced. The function was implemented as a two-loop process, where the former loop accumulates and the latter evaluates. To accumulate, a string_list is used. Within the first loop, there are three cases where a string is added to the string_list. Two of them add strings that do not need to be freed. But in the third case, the string added is returned by match_name_with_pattern(), which needs to be freed. The string_list is initialized with STRING_LIST_INIT_NODUP, i.e. when cleared, the strings added are not freed. Therefore, the string returned by match_name_with_pattern() is not freed, so we have a leak. $ git remote add local . $ git update-ref refs/remotes/local/foo HEAD $ git branch --track bar local/foo Direct leak of 24 byte(s) in 1 object(s) allocated from: ... in xrealloc wrapper.c ... in strbuf_grow strbuf.c ... in strbuf_add strbuf.c ... in match_name_with_pattern remote.c ... in query_matches_negative_refspec remote.c ... in query_refspecs remote.c ... in remote_find_tracking remote.c ... in find_tracked_branch branch.c ... in for_each_remote remote.c ... in setup_tracking branch.c ... in create_branch branch.c ... in cmd_branch builtin/branch.c ... in run_builtin git.c Direct leak of 24 byte(s) in 1 object(s) allocated from: ... in xrealloc wrapper.c ... in strbuf_grow strbuf.c ... in strbuf_add strbuf.c ... in match_name_with_pattern remote.c ... in query_matches_negative_refspec remote.c ... in query_refspecs remote.c ... in remote_find_tracking remote.c ... in check_tracking_branch branch.c ... in for_each_remote remote.c ... in validate_remote_tracking_branch branch.c ... in dwim_branch_start branch.c ... in create_branch branch.c ... in cmd_branch builtin/branch.c ... in run_builtin git.c An interesting point to note is that while string_list_append() is used in the first two cases described, string_list_append_nodup() is used in the third. This seems to indicate an intention to delegate the responsibility for freeing the string, to the string_list. As if the string_list had been initialized with STRING_LIST_INIT_DUP, i.e. the strings are strdup()'d when added (except if the "_nodup" API is used) and freed when cleared. Switching to STRING_LIST_INIT_DUP fixes the leak and probably is what we wanted to do originally. Let's do it. Signed-off-by: Rubén Justo --- remote.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/remote.c b/remote.c index 0764fca0db..1bcd36e358 100644 --- a/remote.c +++ b/remote.c @@ -890,7 +890,7 @@ static int query_matches_negative_refspec(struct refspec *rs, struct refspec_ite { int i, matched_negative = 0; int find_src = !query->src; - struct string_list reversed = STRING_LIST_INIT_NODUP; + struct string_list reversed = STRING_LIST_INIT_DUP; const char *needle = find_src ? query->dst : query->src; /* From patchwork Sun Jun 11 18:49:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13275325 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22330C7EE2E for ; Sun, 11 Jun 2023 18:49:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231255AbjFKStw (ORCPT ); Sun, 11 Jun 2023 14:49:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232598AbjFKSts (ORCPT ); Sun, 11 Jun 2023 14:49:48 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95569E6A for ; Sun, 11 Jun 2023 11:49:45 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3f732d37d7bso25485905e9.0 for ; Sun, 11 Jun 2023 11:49:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686509384; x=1689101384; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:to:from:subject:from:to:cc :subject:date:message-id:reply-to; bh=Z2/Tw0uepHAlXppAx+Jppg6bKIxRe4qPeS+gdVaI8h0=; b=Pa11FA+Eq4W/Ql16OIZ0Nb+zUMGL9rAleQ4xUKB1rtviOQrvWdOftRogRr3z3CYjc1 1k5JuQej8u+HWiBEcqDnLIDhOe3krgbHr5iGh59oG9i/FasCIEe0921ZbGu00XXwUwn5 RDR25eH4Puee78BObJL8Ya2ZrdMVlYx/DAzqmQBHFP4wTGlFXf1tF/FfpKvuupndzyFT 2r4q+n9jETo9meKzCrJYXE+fqx+0HUE26uNQx+C7yEaGDBFxF8gOgzE6JNPEqUK+vree UJUcfEnWVgboM6/x7w6Vf7B4y0f9pb33OzsWvSUHhmuDrnxkzWZLJrQDFH77f+FJHyrm UKRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686509384; x=1689101384; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:to:from:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Z2/Tw0uepHAlXppAx+Jppg6bKIxRe4qPeS+gdVaI8h0=; b=OCT8PK7DsO8mcNQbVagNUwZPX74rGAzCH4sUvtCnyyhtPTDz+hzjY6jv0supNWHogt G6MJ+wC9LXkQgOQyafdqSoE/wldGtrv9OtLrHeuGZN3PjR/SvfBZgnttw51rR6ihh4dk ZuFQ71PCBYDPO9s8WjSch992IPw2pYzZqEcnWbPud+KD1gt8AHAbpW8VisiLuDnhikIf GYhe/8VC3qqBrsU28fIDyE2+kHM7uf1GCUpTu8UNjIwHr9TxelydfZL9wv8eAaNGuHb6 skOoq+BvrkDJfhsQu+Dcl4t0Q3QvPO9+uD44Pa+5d13mihxx3OWHmKFhE6Zpb21ZWEnF Jw3A== X-Gm-Message-State: AC+VfDzXW2uzh0y9QDNUREh21TT1i2j4K4pOXCQyeTXUsTSvLmqw3JT0 5awYIHc0uD8G/Ub1IR5/X/t0cSarQSY= X-Google-Smtp-Source: ACHHUZ5tJy/Bi9iz3uCM3RyE1q91x2QSGOfKA827MGwSHwfOEJ7hcLmX7uAqWwH3eEL+3JHOjw9fDg== X-Received: by 2002:a05:600c:219a:b0:3f1:9b85:e305 with SMTP id e26-20020a05600c219a00b003f19b85e305mr4937236wme.34.1686509383855; Sun, 11 Jun 2023 11:49:43 -0700 (PDT) Received: from [192.168.2.52] (151.red-88-14-53.dynamicip.rima-tde.net. [88.14.53.151]) by smtp.gmail.com with ESMTPSA id f16-20020a1c6a10000000b003f60fb2addbsm9104992wmc.44.2023.06.11.11.49.43 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 11 Jun 2023 11:49:43 -0700 (PDT) Subject: [PATCH 04/11] branch: fix a leak in dwim_and_setup_tracking From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> Message-ID: Date: Sun, 11 Jun 2023 20:49:43 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In e89f151db1 (branch: move --set-upstream-to behavior to dwim_and_setup_tracking(), 2022-01-28) the string returned by dwim_branch_start() was not freed, resulting in a memory leak. It can be reviewed with: $ git remote add local . $ git update-ref refs/remotes/local/foo HEAD $ git branch --set-upstream-to local/foo foo Direct leak of 23 byte(s) in 1 object(s) allocated from: ... in xstrdup wrapper.c ... in expand_ref refs.c ... in repo_dwim_ref refs.c ... in dwim_branch_start branch.c ... in dwim_and_setup_tracking branch.c ... in cmd_branch builtin/branch.c ... in run_builtin git.c Let's free it now. Signed-off-by: Rubén Justo --- branch.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/branch.c b/branch.c index ba3914adf5..a7333a4c32 100644 --- a/branch.c +++ b/branch.c @@ -638,9 +638,10 @@ void dwim_and_setup_tracking(struct repository *r, const char *new_ref, const char *orig_ref, enum branch_track track, int quiet) { - char *real_orig_ref; + char *real_orig_ref = NULL; dwim_branch_start(r, orig_ref, track, &real_orig_ref, NULL); setup_tracking(new_ref, real_orig_ref, track, quiet); + free(real_orig_ref); } /** From patchwork Sun Jun 11 18:49:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13275326 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03A4EC7EE2E for ; Sun, 11 Jun 2023 18:49:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232236AbjFKSt4 (ORCPT ); Sun, 11 Jun 2023 14:49:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230041AbjFKSty (ORCPT ); Sun, 11 Jun 2023 14:49:54 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67536E69 for ; Sun, 11 Jun 2023 11:49:53 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-3f6d7abe934so25058515e9.2 for ; Sun, 11 Jun 2023 11:49:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686509392; x=1689101392; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:to:from:subject:from:to:cc :subject:date:message-id:reply-to; bh=T6KT9WQG46CrZDtm8XKNJpdaUYuwHNxyMAC9Pl6emhs=; b=mKAGKIaNVEJmH8OhZHd3/KfDcSr+x7LKmadWkDMu8SI/2oxsrOUPWxmcmB4T8WWzkM g2vX549bg6ychzvDTWoR++XwCsOMNLhRtWkAl5PSsqYBUElMeD8ilCZKqJbB+pgRCMJI ivFTY0+VkEvryMAMdQG5AmC19ZWQ0FkLHcLofH9aYUXX2+NAz3i9fAWV47qvOcivvsuD Mcn930e3Beo+G419VL1WtO7mq54LojwWk9Dv0r8QvE1/ujXNMhvOrVPW1Sat5u4bQ9xm KrjoNvW1VQz+QeoAmi6y2evB/y3LT6ssfeUiT+RgNR6Mf5j3FV5hae6S5lNLj58LVsyl gDuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686509392; x=1689101392; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:to:from:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=T6KT9WQG46CrZDtm8XKNJpdaUYuwHNxyMAC9Pl6emhs=; b=AmGJ36xpNMsMJC778UXLZdfaL5uGDoc1ty5VOtp5ViYGLoVeGDSaxKFInd6AJdTfbm f4FC9NeWk1DAd2gtacCpo+kFfztACml7GRav0O2iF8lubkg82wenLfEO+8i+jBloO9Zs D31IC3uR5AG7iD3CbndJpWxKSjsz5AmoFshl1hoYcE8OOAf58JFC+EnGF4Etsh/wcos4 7ppmfRDI9uGA8vHmv2uYWqcw2e9GQN6sWR1UN8bV+iVN6W2QLh9m+bgnjmVG9/3fW41x e3YySef8M2Fg4mm9JAr0dBW8eto1la/LxfB2nOxYsUf6lcDmWmC7tqQM/meEheMm0rTw a8Wg== X-Gm-Message-State: AC+VfDwH+vXaAdq0+cnZkPAVmSM+rEJ7TpCBa6g2PiocOH3l796DrCGs i2hiXWYZkts5GCONy8NhWhp5G+8spDw= X-Google-Smtp-Source: ACHHUZ66JZAZbtALp0PGQoqIOU6BQt1Qg7GIeO6QjQC3lvP/mpJquUyfyT057J76AUjv5ytAniTbVw== X-Received: by 2002:a05:600c:2204:b0:3f6:91c:4e86 with SMTP id z4-20020a05600c220400b003f6091c4e86mr4554013wml.3.1686509391874; Sun, 11 Jun 2023 11:49:51 -0700 (PDT) Received: from [192.168.2.52] (151.red-88-14-53.dynamicip.rima-tde.net. [88.14.53.151]) by smtp.gmail.com with ESMTPSA id o6-20020a05600c378600b003f7cb42fa20sm9079917wmr.42.2023.06.11.11.49.51 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 11 Jun 2023 11:49:51 -0700 (PDT) Subject: [PATCH 05/11] branch: fix a leak in setup_tracking From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> Message-ID: <49a4339b-d736-2c30-0c57-194ab33f377c@gmail.com> Date: Sun, 11 Jun 2023 20:49:51 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In bdaf1dfae7 (branch: new autosetupmerge option "simple" for matching branches, 2022-04-29) a new exit for setup_tracking() missed the clean-up, producing a leak. $ git config branch.autoSetupMerge simple $ git remote add local . $ git update-ref refs/remotes/local/foo HEAD $ git branch bar local/foo Direct leak of 384 byte(s) in 1 object(s) allocated from: ... in xrealloc wrapper.c ... in string_list_append_nodup string-list.c ... in find_tracked_branch branch.c ... in for_each_remote remote.c ... in setup_tracking branch.c ... in create_branch branch.c ... in cmd_branch builtinbranch.c ... in run_builtin git.c Indirect leak of 24 byte(s) in 1 object(s) allocated from: ... in xrealloc wrapper.c ... in strbuf_grow strbuf.c ... in strbuf_add strbuf.c ... in match_name_with_pattern remote.c ... in query_refspecs remote.c ... in remote_find_tracking remote.c ... in find_tracked_branch branch.c ... in for_each_remote remote.c ... in setup_tracking branch.c ... in create_branch branch.c ... in cmd_branch builtinbranch.c ... in run_builtin git.c The return introduced in bdaf1dfae7 was to avoid setting up the tracking, but even in that case it is still necessary to do the clean-up. Let's do it. Signed-off-by: Rubén Justo --- branch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/branch.c b/branch.c index a7333a4c32..ff81c2266a 100644 --- a/branch.c +++ b/branch.c @@ -333,7 +333,7 @@ static void setup_tracking(const char *new_ref, const char *orig_ref, if (!skip_prefix(tracking.srcs->items[0].string, "refs/heads/", &tracked_branch) || strcmp(tracked_branch, new_ref)) - return; + goto cleanup; } if (tracking.srcs->nr < 1) From patchwork Sun Jun 11 18:50:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13275327 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A57E8C7EE2E for ; Sun, 11 Jun 2023 18:50:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229636AbjFKSuK (ORCPT ); Sun, 11 Jun 2023 14:50:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230041AbjFKSuJ (ORCPT ); Sun, 11 Jun 2023 14:50:09 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 716D4E64 for ; Sun, 11 Jun 2023 11:50:08 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3f81b449357so2509065e9.0 for ; Sun, 11 Jun 2023 11:50:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686509407; x=1689101407; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:to:from:subject:from:to:cc :subject:date:message-id:reply-to; bh=Tt1FB1kn+UlodWOOSYnStELOGQ4ptiZzYdo3jNYafQ4=; b=Fm5oI8yV8WylDHSCL2EdyZkE3YnlYX0sOcM4SOHsPGVwbsOF5hKBsLQnDeV11uiBH7 bSEeSrOZJpjkEuAq1MnoGnz0MYgWLJwSypyTIcAO7PzE2WJwp6WK0+xOlKOKJUkqLmc9 n0wnxP/ihNuNvHdS02lHNitO8fBAxUedqPtIZFfS+0uufHqZtCLJ/XCFh2DYCokTbdkb BlUVn57Yl1L9eYYYj701ztl/Gvu/nJ11oCBr/HgaiG0xtkY6JEN7YZHaeHALseGRoix5 IxEyHwJ+ex3xq66I/Jsb3p/TFvH8335oViLJzZb9/2zpbzHJ1FqvwJiYoZINN5TfP5tW eXlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686509407; x=1689101407; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:to:from:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Tt1FB1kn+UlodWOOSYnStELOGQ4ptiZzYdo3jNYafQ4=; b=POhMcy4IM5ejOrbQzRvXWnfVMiK+LvlC+cCPbL7hNpFQ5uzg1CQ2kr6xT47G1qFIm+ jMt6pheNLrYNkYsTeADJB21QqkXzoDtMnEFWHmmYWH4+jDCJVvPDFvPIQJ4eRnsQQ976 MQFxZ4JTMAgEdIAgjgJlygc3d7x6y7QsIHA6S6IhzbjKu7y0Fcmf3Dhm079cWdcZ77Wb PcMMvl806Fof4Upbz7MOVuVk6u00WZPJklrDHxjdld/OpYhkuTXLWhIpMW3QqPxkE/l+ AY9Int5pciQObKtQ3vUIG/OGAFfSqF5AjMyYLNnOOV8ho+AGju0AUy8cGB5zf81DwJMX x6CQ== X-Gm-Message-State: AC+VfDzcTWAHpO3us0/JCyVYGbZgFoA8Sg9/bRU10gQG0TdiqHPyZ6t8 WOTd1wVZUAnp93ODhvuca1YZnrUHcLQ= X-Google-Smtp-Source: ACHHUZ7p1QDWqnxffam0vfIXWxBqNDknpF9J/OGKbAQuZNe9xPLxdBzB4mbpZsROV3omUAkTRYBlEA== X-Received: by 2002:a7b:c84c:0:b0:3f7:371a:ec8f with SMTP id c12-20020a7bc84c000000b003f7371aec8fmr5483354wml.15.1686509406688; Sun, 11 Jun 2023 11:50:06 -0700 (PDT) Received: from [192.168.2.52] (151.red-88-14-53.dynamicip.rima-tde.net. [88.14.53.151]) by smtp.gmail.com with ESMTPSA id y19-20020a05600c365300b003f7f60203ffsm9073946wmq.25.2023.06.11.11.50.06 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 11 Jun 2023 11:50:06 -0700 (PDT) Subject: [PATCH 06/11] branch: fix a leak in cmd_branch From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> Message-ID: <6cbdf9b9-227a-4665-5725-6a863676e95d@gmail.com> Date: Sun, 11 Jun 2023 20:50:05 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In 98e7ab6d42 (for-each-ref: delay parsing of --sort= options, 2021-10-20) a new string_list was introduced to accumulate any "branch.sort" setting. That string_list is cleared in ref_sorting_options(), which is only called when processing the "--list" sub-command. Therefore, with other sub-command, while having any sort option set, a leak is produced, e.g.: $ git config branch.sort invalid_sort_option $ git branch --edit-description Direct leak of 384 byte(s) in 1 object(s) allocated from: ... in xrealloc wrapper.c ... in string_list_append_nodup string-list.c ... in string_list_append string-list.c ... in git_branch_config builtin/branch.c ... in configset_iter config.c ... in repo_config config.c ... in git_config config.c ... in cmd_branch builtin/branch.c ... in run_builtin git.c Indirect leak of 20 byte(s) in 1 object(s) allocated from: ... in xstrdup wrapper.c ... in string_list_append string-list.c ... in git_branch_config builtin/branch.c ... in configset_iter config.c ... in repo_config config.c ... in git_config config.c ... in cmd_branch builtin/branch.c ... in run_builtin git.c We don't have a common clean-up section in cmd_branch(). To avoid refactoring and keep the fix simple, and while we find a better solution, let's silence the leak-hunter making the list static. Signed-off-by: Rubén Justo --- builtin/branch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/branch.c b/builtin/branch.c index e6c2655af6..759480fe8d 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -709,7 +709,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) enum branch_track track; struct ref_filter filter; static struct ref_sorting *sorting; - struct string_list sorting_options = STRING_LIST_INIT_DUP; + static struct string_list sorting_options = STRING_LIST_INIT_DUP; struct ref_format format = REF_FORMAT_INIT; struct option options[] = { From patchwork Sun Jun 11 18:50:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13275328 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02E7EC77B7A for ; Sun, 11 Jun 2023 18:50:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232304AbjFKSuV (ORCPT ); Sun, 11 Jun 2023 14:50:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230041AbjFKSuT (ORCPT ); Sun, 11 Jun 2023 14:50:19 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8950AE64 for ; Sun, 11 Jun 2023 11:50:18 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-30af86a966eso2254929f8f.2 for ; Sun, 11 Jun 2023 11:50:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686509417; x=1689101417; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:to:from:subject:from:to:cc :subject:date:message-id:reply-to; bh=iMGH5694LA6mEBuhJb4jLEC639P9iTY2nBlFubRef20=; b=rWSnn9bcCvxiHz2WMVfoGHsmdvTjEpNMzAblqa43S8aTEQJ5iKf/SXeMQ/Az6poWz6 MEw75D0lmpANjoA757pbp/1GxFal7bjACepSYLOOs+vpycuORYU2aTf4LWduzU5H9d75 iWUI4Nr8ocvW52pjdfFb0GGZwowHrwxy45grhh2MY+HlHZ4G5UfpwH4RvYeIupTIrez4 L0wzlomRer5oxx83jBqCwBsyTI5dnKB8R6ILhwkGtxa1jYnwdJvZHwNALTWfdTJNsS8q dstLg9o80f7TsGDoh9vpVVUiWDu/WMxQhkqhEhGwVN2+FbOZCaFEkq5HTmHF7ZORktT7 Du0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686509417; x=1689101417; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:to:from:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=iMGH5694LA6mEBuhJb4jLEC639P9iTY2nBlFubRef20=; b=biyS1DMbgB4uyE/jD/kB01d154vlS8kmlkHg0SRNZI0m2kP8L9Blvc2hXdsDjsXzEs q40qNeuyhUEYgIAMRTPs//vhHQ2d2Xbj/WWOjbLj3lRoIkkd785WG2TYobB2UboM5sB/ WLNkCAcl2wcd8SKdyCT31sMgOb1ypbHcfqFR6TDgS/y2SplCUwi1JFWWvlJytaLLsDju ulECoTHbpEasikuKXEFzsAWBIJ666I47G12L29SQeaZSNvMOdvF0jCVMFwFu9lK0JP35 YMvJpkG2PZU0YC7P2X3BtFshiJxRwdcEW5XJZH5h6DrQRC4PUsx/Og1J2MFkiFhdU72D rqaw== X-Gm-Message-State: AC+VfDwQwfMwUPK+E+rNA8Z9kGsoEOvhZoklnd1Cwsy171zWYxyH+OO4 K/SFlQB92kNe37fLPSDRocjseuTPLeI= X-Google-Smtp-Source: ACHHUZ6SmyqSwo3ZL+xqRNhSFno5Gf+koJJjrdjK2HWEjigpP+KTYdnnAZ2Qa3x9PH1QvfGhWgMLxQ== X-Received: by 2002:adf:f68c:0:b0:30d:43ca:55ab with SMTP id v12-20020adff68c000000b0030d43ca55abmr2771033wrp.38.1686509417004; Sun, 11 Jun 2023 11:50:17 -0700 (PDT) Received: from [192.168.2.52] (151.red-88-14-53.dynamicip.rima-tde.net. [88.14.53.151]) by smtp.gmail.com with ESMTPSA id c2-20020a5d5282000000b002fae7408544sm10320581wrv.108.2023.06.11.11.50.16 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 11 Jun 2023 11:50:16 -0700 (PDT) Subject: [PATCH 07/11] branch: fix a leak in inherit_tracking From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> Message-ID: <25e68755-7073-9523-dacc-d79e4e10eb39@gmail.com> Date: Sun, 11 Jun 2023 20:50:16 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In d3115660b4 (branch: add flags and config to inherit tracking, 2021-12-20) a new option was introduced to allow creating a new branch, inheriting the tracking of another branch. The new code, strdup()'d the remote_name of the existing branch, but unfortunately it was not freed, producing a leak. $ git remote add local . $ git update-ref refs/remotes/local/foo HEAD $ git branch --track bar local/foo branch 'bar' set up to track 'local/foo'. $ git branch --track=inherit baz bar branch 'baz' set up to track 'local/foo'. Direct leak of 6 byte(s) in 1 object(s) allocated from: ... in xstrdup wrapper.c ... in inherit_tracking branch.c ... in setup_tracking branch.c ... in create_branch branch.c ... in cmd_branch builtin/branch.c ... in run_builtin git.c Actually, the string we're strdup()'ing is from the struct branch returned by get_branch(). Which, in turn, retrieves the string from the global "struct repository". This makes perfectly valid to use the string throughout the entire execution of create_branch(). There is no need to duplicate it. Let's fix the leak, removing the strdup(). Signed-off-by: Rubén Justo --- branch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/branch.c b/branch.c index ff81c2266a..19d606d360 100644 --- a/branch.c +++ b/branch.c @@ -233,7 +233,7 @@ static int inherit_tracking(struct tracking *tracking, const char *orig_ref) return -1; } - tracking->remote = xstrdup(branch->remote_name); + tracking->remote = branch->remote_name; for (i = 0; i < branch->merge_nr; i++) string_list_append(tracking->srcs, branch->merge_name[i]); return 0; From patchwork Sun Jun 11 18:50:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13275329 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10D5FC7EE2E for ; Sun, 11 Jun 2023 18:50:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232418AbjFKSuc (ORCPT ); Sun, 11 Jun 2023 14:50:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230041AbjFKSub (ORCPT ); Sun, 11 Jun 2023 14:50:31 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A246E64 for ; Sun, 11 Jun 2023 11:50:30 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-3f7e7fc9fe6so35860255e9.3 for ; Sun, 11 Jun 2023 11:50:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686509428; x=1689101428; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:to:from:subject:from:to:cc :subject:date:message-id:reply-to; bh=NODsiNAlG4vb2GIEImBT8Ci9czCAMw8/gKhjVazLjTI=; b=IkugZLi+z0Vfr5Bjes+hqgWrnvn1wdNPS6MOeBmA4E4AQ4sKSe6e6NMzjcta48mA0h naehTFrIqvDjcY8W2jWFgzfUrMCaUyUl3Ce6KEfN2yE54EPBrauhXiN+AvIgBWZNFJ0A 9NV44hG5Wbv1ix1AsqHNEM7PL3SFIo9yqpLV3RXj4wQNkAUkdWPDlKJAKQdBNy8mJv1y QALvi9BhYz8y2baWAEDstTKMgIXNA+qRbT/ojh0inm7rRajh14GBEs3Z8QDJuXMa9fT+ 7O36+QfbX8xIA+LQWv0apdbz50E+oZ66mcvRYCYKusdCHWlve497isr8hdViZq82psdM rZuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686509428; x=1689101428; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:to:from:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NODsiNAlG4vb2GIEImBT8Ci9czCAMw8/gKhjVazLjTI=; b=i0ELa0HwBmbarniu5n8FFLpRoN0sZXNZyGLWm1m0eC3H3PZBJ6rZNAz7U5vVZWH5q6 zviEoO/8WPtVlZGcYqTRcCCRiMtZEcdG4Rnjq6BDvlNfx8skAOSkAF8uMCreYmeDZeAO cYZmA+QqXV8H5Hflf5T91W3tAQY/G6Ms3oiOYj6zWjf9H9q/FwaO8zMNeRdDQKvsLmJb Hkl7LErDsmmRfhUp7DfcXmjQ1FeZsoPAHfrldln44lkUTcXmAeYtV++MJZN8aMN8536R m8R4BZKgup4kKVU5XmHLYYQxXpef6sPudKaqGkFcpRJMvVFoGEEXDROSpqzxRum7P96a fqKg== X-Gm-Message-State: AC+VfDw7kNoQy5DLjgO1HpZfqTvZKuvBi8Z3yEg7t0XDCNNvLoaaqZbN oxQaBNTBzQY57THA9kg0SzQgPjJL1vI= X-Google-Smtp-Source: ACHHUZ7Lzc5Auqyp2PDtuDMYAmYwUu0ZBuzuwAMzWkmzF6Pwuz2eEQPxT3B6SBqg4JL3iInPy5bifg== X-Received: by 2002:a7b:c447:0:b0:3f7:cb42:fa28 with SMTP id l7-20020a7bc447000000b003f7cb42fa28mr5481153wmi.28.1686509428685; Sun, 11 Jun 2023 11:50:28 -0700 (PDT) Received: from [192.168.2.52] (151.red-88-14-53.dynamicip.rima-tde.net. [88.14.53.151]) by smtp.gmail.com with ESMTPSA id l5-20020a1ced05000000b003f8178bf349sm2395143wmh.44.2023.06.11.11.50.28 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 11 Jun 2023 11:50:28 -0700 (PDT) Subject: [PATCH 08/11] branch: fix a leak in check_tracking_branch From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> Message-ID: <98c68cb4-abbe-0b86-0052-517f47711271@gmail.com> Date: Sun, 11 Jun 2023 20:50:27 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Let's fix a leak we have in check_tracking_branch() since the function was introduced in 41c21f22d0 (branch.c: Validate tracking branches with refspecs instead of refs/remotes/*, 2013-04-21). The leak can be reviewed with: $ git remote add local . $ git update-ref refs/remotes/local/foo HEAD $ git branch --track bar local/foo Direct leak of 24 byte(s) in 1 object(s) allocated from: ... in xrealloc wrapper.c ... in strbuf_grow strbuf.c ... in strbuf_add strbuf.c ... in match_name_with_pattern remote.c ... in query_refspecs remote.c ... in remote_find_tracking remote.c ... in check_tracking_branch branch.c ... in for_each_remote remote.c ... in validate_remote_tracking_branch branch.c ... in dwim_branch_start branch.c ... in create_branch branch.c ... in cmd_branch builtin/branch.c ... in run_builtin git.c Signed-off-by: Rubén Justo --- branch.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/branch.c b/branch.c index 19d606d360..09b9563ae7 100644 --- a/branch.c +++ b/branch.c @@ -480,9 +480,12 @@ static int check_tracking_branch(struct remote *remote, void *cb_data) { char *tracking_branch = cb_data; struct refspec_item query; + int res; memset(&query, 0, sizeof(struct refspec_item)); query.dst = tracking_branch; - return !remote_find_tracking(remote, &query); + res = !remote_find_tracking(remote, &query); + free(query.src); + return res; } static int validate_remote_tracking_branch(char *ref) From patchwork Sun Jun 11 18:50:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13275330 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19135C7EE2E for ; Sun, 11 Jun 2023 18:50:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232579AbjFKSul (ORCPT ); Sun, 11 Jun 2023 14:50:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230041AbjFKSuk (ORCPT ); Sun, 11 Jun 2023 14:50:40 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 453B3E64 for ; Sun, 11 Jun 2023 11:50:39 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3f739ec88b2so25329135e9.1 for ; Sun, 11 Jun 2023 11:50:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686509438; x=1689101438; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:to:from:subject:from:to:cc :subject:date:message-id:reply-to; bh=4ymGwbn81ZsgJbneBe2lCC5oLGT5ZgBzN1yZS84ornI=; b=nucnYwCA396x+MyaT6p5ghygfYD1GhHx4dQOID9ZZ0miGwr2kohu12MFmzGcFB6d7O RjHkXq4C94v+nu+W1hmPwuMyPETOWPyon05EFxPLmUKbMv7wR8MioP2Ad1Qp+LFqUYdF Qw8UdDTXygMirUO+HQc8sQQnxeDFXn+4O4GZCnIwHRQOgzzFIMXWaWoChiHR/LHqahJO njm9lKAXGyx1FKmaA/saML+C3Ugpt5ODiuiRLFMTgK5H4R08s4VLS86R0iN71lM/lcJC 9DbAQMV4ITiI++TvfVeYUPKf86kXRz0aT/OjpV8iFK3n3qDh+CvMl7eHTbj3etoGrW0d tepg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686509438; x=1689101438; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:to:from:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4ymGwbn81ZsgJbneBe2lCC5oLGT5ZgBzN1yZS84ornI=; b=Z68A+Oqs69LKCqWBw63FpihZCms7wIzAVSOSOYvYXqAEGgeWLqn23JziismgamOS7s jKqLtnZh5MNoiFmRXck8TGrHxL93jYju+MwGV+mKsgqpYqu08KEetS6RieAp+lL9IXlj MtycWBY25Xf0TpHFYEQ304SvCDNw8mcKFdE6CynzsMJCub57+pa+g1o4H8YTDxhmQ8t0 S3YpUfsNvJRiZg95X4eRzOYLhx+dbpJGvRcfzRtSjUuRGw3PJyZvNXqB2yLoSJq5baWq IfSxFazvqhmc3NHdkVnRNTNpeHZHSaLo4ceNJ/h9ryb0x+Qm0lNrwe6Fk6gwFfunuQ5i PoJg== X-Gm-Message-State: AC+VfDwBLaAT2943UP6v/W4UkaCcH/fjxvCTT7e6oy7DgZXifxsFjwaG +tyvQqFB48dDFUcjsxCRP5+GahlTWJU= X-Google-Smtp-Source: ACHHUZ7S1JJScWde3hZYvq1GOb/70SG9NoqQ6yVMD8qUUAx/rJ1lWsHMfCdi9nXMXkMDEFsxyxbuPQ== X-Received: by 2002:a1c:ed06:0:b0:3f4:2266:8cf0 with SMTP id l6-20020a1ced06000000b003f422668cf0mr4307875wmh.10.1686509437528; Sun, 11 Jun 2023 11:50:37 -0700 (PDT) Received: from [192.168.2.52] (151.red-88-14-53.dynamicip.rima-tde.net. [88.14.53.151]) by smtp.gmail.com with ESMTPSA id v13-20020adfebcd000000b00309382eb047sm10371279wrn.112.2023.06.11.11.50.37 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 11 Jun 2023 11:50:37 -0700 (PDT) Subject: [PATCH 09/11] branch: fix a leak in setup_tracking From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> Message-ID: <471dcc04-d60c-b745-15f0-05fe4e93ff11@gmail.com> Date: Sun, 11 Jun 2023 20:50:36 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The commit d3115660b4 (branch: add flags and config to inherit tracking, 2021-12-20) replaced in "struct tracking", the member "char *src" by a new "struct string_list *srcs". This caused a modification in find_tracked_branch(). The string returned by remote_find_tracking(), previously assigned to "src", is now added to the string_list "srcs". That string_list is initialized with STRING_LIST_INIT_DUP, which means that what is added is not the given string, but a duplicate. Therefore, the string returned by remote_find_tracking() is leaked. The leak can be reviewed with: $ git branch foo $ git remote add local . $ git fetch local $ git branch --track bar local/foo Direct leak of 24 byte(s) in 1 object(s) allocated from: ... in xrealloc wrapper.c ... in strbuf_grow strbuf.c ... in strbuf_add strbuf.c ... in match_name_with_pattern remote.c ... in query_refspecs remote.c ... in remote_find_tracking remote.c ... in find_tracked_branch branch.c ... in for_each_remote remote.c ... in setup_tracking branch.c ... in create_branch branch.c ... in cmd_branch builtin/branch.c ... in run_builtin git.c Let's fix the leak, using the "_nodup" API to add to the string_list. This way, the string itself will be added instead of being strdup()'d. And when the string_list is cleared, the string will be freed. Signed-off-by: Rubén Justo --- branch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/branch.c b/branch.c index 09b9563ae7..d88f50a48a 100644 --- a/branch.c +++ b/branch.c @@ -37,7 +37,7 @@ static int find_tracked_branch(struct remote *remote, void *priv) if (!remote_find_tracking(remote, &tracking->spec)) { switch (++tracking->matches) { case 1: - string_list_append(tracking->srcs, tracking->spec.src); + string_list_append_nodup(tracking->srcs, tracking->spec.src); tracking->remote = remote->name; break; case 2: From patchwork Sun Jun 11 18:50:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13275338 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 386AAC7EE2E for ; Sun, 11 Jun 2023 18:50:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232598AbjFKSuv (ORCPT ); Sun, 11 Jun 2023 14:50:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230041AbjFKSut (ORCPT ); Sun, 11 Jun 2023 14:50:49 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35728E64 for ; Sun, 11 Jun 2023 11:50:48 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-30ad458f085so2544303f8f.0 for ; Sun, 11 Jun 2023 11:50:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686509446; x=1689101446; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:to:from:subject:from:to:cc :subject:date:message-id:reply-to; bh=9JIbPgdsiKpXM1bp1v3FWE/MNtsf9HHnjwD9ou7ZyOE=; b=gFY5h5KR/O2d7uvF2STYmSpJ5OnJkxfK+tPTRQ+CNhNegHaLP6qmDS/bCp5uWn4wJ7 1EMV3NYw3rd9pq1cwMnRcJ5J5gxeXroclhgijoMlQXovRGrD7e4SmmJ7jaHUE8Mn18+b 1rRsJhHOj/DaAUUqCdz2Am6Esm5o6Dq+r8bNRf81cmZr7rHCLjHGVTrZE2Ut8OK78fZN fkYnAUOJfWlG8tjshiPGwPwisOV2svr/zWNizykmkHaxCjVGxWOM/Fvg8kdsteyZgqS5 UUwPp4RPAgv9Eyelje+8C3OrSYvQ5HcXedwlzP+W8dnDm2bH7BcbMBJnjBnc3/GLBMit hvnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686509446; x=1689101446; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:to:from:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9JIbPgdsiKpXM1bp1v3FWE/MNtsf9HHnjwD9ou7ZyOE=; b=Rboi3OVw7BuT83xAyqcNZKzffHoc9pz6z/AIazK3xDuF4tgFmqvU/fb03pDYzjL6ii AyHarXbA2nWkgxyaSQsB02wMwsOsSO1dh5GFjXFtYaSeIr64iZATLkUJHGYmCAcLTdJy sw+TDOOsR5Txzw+bJ35L6pzjNh59vwL5HGqOpdW09jCam7/MgoMGFX2u/JLyL50IgFUs 2mjSxfFXO0DS5uTmFjLC+QoZ0offo0l0WMLyOs+p83fHMv0ooiPAy7/FlLuqnUQ3TRwZ QujxClgolsn7zYwWDcNj9ZMwQEEODDiVRN2dths9GkyUdz0kVMq8ahLcypblq/mzYGIV X1KQ== X-Gm-Message-State: AC+VfDwkfAhBtm7uKy1JqRtkx6G/IxW6rXUVjcq5IpdFeKxf2BYq8fH3 vDPQ+UCaIzrZCL+vG5VkjYXWeS0nPus= X-Google-Smtp-Source: ACHHUZ7erxxYmvg6M6PhjuG3u6RMtfnNjsvXq/N1kBKtg93W0ODAKcJaw4MVv2NnY1ZK/x4yacKsdg== X-Received: by 2002:adf:f0c9:0:b0:307:95c9:c010 with SMTP id x9-20020adff0c9000000b0030795c9c010mr3298952wro.34.1686509446650; Sun, 11 Jun 2023 11:50:46 -0700 (PDT) Received: from [192.168.2.52] (151.red-88-14-53.dynamicip.rima-tde.net. [88.14.53.151]) by smtp.gmail.com with ESMTPSA id r11-20020a05600c2c4b00b003f7eb5375ddsm9159576wmg.15.2023.06.11.11.50.46 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 11 Jun 2023 11:50:46 -0700 (PDT) Subject: [PATCH 10/11] config: fix a leak in git_config_copy_or_rename_section_in_file From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> Message-ID: <3ee93720-dce0-8f90-68bf-0242e5731a36@gmail.com> Date: Sun, 11 Jun 2023 20:50:45 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org A branch can have its configuration spread over several configuration sections. This situation was already foreseen in 52d59cc645 (branch: add a --copy (-c) option to go with --move (-m), 2017-06-18) when "branch -c" was introduced. Unfortunately, a leak was also introduced: $ git branch foo $ cat >> .git/config < --- config.c | 1 + 1 file changed, 1 insertion(+) diff --git a/config.c b/config.c index 39a7d7422c..207e4394a3 100644 --- a/config.c +++ b/config.c @@ -3833,6 +3833,7 @@ static int git_config_copy_or_rename_section_in_file(const char *config_filename output[0] = '\t'; } } else { + strbuf_release(©str); copystr = store_create_section(new_name, &store); } } From patchwork Sun Jun 11 18:50:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Rub=C3=A9n_Justo?= X-Patchwork-Id: 13275339 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9501C77B7A for ; Sun, 11 Jun 2023 18:51:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232667AbjFKSvE (ORCPT ); Sun, 11 Jun 2023 14:51:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbjFKSvC (ORCPT ); Sun, 11 Jun 2023 14:51:02 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21872E6A for ; Sun, 11 Jun 2023 11:51:01 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-30fba11b1ceso842564f8f.1 for ; Sun, 11 Jun 2023 11:51:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686509459; x=1689101459; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:to:from:subject:from:to:cc :subject:date:message-id:reply-to; bh=ESAayQ9bQ4JcZ0vr59LHuaCLZ8diClxReSMyTOUmjKc=; b=jzZ5AEawdmg5JFb9Pz0EIlV6C2G5S3A+sSjo8lOTP3klA5Ma6QhgQ19FPsyRtqSn4K 0cX6ptnZwLDEOEeQezZZ4fpJ45I2Q+N/j7JDaVZqN7X0i9RmxHVOTsjCtqfBGrmPpTTs xgbZiOV5fhvTX0L5dpKxpbycEc1ZHqsbQUyHLsWcm2aB/hA4TdnG7aStgw0zclLy798K f5FMhy1U2tjWmhkM7vmeYCgHbW6DpKQFNXXhieo48pNQlsqKzSgfH0ytL3UTQrCPv1Ii zDHStmk/oNTZui2I73dbMcfz59T4WdcJel7/p+xyeUQDKgkFDjV5Gg1M/aWlIeBUAXAF epcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686509459; x=1689101459; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:references:to:from:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ESAayQ9bQ4JcZ0vr59LHuaCLZ8diClxReSMyTOUmjKc=; b=FeH8dsT4xpXj4zGHvZhuH7lzLpII/kitIdXQbDJhmmHj04FQfut/5ZuiLm1OyboiCy ciXHxDv62jiow/ZU5PfS0axj+H0asCyndemZJnCelDJ060k0VOJThT4XUlqFshjMFoKR xP/rmpXHSe5NkGQJJ1vtx+kAUuqKhZVvuA7rzGJgOU5gwZIOmJLZzIItzqXKF7xcetQh c8ZRwmibtNqdm7Vv1CJBPQpK2XussYFC8ELdC1zhxIpYbyrBDDPVaKMFy9638aTjlyhR B3w6/91/dELyRB/HbFzwVX3fvATyQ/iIOdDbIQOB7/uMf6NSbhLgRMFNxWVksx3y6bj+ YIdw== X-Gm-Message-State: AC+VfDwYGy6o2xmR9P6qVNlDYitM5exTxp2KG6ZCiDDFe/kRoHJS0oz+ DyQrZS19r07khMu0ZdITGhFWs3yFf8k= X-Google-Smtp-Source: ACHHUZ6/6fCPqWbWFz9zC9GlqEz0xNz7/Cy9Nq/jcpFgxn9yPgLPYxHNbbffglWqm/kU+/kqzpKQWg== X-Received: by 2002:adf:e484:0:b0:30a:e589:689a with SMTP id i4-20020adfe484000000b0030ae589689amr3797994wrm.18.1686509459486; Sun, 11 Jun 2023 11:50:59 -0700 (PDT) Received: from [192.168.2.52] (151.red-88-14-53.dynamicip.rima-tde.net. [88.14.53.151]) by smtp.gmail.com with ESMTPSA id m7-20020a056000008700b0030fa166d8a1sm7722405wrx.34.2023.06.11.11.50.59 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 11 Jun 2023 11:50:59 -0700 (PDT) Subject: [PATCH 11/11] tests: mark as passing with SANITIZE=leak From: =?utf-8?q?Rub=C3=A9n_Justo?= To: Git List References: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> Message-ID: <32527a42-ed33-cfd0-60dc-03ccc679ba20@gmail.com> Date: Sun, 11 Jun 2023 20:50:58 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <9eb931e7-dd18-8ce8-4d4a-cf3d85066189@gmail.com> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The tests listed below, since previous commits, no longer trigger any leak. + t1507-rev-parse-upstream.sh + t1508-at-combinations.sh + t1514-rev-parse-push.sh + t2027-checkout-track.sh + t3200-branch.sh + t3204-branch-name-interpretation.sh + t5404-tracking-branches.sh + t5517-push-mirror.sh + t5525-fetch-tagopt.sh + t6040-tracking-info.sh + t7508-status.sh Let's mark them with "TEST_PASSES_SANITIZE_LEAK=true" to notice and fix promptly any new leak that may be introduced and triggered by them, in the future. As a reference, the list has been formed using: $ GIT_TEST_PASSING_SANITIZE_LEAK=check make SANITIZE=leak test Signed-off-by: Rubén Justo --- t/t1507-rev-parse-upstream.sh | 1 + t/t1508-at-combinations.sh | 1 + t/t1514-rev-parse-push.sh | 1 + t/t2027-checkout-track.sh | 1 + t/t3200-branch.sh | 1 + t/t3204-branch-name-interpretation.sh | 1 + t/t5404-tracking-branches.sh | 1 + t/t5517-push-mirror.sh | 1 + t/t5525-fetch-tagopt.sh | 1 + t/t6040-tracking-info.sh | 1 + t/t7508-status.sh | 1 + 11 files changed, 11 insertions(+) diff --git a/t/t1507-rev-parse-upstream.sh b/t/t1507-rev-parse-upstream.sh index cb9ef7e329..b9af6b3ac0 100755 --- a/t/t1507-rev-parse-upstream.sh +++ b/t/t1507-rev-parse-upstream.sh @@ -5,6 +5,7 @@ test_description='test @{upstream} syntax' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh diff --git a/t/t1508-at-combinations.sh b/t/t1508-at-combinations.sh index 87a4286414..e841309d0e 100755 --- a/t/t1508-at-combinations.sh +++ b/t/t1508-at-combinations.sh @@ -4,6 +4,7 @@ test_description='test various @{X} syntax combinations together' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh check() { diff --git a/t/t1514-rev-parse-push.sh b/t/t1514-rev-parse-push.sh index d868a08110..a835a196aa 100755 --- a/t/t1514-rev-parse-push.sh +++ b/t/t1514-rev-parse-push.sh @@ -4,6 +4,7 @@ test_description='test @{push} syntax' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh resolve () { diff --git a/t/t2027-checkout-track.sh b/t/t2027-checkout-track.sh index dca35aa3e3..a8bbc60954 100755 --- a/t/t2027-checkout-track.sh +++ b/t/t2027-checkout-track.sh @@ -5,6 +5,7 @@ test_description='tests for git branch --track' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index 98b6c8ac34..daf1666df7 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -8,6 +8,7 @@ test_description='git branch assorted tests' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-rebase.sh diff --git a/t/t3204-branch-name-interpretation.sh b/t/t3204-branch-name-interpretation.sh index 3399344f25..594e3e43e1 100755 --- a/t/t3204-branch-name-interpretation.sh +++ b/t/t3204-branch-name-interpretation.sh @@ -9,6 +9,7 @@ This script aims to check the behavior of those corner cases. GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh expect_branch() { diff --git a/t/t5404-tracking-branches.sh b/t/t5404-tracking-branches.sh index cc07889667..51737eeafe 100755 --- a/t/t5404-tracking-branches.sh +++ b/t/t5404-tracking-branches.sh @@ -5,6 +5,7 @@ test_description='tracking branch update checks for git push' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t5517-push-mirror.sh b/t/t5517-push-mirror.sh index a448e169bd..6d4944a728 100755 --- a/t/t5517-push-mirror.sh +++ b/t/t5517-push-mirror.sh @@ -5,6 +5,7 @@ test_description='pushing to a mirror repository' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh D=$(pwd) diff --git a/t/t5525-fetch-tagopt.sh b/t/t5525-fetch-tagopt.sh index 45815f7378..3a28f1ded5 100755 --- a/t/t5525-fetch-tagopt.sh +++ b/t/t5525-fetch-tagopt.sh @@ -2,6 +2,7 @@ test_description='tagopt variable affects "git fetch" and is overridden by commandline.' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh setup_clone () { diff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh index a313849406..7ddbd96e58 100755 --- a/t/t6040-tracking-info.sh +++ b/t/t6040-tracking-info.sh @@ -5,6 +5,7 @@ test_description='remote tracking stats' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh advance () { diff --git a/t/t7508-status.sh b/t/t7508-status.sh index aed07c5b62..4c1f03e609 100755 --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@ -5,6 +5,7 @@ test_description='git status' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-terminal.sh