From patchwork Wed Jul 13 13:16:06 2022 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: 12916681 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 EE02CC433EF for ; Wed, 13 Jul 2022 13:16:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236169AbiGMNQd (ORCPT ); Wed, 13 Jul 2022 09:16:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230048AbiGMNQ2 (ORCPT ); Wed, 13 Jul 2022 09:16:28 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C12628C for ; Wed, 13 Jul 2022 06:16:27 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id ay25so6502525wmb.1 for ; Wed, 13 Jul 2022 06:16:27 -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=Mol2P9qRiDB02MBAu8YnwLHPZ9g3oGYn7gZYpj+O4DI=; b=Nzg1KbIQl0gg6mzXSIL/bDE9TaZQtxJeSU6rxBndA4C65TEfuLBYlANg0xH633hUbY TNuk9FwKSU5JnCyvwWIAgd7PFGVSy32xo78jXTzdAMraokwIGO/zicf5BP5bRnBbBHxc PdNggD9IgiARkh4rYHyhFYVRFX0FP9QGoCjRM+FwcnnCtBoKzy392BKeySnxzN2hh9nR oxDLBE+iOC6jLMKRV7N4KoudZmDzlN95Y3RNTxA0sbqA81Q2/NzsxY38TkoproPW4t+f PQlzccrv1ixDnlcMLMgR75V90RHz6HW6inH6VXqGfp2I8szDuKK/KgXJzZRgvaIxq9a5 9PFw== 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=Mol2P9qRiDB02MBAu8YnwLHPZ9g3oGYn7gZYpj+O4DI=; b=ltQUesgeM2RsDrioR/FFzaZ00NcAP7ZyTfKjOJjcpM/r17OZsbTskYfJCMQA0K9QaN LoG8h9BmZ8vE+PnIeq352iCmemXXBq9h/N03G0R2+u7WeGyEhisit2Eh09CdKCoOioGD X4niand2m6Br7OaNVtKZzGAWkWkfqiZhIIvSku23ykeAIPSydb4b0z+m8IhOsAPYRI3Z Gb1ywUo7ShjcqbWUWtz6lVPy9SlX/yVYnK78UrdDMkwBkEtvUkT8QzhcnIccBA/2VGZQ FEGADKFtp6Btow5wufP1P8uQo9DyXrn2u10l82qJ6CQJxKvBpWLDhpy02eyzDPWdc+iD yBnQ== X-Gm-Message-State: AJIora+53yh+TcEVRzJ5QZhH11M+wlZ25+K+Lsi5uhexcf0R1pikj8h6 TsG2MqWyHMghqBfX/qr6m8ZCD9YLXfaD9Q== X-Google-Smtp-Source: AGRyM1uFw3l7IG7TmsRWGheMmMj2DXqEbqExSd56VhVZr9+TvHbl6BpRfO/3jm3HdUnm5QGqhEtk4Q== X-Received: by 2002:a05:600c:a4c:b0:39c:6517:1136 with SMTP id c12-20020a05600c0a4c00b0039c65171136mr3604095wmq.12.1657718185641; Wed, 13 Jul 2022 06:16:25 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id t63-20020a1c4642000000b003a2e05a81b3sm2216352wma.8.2022.07.13.06.16.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 06:16:24 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 01/11] submodule.c: free() memory from xgetcwd() Date: Wed, 13 Jul 2022 15:16:06 +0200 Message-Id: X-Mailer: git-send-email 2.37.0.932.g7b7031e73bc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a memory leak in code added in bf0231c6614 (rev-parse: add --show-superproject-working-tree, 2017-03-08), we should never have made the result of xgetcwd() a "const char *", as we return a strbuf_detach()'d value. Let's fix that and free() it when we're done with it. We can't mark any tests passing passing with SANITIZE=leak using "TEST_PASSES_SANITIZE_LEAK=true" as a result of this change, but e.g. "t/t1500-rev-parse.sh" now gets closer to passing. Signed-off-by: Ævar Arnfjörð Bjarmason --- submodule.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/submodule.c b/submodule.c index 2af16c647d5..3fa5db3ecdf 100644 --- a/submodule.c +++ b/submodule.c @@ -2388,7 +2388,7 @@ int get_superproject_working_tree(struct strbuf *buf) struct child_process cp = CHILD_PROCESS_INIT; struct strbuf sb = STRBUF_INIT; struct strbuf one_up = STRBUF_INIT; - const char *cwd = xgetcwd(); + char *cwd = xgetcwd(); int ret = 0; const char *subpath; int code; @@ -2451,6 +2451,7 @@ int get_superproject_working_tree(struct strbuf *buf) ret = 1; free(super_wt); } + free(cwd); strbuf_release(&sb); code = finish_command(&cp); From patchwork Wed Jul 13 13:16:07 2022 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: 12916680 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 3C537C433EF for ; Wed, 13 Jul 2022 13:16:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236147AbiGMNQb (ORCPT ); Wed, 13 Jul 2022 09:16:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236003AbiGMNQ3 (ORCPT ); Wed, 13 Jul 2022 09:16:29 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CE15295 for ; Wed, 13 Jul 2022 06:16:28 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id r10so9313042wrv.4 for ; Wed, 13 Jul 2022 06:16:28 -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=j7D66cr6aKKSAfQZwQnLaGa8pSypCW5Cp+N3a3YCk2M=; b=KLm3BiExE5ssnlCP9iAqcDp9qM591+zUB78Lr/FtH5uBnf8yi9GQNcm2i8F9L5B9fx 76wMM7/9yfZB6HRUYUHJzH8Uo2XcemgO2b+q7EC71GTndfltQyylas/eLtkBy9rRP10s wYGe0D820BLtFb+JOxfeZayaGfjeSy+2/GKYySn99TQGq7iha4+AMf8b4x4KABfzwetC cVpUD+KtPia/oK1zygWkurnRcHVt/NK9nwTgZ3je3b2RFkOBVDVEriGe+dhTmcqz7CO5 Ac+AROJ78+lz0QvYcQYpHv6B5fiTUl47L03VzK8itprj70TAOrLKV4IJbwkCLUPLiknT 7G/Q== 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=j7D66cr6aKKSAfQZwQnLaGa8pSypCW5Cp+N3a3YCk2M=; b=akCZYkthE2O3yVAmquSez2ciB24+lu/rOn1eZYsS1erCEfpC/OqsJK76zMWaJKlh8O Nh2EwO/7dDiPDI6+Br/GRQFhs1nmT5cQcat3aZ6Ni2uJ4QE3FxyZX8lIsQ8wZ9z5KwIl xLcYIzmiecGklavWEGFEMMCyuzpCyI0HxnulZl5/YDdPUZV6RjiAZfbhz0ODO9usemLW Z8cFekST3lVcY6LRJ/p9CVczS6HrCLuB1fP4D4dsJ0G3BHi8SeDCXi+RH+qup5Jhj6ZM 6CP8zwn9JYJfLYryDsvdu01Rtpo+aYWmsrLmn2HORw+xAj9L9+HTVaBJjTM5UMwkiC/G obDA== X-Gm-Message-State: AJIora/JYcZcXBliNeAXNaDXN9Zd2d3xOhye6X4Ok8Wx2l45abHl+9zc DnT7rQlvm+RfPyzvzU0gzoonq/n23ZPSyA== X-Google-Smtp-Source: AGRyM1uZRaF+jFMW63P5djQM/9RbUiVvzGtupDwe8kjgxTSPR+hTqPGHfD2Mvu35eRElilP/jZYlwg== X-Received: by 2002:a5d:44d1:0:b0:21d:7471:2094 with SMTP id z17-20020a5d44d1000000b0021d74712094mr3306689wrr.374.1657718186651; Wed, 13 Jul 2022 06:16:26 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id t63-20020a1c4642000000b003a2e05a81b3sm2216352wma.8.2022.07.13.06.16.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 06:16:25 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 02/11] submodule--helper: replace memset() with { 0 }-initialization Date: Wed, 13 Jul 2022 15:16:07 +0200 Message-Id: X-Mailer: git-send-email 2.37.0.932.g7b7031e73bc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Use the less verbose { 0 }-initialization syntax rather than memset() in builtin/submodule--helper.c, this doesn't make a difference in terms of behavior, but as we're about to modify adjacent code makes this more consistent, and lets us avoid worrying about when the memset() happens v.s. a "goto cleanup". Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index fac52ade5e1..73717be957c 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1744,7 +1744,7 @@ static int module_clone(int argc, const char **argv, const char *prefix) { int dissociate = 0, quiet = 0, progress = 0, require_init = 0; struct module_clone_data clone_data = MODULE_CLONE_DATA_INIT; - struct list_objects_filter_options filter_options; + struct list_objects_filter_options filter_options = { 0 }; struct option module_clone_options[] = { OPT_STRING(0, "prefix", &clone_data.prefix, @@ -1786,7 +1786,6 @@ static int module_clone(int argc, const char **argv, const char *prefix) NULL }; - memset(&filter_options, 0, sizeof(filter_options)); argc = parse_options(argc, argv, prefix, module_clone_options, git_submodule_helper_usage, 0); @@ -2563,7 +2562,7 @@ static int module_update(int argc, const char **argv, const char *prefix) { struct pathspec pathspec; struct update_data opt = UPDATE_DATA_INIT; - struct list_objects_filter_options filter_options; + struct list_objects_filter_options filter_options = { 0 }; int ret; struct option module_update_options[] = { @@ -2623,7 +2622,6 @@ static int module_update(int argc, const char **argv, const char *prefix) update_clone_config_from_gitmodules(&opt.max_jobs); git_config(git_update_clone_config, &opt.max_jobs); - memset(&filter_options, 0, sizeof(filter_options)); argc = parse_options(argc, argv, prefix, module_update_options, git_submodule_helper_usage, 0); From patchwork Wed Jul 13 13:16:08 2022 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: 12916682 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 1B13DC43334 for ; Wed, 13 Jul 2022 13:16:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236183AbiGMNQg (ORCPT ); Wed, 13 Jul 2022 09:16:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236130AbiGMNQb (ORCPT ); Wed, 13 Jul 2022 09:16:31 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A248B89 for ; Wed, 13 Jul 2022 06:16:29 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id r14so15507285wrg.1 for ; Wed, 13 Jul 2022 06:16:29 -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=ZDH3b6x8h+OcaYWfKRk+Vhl12tgBLrgywlkNhczg4VU=; b=Jh6Oi/Yf9hRb9HUNBgRXKbEr9DoDfZsei1q42RcPns93vXKt8ITWyE8sC8RdqdZsK2 PlCukMMWwv8WzPriK+khU1stU8csceFUuIiDn8/Zke6HieNavVbz0qUFiKa2m0Wp8Mu0 sR2gdyYibCdoOws/TiW/eA+QTBs9iiWbUS1pHfHB71g3WnFhriPe5rBdibgcnNYA8yfN Z+7rKSi1oBFQeADYqYwxJ059q5ctKjI8XHQmZHrTF8Rb4b3ZBj7UZFrBCyyQs4EdJ6XF HHDURAbv/5lGo3NwAf1JFmdTrEz66oHzVHD3vZHy+/EcNCfJvV60YRkcNbneuCexuyhc Z4mw== 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=ZDH3b6x8h+OcaYWfKRk+Vhl12tgBLrgywlkNhczg4VU=; b=xHmEPPaOFKMGllK5CRZbt9w0t4MH20iBYVUO3+o7Xyu0m+X8GDb7xoWvZ8fkMpgskw Wtv15qrLb4T6xIE1oJrhmcEYDNynO7VylGcHz6lyUl93HkKVh+y+qaMikw/6zKQ82DVV KBlPNkzMZ5ekZnwWg78PGuDvnD2SDUqe4wW3gbTDq1M8ceUZ7J5BmRB2GvwwbB07GTgB 8DL8+ZOU4ztfghnP6b8VWhzr4cUFF6cVhk7onr1sr/leKWyHDjLGzk3vuUz6ZSguwUpA XhPoFnrBxoCSGZCn0PqAwpbKghzZoHdTmHkSkWTuL8Sx/lOkXj7JdITZYeGFZLVnvfSa m//w== X-Gm-Message-State: AJIora9S/A6f/pf67947QwQCd5C+yIwdwaAJKabOkrU09DZmyhjKM+AZ Hjm9B4O3t4mkCOl1dCUTpHHQe3P6mJC9bg== X-Google-Smtp-Source: AGRyM1uBfNs8V4wR0T4+VRNygf1uOmghVFy2FCohAondUSPNYmha7eZN0967qKjBWHZbcMkWTePAgg== X-Received: by 2002:a05:6000:1acf:b0:21d:b410:59b2 with SMTP id i15-20020a0560001acf00b0021db41059b2mr3377609wry.31.1657718187809; Wed, 13 Jul 2022 06:16:27 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id t63-20020a1c4642000000b003a2e05a81b3sm2216352wma.8.2022.07.13.06.16.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 06:16:26 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 03/11] submodule--helper: fix "module_clone_data" memory leaks Date: Wed, 13 Jul 2022 15:16:08 +0200 Message-Id: X-Mailer: git-send-email 2.37.0.932.g7b7031e73bc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix memory leaks related to the "struct module_clone_data" by creating a module_clone_data_release() function to go with the MODULE_CLONE_DATA_INIT added in a98b02c1128 (submodule--helper: refactor module_clone(), 2021-07-10). The "path" member can come from "argv" (i.e. not malloc'd), or it can be something we determine at runtime. In the latter case let's save away a pointer to free() to avoid leaking memory. Fixing this leak makes several tests pass, so let's mark them as passing with TEST_PASSES_SANITIZE_LEAK=true. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 24 +++++++++++++++++++----- t/t6008-rev-list-submodule.sh | 1 + t/t7414-submodule-mistakes.sh | 2 ++ t/t7506-status-submodule.sh | 1 + t/t7507-commit-verbose.sh | 2 ++ 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 73717be957c..23ab9c7e349 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1511,6 +1511,7 @@ static int module_deinit(int argc, const char **argv, const char *prefix) struct module_clone_data { const char *prefix; const char *path; + char *path_free; const char *name; const char *url; const char *depth; @@ -1527,6 +1528,11 @@ struct module_clone_data { .single_branch = -1, \ } +static void module_clone_data_release(struct module_clone_data *cd) +{ + free(cd->path_free); +} + struct submodule_alternate_setup { const char *submodule_name; enum SUBMODULE_ALTERNATE_ERROR_MODE { @@ -1651,9 +1657,9 @@ static int clone_submodule(struct module_clone_data *clone_data) if (!is_absolute_path(clone_data->path)) { strbuf_addf(&sb, "%s/%s", get_git_work_tree(), clone_data->path); - clone_data->path = strbuf_detach(&sb, NULL); + clone_data->path = clone_data->path_free = strbuf_detach(&sb, NULL); } else { - clone_data->path = xstrdup(clone_data->path); + clone_data->path = clone_data->path_free = xstrdup(clone_data->path); } if (validate_submodule_git_dir(sm_gitdir, clone_data->name) < 0) @@ -1801,6 +1807,8 @@ static int module_clone(int argc, const char **argv, const char *prefix) clone_submodule(&clone_data); list_objects_filter_release(&filter_options); + + module_clone_data_release(&clone_data); return 0; } @@ -3016,6 +3024,7 @@ static int add_submodule(const struct add_data *add_data) { char *submod_gitdir_path; struct module_clone_data clone_data = MODULE_CLONE_DATA_INIT; + int ret; /* perhaps the path already exists and is already a git repo, else clone it */ if (is_directory(add_data->sm_path)) { @@ -3077,8 +3086,10 @@ static int add_submodule(const struct add_data *add_data) if (add_data->depth >= 0) clone_data.depth = xstrfmt("%d", add_data->depth); - if (clone_submodule(&clone_data)) - return -1; + if (clone_submodule(&clone_data)) { + ret = -1; + goto cleanup; + } prepare_submodule_repo_env(&cp.env); cp.git_cmd = 1; @@ -3097,7 +3108,10 @@ static int add_submodule(const struct add_data *add_data) if (run_command(&cp)) die(_("unable to checkout submodule '%s'"), add_data->sm_path); } - return 0; + ret = 0; +cleanup: + module_clone_data_release(&clone_data); + return ret; } static int config_submodule_in_gitmodules(const char *name, const char *var, const char *value) diff --git a/t/t6008-rev-list-submodule.sh b/t/t6008-rev-list-submodule.sh index 3153a0d8910..12e67e187ef 100755 --- a/t/t6008-rev-list-submodule.sh +++ b/t/t6008-rev-list-submodule.sh @@ -8,6 +8,7 @@ test_description='git rev-list involving submodules that this repo has' 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/t7414-submodule-mistakes.sh b/t/t7414-submodule-mistakes.sh index f2e7df59cf2..3269298197c 100755 --- a/t/t7414-submodule-mistakes.sh +++ b/t/t7414-submodule-mistakes.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='handling of common mistakes people may make with submodules' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'create embedded repository' ' diff --git a/t/t7506-status-submodule.sh b/t/t7506-status-submodule.sh index 3fcb44767f5..f5426a8e589 100755 --- a/t/t7506-status-submodule.sh +++ b/t/t7506-status-submodule.sh @@ -2,6 +2,7 @@ test_description='git status for submodule' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_create_repo_with_commit () { diff --git a/t/t7507-commit-verbose.sh b/t/t7507-commit-verbose.sh index ed2653d46fe..92462a22374 100755 --- a/t/t7507-commit-verbose.sh +++ b/t/t7507-commit-verbose.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='verbose commit template' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh write_script "check-for-diff" <<\EOF && From patchwork Wed Jul 13 13:16:09 2022 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: 12916683 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 335FCC43334 for ; Wed, 13 Jul 2022 13:16:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236223AbiGMNQh (ORCPT ); Wed, 13 Jul 2022 09:16:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235042AbiGMNQc (ORCPT ); Wed, 13 Jul 2022 09:16:32 -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 4B0522199 for ; Wed, 13 Jul 2022 06:16:31 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id d16so15444587wrv.10 for ; Wed, 13 Jul 2022 06:16:31 -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=EAs4qL93mDfMbwvOLmMb49gIZtMC2Pa1ckg6bbTRBrk=; b=kjAtzOJzn8rWkUuOIlwaXW8JGs/RQuq9F+INuA7qOVEjTs4js6Do63nyebIVrhBHTc JjKehKNIrp4LhH7/en/v7OSFnbj0I2ElHDLXkLHejzBgg2Bc+F3+j6COfPC//TGEuoGP s+ovep3ZI0sW+qPaVeSN/Z2DrtKY5XWwus3lOjsBrKPFTnMUT08rx+MSZu92yTTWENNs tpYhPSTzBdDQtOVCEMnQoqVF2MWHqAqe1FtImo6w+wdWqQlDPjA5ke7pTDg2MxghYe4k 9VeTwINoUronfZz0H7wQRpNbz7LKwEHQMuxuMFIbz5LFlX6ThS6YT/WmMBMW3/8a/Pk5 EgCw== 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=EAs4qL93mDfMbwvOLmMb49gIZtMC2Pa1ckg6bbTRBrk=; b=Ivx5SOP05GTk8O7COqzggA/f3h+g58Gd8CP8tTln0dgKw0RNebl6aBpYZN9KWPcnLq vSC3U6IzA+0HstjCHe3MrSelf16unHABhLa1HO4hg+y0KJhOcraTdVKXZOWjmhF7ZIFb Y+OUJDJf+A4EVJWSVWcPSTf5gUhl7igzcMvO4RXyUBAgTBzf++kYA8urecFBS/CIQF0Y vVSmNtSKO7jRjyycU5FbqAV7qXUV5NU+ll8EcK9cnpBOppYcZ1QtZz8znk7AJ7yDtRxX pn5c5BETP+gDHDS9F8ISsixYAVenK5KICKu9mGLi9ABQBBZ/VaOdDEEp4DZz72K41aUo AXwA== X-Gm-Message-State: AJIora9tZveNbdYpfFyzeTNSjhPfuhEMP/uhVLiHyTl+2Xx4ClUro7ly /We8lKDf82Y1hkUCcxFhNz1yy5jqy6zsMA== X-Google-Smtp-Source: AGRyM1tCumZHglovbMtyxb/sPRuwC/3gbo6jG5+eC4pUpkV1+RdV6OuQH3xYPtIWVlnenmRC54ivew== X-Received: by 2002:adf:e28a:0:b0:210:b31:722 with SMTP id v10-20020adfe28a000000b002100b310722mr3216100wri.65.1657718189370; Wed, 13 Jul 2022 06:16:29 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id t63-20020a1c4642000000b003a2e05a81b3sm2216352wma.8.2022.07.13.06.16.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 06:16:28 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 04/11] submodule--helper: fix "struct pathspec" memory leaks Date: Wed, 13 Jul 2022 15:16:09 +0200 Message-Id: X-Mailer: git-send-email 2.37.0.932.g7b7031e73bc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Call clear_pathspec() at the end of various functions that work with and allocate a "struct pathspec". Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 115 +++++++++++++++++++++++++----------- 1 file changed, 81 insertions(+), 34 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 23ab9c7e349..a8e439e59b8 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -269,7 +269,7 @@ static char *get_up_path(const char *path) static int module_list(int argc, const char **argv, const char *prefix) { int i; - struct pathspec pathspec; + struct pathspec pathspec = { 0 }; struct module_list list = MODULE_LIST_INIT; struct option module_list_options[] = { @@ -278,6 +278,7 @@ static int module_list(int argc, const char **argv, const char *prefix) N_("alternative anchor for relative paths")), OPT_END() }; + int ret; const char *const git_submodule_helper_usage[] = { N_("git submodule--helper list [--prefix=] [...]"), @@ -287,8 +288,10 @@ static int module_list(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, module_list_options, git_submodule_helper_usage, 0); - if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0) - return 1; + if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0) { + ret = 1; + goto cleanup; + } for (i = 0; i < list.nr; i++) { const struct cache_entry *ce = list.entries[i]; @@ -302,7 +305,10 @@ static int module_list(int argc, const char **argv, const char *prefix) fprintf(stdout, "%s\n", ce->name); } - return 0; + ret = 0; +cleanup: + clear_pathspec(&pathspec); + return ret; } static void for_each_listed_submodule(const struct module_list *list, @@ -427,7 +433,7 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item, static int module_foreach(int argc, const char **argv, const char *prefix) { struct foreach_cb info = FOREACH_CB_INIT; - struct pathspec pathspec; + struct pathspec pathspec = { 0 }; struct module_list list = MODULE_LIST_INIT; struct option module_foreach_options[] = { @@ -441,12 +447,15 @@ static int module_foreach(int argc, const char **argv, const char *prefix) N_("git submodule foreach [--quiet] [--recursive] [--] "), NULL }; + int ret; argc = parse_options(argc, argv, prefix, module_foreach_options, git_submodule_helper_usage, 0); - if (module_list_compute(0, NULL, prefix, &pathspec, &list) < 0) - return 1; + if (module_list_compute(0, NULL, prefix, &pathspec, &list) < 0) { + ret = 1; + goto cleanup; + } info.argc = argc; info.argv = argv; @@ -454,7 +463,10 @@ static int module_foreach(int argc, const char **argv, const char *prefix) for_each_listed_submodule(&list, runcommand_in_submodule_cb, &info); - return 0; + ret = 0; +cleanup: + clear_pathspec(&pathspec); + return ret; } static int starts_with_dot_slash(const char *const path) @@ -562,7 +574,7 @@ static void init_submodule_cb(const struct cache_entry *list_item, void *cb_data static int module_init(int argc, const char **argv, const char *prefix) { struct init_cb info = INIT_CB_INIT; - struct pathspec pathspec; + struct pathspec pathspec = { 0 }; struct module_list list = MODULE_LIST_INIT; int quiet = 0; @@ -575,12 +587,15 @@ static int module_init(int argc, const char **argv, const char *prefix) N_("git submodule init [] []"), NULL }; + int ret; argc = parse_options(argc, argv, prefix, module_init_options, git_submodule_helper_usage, 0); - if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0) - return 1; + if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0) { + ret = 1; + goto cleanup; + } /* * If there are no path args and submodule.active is set then, @@ -595,7 +610,10 @@ static int module_init(int argc, const char **argv, const char *prefix) for_each_listed_submodule(&list, init_submodule_cb, &info); - return 0; + ret = 0; +cleanup: + clear_pathspec(&pathspec); + return ret; } struct status_cb { @@ -740,7 +758,7 @@ static void status_submodule_cb(const struct cache_entry *list_item, static int module_status(int argc, const char **argv, const char *prefix) { struct status_cb info = STATUS_CB_INIT; - struct pathspec pathspec; + struct pathspec pathspec = { 0 }; struct module_list list = MODULE_LIST_INIT; int quiet = 0; @@ -755,12 +773,15 @@ static int module_status(int argc, const char **argv, const char *prefix) N_("git submodule status [--quiet] [--cached] [--recursive] [...]"), NULL }; + int ret; argc = parse_options(argc, argv, prefix, module_status_options, git_submodule_helper_usage, 0); - if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0) - return 1; + if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0) { + ret = 1; + goto cleanup; + } info.prefix = prefix; if (quiet) @@ -768,7 +789,10 @@ static int module_status(int argc, const char **argv, const char *prefix) for_each_listed_submodule(&list, status_submodule_cb, &info); - return 0; + ret = 0; +cleanup: + clear_pathspec(&pathspec); + return ret; } static int module_name(int argc, const char **argv, const char *prefix) @@ -1105,7 +1129,7 @@ static int compute_summary_module_list(struct object_id *head_oid, struct strvec diff_args = STRVEC_INIT; struct rev_info rev; struct module_cb_list list = MODULE_CB_LIST_INIT; - int ret = 0; + int ret; strvec_push(&diff_args, get_diff_cmd(diff_cmd)); if (info->cached) @@ -1145,6 +1169,7 @@ static int compute_summary_module_list(struct object_id *head_oid, else run_diff_files(&rev, 0); prepare_submodule_summary(info, &list); + ret = 0; cleanup: strvec_clear(&diff_args); release_revisions(&rev); @@ -1326,10 +1351,11 @@ static void sync_submodule_cb(const struct cache_entry *list_item, void *cb_data static int module_sync(int argc, const char **argv, const char *prefix) { struct sync_cb info = SYNC_CB_INIT; - struct pathspec pathspec; + struct pathspec pathspec = { 0 }; struct module_list list = MODULE_LIST_INIT; int quiet = 0; int recursive = 0; + int ret; struct option module_sync_options[] = { OPT__QUIET(&quiet, N_("suppress output of synchronizing submodule url")), @@ -1346,8 +1372,10 @@ static int module_sync(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, module_sync_options, git_submodule_helper_usage, 0); - if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0) - return 1; + if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0) { + ret = 1; + goto cleanup; + } info.prefix = prefix; if (quiet) @@ -1357,7 +1385,10 @@ static int module_sync(int argc, const char **argv, const char *prefix) for_each_listed_submodule(&list, sync_submodule_cb, &info); - return 0; + ret = 0; +cleanup: + clear_pathspec(&pathspec); + return ret; } struct deinit_cb { @@ -1464,7 +1495,7 @@ static void deinit_submodule_cb(const struct cache_entry *list_item, static int module_deinit(int argc, const char **argv, const char *prefix) { struct deinit_cb info = DEINIT_CB_INIT; - struct pathspec pathspec; + struct pathspec pathspec = { 0 }; struct module_list list = MODULE_LIST_INIT; int quiet = 0; int force = 0; @@ -1481,6 +1512,7 @@ static int module_deinit(int argc, const char **argv, const char *prefix) N_("git submodule deinit [--quiet] [-f | --force] [--all | [--] [...]]"), NULL }; + int ret; argc = parse_options(argc, argv, prefix, module_deinit_options, git_submodule_helper_usage, 0); @@ -1494,8 +1526,10 @@ static int module_deinit(int argc, const char **argv, const char *prefix) if (!argc && !all) die(_("Use '--all' if you really want to deinitialize all submodules")); - if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0) - return 1; + if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0) { + ret = 1; + goto cleanup; + } info.prefix = prefix; if (quiet) @@ -1505,7 +1539,10 @@ static int module_deinit(int argc, const char **argv, const char *prefix) for_each_listed_submodule(&list, deinit_submodule_cb, &info); - return 0; + ret = 0; +cleanup: + clear_pathspec(&pathspec); + return ret; } struct module_clone_data { @@ -2568,7 +2605,7 @@ static int update_submodules(struct update_data *update_data) static int module_update(int argc, const char **argv, const char *prefix) { - struct pathspec pathspec; + struct pathspec pathspec = { 0 }; struct update_data opt = UPDATE_DATA_INIT; struct list_objects_filter_options filter_options = { 0 }; int ret; @@ -2647,8 +2684,8 @@ static int module_update(int argc, const char **argv, const char *prefix) opt.update_strategy.type = opt.update_default; if (module_list_compute(argc, argv, prefix, &pathspec, &opt.list) < 0) { - list_objects_filter_release(&filter_options); - return 1; + ret = 1; + goto cleanup; } if (pathspec.nr) @@ -2659,8 +2696,10 @@ static int module_update(int argc, const char **argv, const char *prefix) struct init_cb info = INIT_CB_INIT; if (module_list_compute(argc, argv, opt.prefix, - &pathspec, &list) < 0) - return 1; + &pathspec, &list) < 0) { + ret = 1; + goto cleanup; + } /* * If there are no path args and submodule.active is set then, @@ -2677,7 +2716,9 @@ static int module_update(int argc, const char **argv, const char *prefix) } ret = update_submodules(&opt); +cleanup: list_objects_filter_release(&filter_options); + clear_pathspec(&pathspec); return ret; } @@ -2761,9 +2802,10 @@ static int push_check(int argc, const char **argv, const char *prefix) static int absorb_git_dirs(int argc, const char **argv, const char *prefix) { int i; - struct pathspec pathspec; + struct pathspec pathspec = { 0 }; struct module_list list = MODULE_LIST_INIT; unsigned flags = ABSORB_GITDIR_RECURSE_SUBMODULES; + int ret; struct option embed_gitdir_options[] = { OPT_STRING(0, "prefix", &prefix, @@ -2782,13 +2824,18 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, embed_gitdir_options, git_submodule_helper_usage, 0); - if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0) - return 1; + if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0) { + ret = 1; + goto cleanup; + } for (i = 0; i < list.nr; i++) absorb_git_dir_into_superproject(list.entries[i]->name, flags); - return 0; + ret = 0; +cleanup: + clear_pathspec(&pathspec); + return ret; } static int is_active(int argc, const char **argv, const char *prefix) From patchwork Wed Jul 13 13:16:10 2022 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: 12916684 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 95EEDC433EF for ; Wed, 13 Jul 2022 13:16:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235820AbiGMNQk (ORCPT ); Wed, 13 Jul 2022 09:16:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236176AbiGMNQe (ORCPT ); Wed, 13 Jul 2022 09:16:34 -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 34C559590 for ; Wed, 13 Jul 2022 06:16:32 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id f2so15453733wrr.6 for ; Wed, 13 Jul 2022 06:16:32 -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=PT4r1yzmQUrvMOnCokcj/QQVnA1aOOX56hdxJnDk4Qo=; b=kTMWsw9FCxekf8M6M02jLc/dw0FziEkqL6eRtcA/4r8+dLZ5Krj+0sSauNbVxjAklW WQW5DHKNeujebrEyS6/GFDnUdKU+xVG659/BGCztARyU+Tqby2FqzYUvPJwIVMgVVPHE 48h9NeyWMzzOx6Ir3My3/gdfWqWlfNnQkXNijYxemRlQaJrsJ5YDjK+pEXg0LTM2VsL2 usmFaKpsHiZkVvlkvPd5qud5REmczacHI2nwr6YkMDfewBD9ZPlpGVkIjbOE35eOKk7l NDyJEZCVL7npb06TlNAp3nk5HuPCCWSKX80FBuxOsx5r/4bDzxPhs20RkWf0gcJPVpQn A3Mg== 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=PT4r1yzmQUrvMOnCokcj/QQVnA1aOOX56hdxJnDk4Qo=; b=4ju0uAubLxeInGo3or0B95Z2oU5izqaARyxylQAnLNX5hl9XPDbln4r/7XVh3e45J9 /7un3DUsXtVLbS1vXr7/4RxsRwXxW035VevN0Xuybu+JrzyIRoON5qzyVHVLZfUrZsoL tL47So64Ll9OqwcyHgHKcS8sCJKSPkjSPc6pp9rz4H2zq8sevmQ9LCfLAN5hCh88m0DW fsGgre0EO/L7r1FLFFQf/tj2R5UHm+4LvBQlAH/PNU7LxaPkhYTH9FLHoOuwpFiAHKRZ Bv5Q387wuRufnAHEAot9z+tELUFHB4VkqtKTWYChzfZDQx6cdaEnTSol9hJVWtG8gMFR SFyg== X-Gm-Message-State: AJIora+yDLemAYk5A4iw8PHZ4xf8bF24NRigwHrn3dxmwn1gjQBSUjNH +aF2UZhbQMS513bEnnh1Ko6icJyr7BD69A== X-Google-Smtp-Source: AGRyM1tjvBdeWfS3FsW8ZC9dWh2TflJzndamu/lH9XsYlmJ8JN9xB/O0j/2iyUni8XmfW0sYESYhSw== X-Received: by 2002:adf:f38f:0:b0:21d:66b5:21c with SMTP id m15-20020adff38f000000b0021d66b5021cmr3288449wro.144.1657718190488; Wed, 13 Jul 2022 06:16:30 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id t63-20020a1c4642000000b003a2e05a81b3sm2216352wma.8.2022.07.13.06.16.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 06:16:29 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 05/11] submodule--helper: free() leaking {run,capture}_command() argument Date: Wed, 13 Jul 2022 15:16:10 +0200 Message-Id: X-Mailer: git-send-email 2.37.0.932.g7b7031e73bc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Free the "dir" member of "struct child_process" that various functions in submodule-helper.c allocate allocates with xstrdup(). Since the "dir" argument is "const char *" let's keep a "char *to_free" variable around for this rather than casting when we call free(). Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 41 +++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index a8e439e59b8..2099c5774b2 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2198,27 +2198,36 @@ static int is_tip_reachable(const char *path, struct object_id *oid) struct child_process cp = CHILD_PROCESS_INIT; struct strbuf rev = STRBUF_INIT; char *hex = oid_to_hex(oid); + char *to_free; + int ret; cp.git_cmd = 1; - cp.dir = xstrdup(path); + cp.dir = to_free = xstrdup(path); cp.no_stderr = 1; strvec_pushl(&cp.args, "rev-list", "-n", "1", hex, "--not", "--all", NULL); prepare_submodule_repo_env(&cp.env); - if (capture_command(&cp, &rev, GIT_MAX_HEXSZ + 1) || rev.len) - return 0; + if (capture_command(&cp, &rev, GIT_MAX_HEXSZ + 1) || rev.len) { + ret = 0; + goto cleanup; + } - return 1; + ret = 1; +cleanup: + free(to_free); + return ret; } static int fetch_in_submodule(const char *module_path, int depth, int quiet, struct object_id *oid) { struct child_process cp = CHILD_PROCESS_INIT; + char *to_free; + int ret; prepare_submodule_repo_env(&cp.env); cp.git_cmd = 1; - cp.dir = xstrdup(module_path); + cp.dir = to_free = xstrdup(module_path); strvec_push(&cp.args, "fetch"); if (quiet) @@ -2232,7 +2241,9 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet, str free(remote); } - return run_command(&cp); + ret = run_command(&cp); + free(to_free); + return ret; } static int run_update_command(struct update_data *ud, int subforce) @@ -2240,6 +2251,8 @@ static int run_update_command(struct update_data *ud, int subforce) struct child_process cp = CHILD_PROCESS_INIT; char *oid = oid_to_hex(&ud->oid); int must_die_on_failure = 0; + char *to_free; + int ret; switch (ud->update_strategy.type) { case SM_UPDATE_CHECKOUT: @@ -2273,7 +2286,7 @@ static int run_update_command(struct update_data *ud, int subforce) } strvec_push(&cp.args, oid); - cp.dir = xstrdup(ud->sm_path); + cp.dir = to_free = xstrdup(ud->sm_path); prepare_submodule_repo_env(&cp.env); if (run_command(&cp)) { switch (ud->update_strategy.type) { @@ -2301,11 +2314,14 @@ static int run_update_command(struct update_data *ud, int subforce) exit(128); /* the command failed, but update must continue */ - return 1; + ret = 1; + goto cleanup; } - if (ud->quiet) - return 0; + if (ud->quiet) { + ret = 0; + goto cleanup; + } switch (ud->update_strategy.type) { case SM_UPDATE_CHECKOUT: @@ -2329,7 +2345,10 @@ static int run_update_command(struct update_data *ud, int subforce) submodule_strategy_to_string(&ud->update_strategy)); } - return 0; + ret = 0; +cleanup: + free(to_free); + return ret; } static int run_update_procedure(struct update_data *ud) From patchwork Wed Jul 13 13:16:11 2022 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: 12916687 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 356CEC43334 for ; Wed, 13 Jul 2022 13:16:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236263AbiGMNQq (ORCPT ); Wed, 13 Jul 2022 09:16:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236221AbiGMNQh (ORCPT ); Wed, 13 Jul 2022 09:16:37 -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 72CAD11473 for ; Wed, 13 Jul 2022 06:16:33 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id v16so15435469wrd.13 for ; Wed, 13 Jul 2022 06:16:33 -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=f7EIr2ouVyGIb9wMj+zPRZlLs6BZL8FuFoUJKmoK15M=; b=epW6b2y3sPXW3AV5iIPpGYwcBsYUWm5a1eZ2uG6+aNoTvMeIpM2EcxB0sIW+fYfPIS EjgOZkTq80E9G31+n1HR1VSoSobIBxMoCkeSuNE8fzHNjmRdOjXSw0rdOrC4nAM5dJcQ j8/g1zu3T8svtH3QYGd/5T1EmDmQdAd0Cm/gcD55IXF3sNWs+w7i7RMosSFZ8aHK5Q6h 03WI8dg/qYk8Gx5DIWQUg+Vwl1lVnB+b2zt0Ja0ejSL2DZzUEur3wLrkh2ZfTcrlToSu +g/cXIt4C1RPHs+FLDOQRpVk2gbsKCG0GvKG6uRsLfKfeEvOKqtKVHfGzNTL59ENnCK0 BUlQ== 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=f7EIr2ouVyGIb9wMj+zPRZlLs6BZL8FuFoUJKmoK15M=; b=7iA4V2KCVo3K0chosNNOp1wnPWPmgig8P5GrYLZN1QbGK7U5gFaW8FJO+891a1R5Cv tSHOx39Qtg7FADMxkHCDcAMNEnToEjYScDs90Njp8sUSDlj4drTb6yLYY36s9TIeVeQG gFMGjlN04JgXoStK+0fw/iMhexNXNbalP85Q8rBgbQzJjOzvJFffhNyIf2AoED+P9CxW moHuX3ZZbZsYdh9JFIERVCLKuPNyipARdhQy5Bdc4ebPdBh4BcVwTJH4NZrGbvs3kfPn tHbAarWkxdmmdIusetKnelQiPwVS3wZvSRG3JR9FhJSB01PsMqGZ/0h6quIPILW2+fWt C0JQ== X-Gm-Message-State: AJIora8ygOGt7HEjjZGMc3n6i1oafhbCekiAP4vtXMvI+XisE4ZOutH3 apZJJYPzcZsrEfUuzYv0DX+TagxsGp4kvA== X-Google-Smtp-Source: AGRyM1sJOZJk6pBvyXkhrhSzpnrIRNmGPvIXZ+6Cj79iBr5Xr9vEkvQq0HI2Tu4ly+xSLYwZfxIkLg== X-Received: by 2002:adf:facc:0:b0:21d:8c8f:4b51 with SMTP id a12-20020adffacc000000b0021d8c8f4b51mr3150546wrs.307.1657718191398; Wed, 13 Jul 2022 06:16:31 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id t63-20020a1c4642000000b003a2e05a81b3sm2216352wma.8.2022.07.13.06.16.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 06:16:30 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 06/11] submodule--helper: add and use *_release() functions Date: Wed, 13 Jul 2022 15:16:11 +0200 Message-Id: X-Mailer: git-send-email 2.37.0.932.g7b7031e73bc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add release functions for "struct module_list", "struct submodule_update_clone" and "struct update_data". For now we're leaving some of the "struct update_data" members, we'll deal with those in a subsequent commit. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 30 +++++++++++++++++++++++++++++- t/t6134-pathspec-in-submodule.sh | 1 + 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 2099c5774b2..a964dbeec38 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -182,6 +182,11 @@ struct module_list { }; #define MODULE_LIST_INIT { 0 } +static void module_list_release(struct module_list *ml) +{ + free(ml->entries); +} + static int module_list_compute(int argc, const char **argv, const char *prefix, struct pathspec *pathspec, @@ -243,7 +248,7 @@ static void module_list_active(struct module_list *list) active_modules.entries[active_modules.nr++] = ce; } - free(list->entries); + module_list_release(list); *list = active_modules; } @@ -307,6 +312,7 @@ static int module_list(int argc, const char **argv, const char *prefix) } ret = 0; cleanup: + module_list_release(&list); clear_pathspec(&pathspec); return ret; } @@ -465,6 +471,7 @@ static int module_foreach(int argc, const char **argv, const char *prefix) ret = 0; cleanup: + module_list_release(&list); clear_pathspec(&pathspec); return ret; } @@ -612,6 +619,7 @@ static int module_init(int argc, const char **argv, const char *prefix) ret = 0; cleanup: + module_list_release(&list); clear_pathspec(&pathspec); return ret; } @@ -791,6 +799,7 @@ static int module_status(int argc, const char **argv, const char *prefix) ret = 0; cleanup: + module_list_release(&list); clear_pathspec(&pathspec); return ret; } @@ -1387,6 +1396,7 @@ static int module_sync(int argc, const char **argv, const char *prefix) ret = 0; cleanup: + module_list_release(&list); clear_pathspec(&pathspec); return ret; } @@ -1541,6 +1551,7 @@ static int module_deinit(int argc, const char **argv, const char *prefix) ret = 0; cleanup: + module_list_release(&list); clear_pathspec(&pathspec); return ret; } @@ -1910,6 +1921,13 @@ struct submodule_update_clone { }; #define SUBMODULE_UPDATE_CLONE_INIT { 0 } +static void submodule_update_clone_release(struct submodule_update_clone *suc) +{ + /* Not "update_data", owned by update_data_release() */ + free(suc->update_clone); + free(suc->failed_clones); +} + struct update_data { const char *prefix; const char *displaypath; @@ -1948,6 +1966,11 @@ struct update_data { .max_jobs = 1, \ } +static void update_data_release(struct update_data *ud) +{ + module_list_release(&ud->list); +} + static void next_submodule_warn_missing(struct submodule_update_clone *suc, struct strbuf *out, const char *displaypath) { @@ -2618,6 +2641,7 @@ static int update_submodules(struct update_data *update_data) } cleanup: + submodule_update_clone_release(&suc); string_list_clear(&update_data->references, 0); return res; } @@ -2716,6 +2740,7 @@ static int module_update(int argc, const char **argv, const char *prefix) if (module_list_compute(argc, argv, opt.prefix, &pathspec, &list) < 0) { + module_list_release(&list); ret = 1; goto cleanup; } @@ -2732,10 +2757,12 @@ static int module_update(int argc, const char **argv, const char *prefix) info.flags |= OPT_QUIET; for_each_listed_submodule(&list, init_submodule_cb, &info); + module_list_release(&list); } ret = update_submodules(&opt); cleanup: + update_data_release(&opt); list_objects_filter_release(&filter_options); clear_pathspec(&pathspec); return ret; @@ -2854,6 +2881,7 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) ret = 0; cleanup: clear_pathspec(&pathspec); + module_list_release(&list); return ret; } diff --git a/t/t6134-pathspec-in-submodule.sh b/t/t6134-pathspec-in-submodule.sh index 0f1cb49cedc..3a241f259de 100755 --- a/t/t6134-pathspec-in-submodule.sh +++ b/t/t6134-pathspec-in-submodule.sh @@ -2,6 +2,7 @@ test_description='test case exclude pathspec' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup a submodule' ' From patchwork Wed Jul 13 13:16:12 2022 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: 12916685 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 3F738C433EF for ; Wed, 13 Jul 2022 13:16:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236258AbiGMNQn (ORCPT ); Wed, 13 Jul 2022 09:16:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236188AbiGMNQg (ORCPT ); Wed, 13 Jul 2022 09:16:36 -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 50958A191 for ; Wed, 13 Jul 2022 06:16:34 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id r127-20020a1c4485000000b003a2fb7c1274so739084wma.1 for ; Wed, 13 Jul 2022 06:16:34 -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=tQmzShT7Je3PaWIUEp8jdQdwVx8CAAGRUYVGVw/PTrE=; b=IIRCOJyMismLL5jBn5TKRaKlKkvstLsz+JTwqW4pPYgp4pGiC+4WnkwA6itZ+rAr82 ie6m+NXrUzE2ZTRnxABUk15JoUt39VdlD/qo8d4v3QFsw6l8NXOM1yhFPM8xFo6y++yg z7Zq91aAza02fXNeYgBoIDD92GH4ezPYRVaEFb8iVzDc84CcPFvHSQNBY1B4c9XHnv0o Ls25kMO+5oQa8yLUnqsaSnw7vIasyGfs4c64kqH0RYWr6ugW23iHQOtSB0/efzASKi7G OnZrloGttF1A6wkUM1WYFDLqp+7SUHTu7ieuCgSHBtgTWMNRguv6cBCqF7FJbvHUJ6yS or/A== 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=tQmzShT7Je3PaWIUEp8jdQdwVx8CAAGRUYVGVw/PTrE=; b=q7eROYLJM8Qz7/s5+Q/zdnUMt6brVsNJjmZOF4w6t+inKthWU55qCshlJH8Aq3hQsv qvsJcduwN3gp49M5rL+wq8KgCKkIGVCrDOWxkqZ7WcxuEg37r0B2NmIpvg75rU0IOw/J D0vvxyD786VNmetG+9Mch4p5nRmlIeXlxm9cLqqoWcpDgwmy570/49KhMTTTDFL7xG1/ kFPJ6ie1O1L1Z8cPB+cmU9XwmwcTFlV+yyc1rv2wcMrGGOqI+YVJpoxIpdGvyJYbXGYe DqgBhxItyF3HPkJKHmAj1IK0XypFHRNCBr0nZjOQE5dt+7gg8JG6cfBpAwf5HnRP5+Eu 9Yyg== X-Gm-Message-State: AJIora9wUwPgZusYLSniLyrxJIu7o4dU1O3BlZRXIthpyBxCSX7qjqma crDqrFofGKSyLzJ383txvOmk2dVXBZXRlw== X-Google-Smtp-Source: AGRyM1u37LBI8LZIIW3v7uBUdx2chRfAesbBQ0ujO1CY6wrQALAU6cz//dkwkb5M5TXieEPOTDVfwA== X-Received: by 2002:a7b:cc82:0:b0:3a2:f0c8:c5d4 with SMTP id p2-20020a7bcc82000000b003a2f0c8c5d4mr3673467wma.86.1657718192377; Wed, 13 Jul 2022 06:16:32 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id t63-20020a1c4642000000b003a2e05a81b3sm2216352wma.8.2022.07.13.06.16.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 06:16:31 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 07/11] submodule--helper: fix "errmsg_str" memory leak Date: Wed, 13 Jul 2022 15:16:12 +0200 Message-Id: X-Mailer: git-send-email 2.37.0.932.g7b7031e73bc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a memory leak introduced in e83e3333b57 (submodule: port submodule subcommand 'summary' from shell to C, 2020-08-13), to do that stop juggling around the "errmsg" and "struct strbuf", let's instead move the "struct strbuf errmsg" to the top-level. Now we don't need to strbuf_detach() it anymore, but we do need to ensure that we pass NULL to print_submodule_summary() when we have no error message. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index a964dbeec38..a05578a7382 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -932,7 +932,8 @@ static void generate_submodule_summary(struct summary_cb *info, { char *displaypath, *src_abbrev = NULL, *dst_abbrev; int missing_src = 0, missing_dst = 0; - char *errmsg = NULL; + char *errmsg; + struct strbuf errmsg_str = STRBUF_INIT; int total_commits = -1; if (!info->cached && oideq(&p->oid_dst, null_oid())) { @@ -1032,7 +1033,6 @@ static void generate_submodule_summary(struct summary_cb *info, * submodule, i.e., deleted or changed to blob */ if (S_ISGITLINK(p->mod_dst)) { - struct strbuf errmsg_str = STRBUF_INIT; if (missing_src && missing_dst) { strbuf_addf(&errmsg_str, " Warn: %s doesn't contain commits %s and %s\n", displaypath, oid_to_hex(&p->oid_src), @@ -1043,10 +1043,10 @@ static void generate_submodule_summary(struct summary_cb *info, oid_to_hex(&p->oid_src) : oid_to_hex(&p->oid_dst)); } - errmsg = strbuf_detach(&errmsg_str, NULL); } } + errmsg = errmsg_str.len ? errmsg_str.buf : NULL; print_submodule_summary(info, errmsg, total_commits, displaypath, src_abbrev, dst_abbrev, p); @@ -1054,6 +1054,7 @@ static void generate_submodule_summary(struct summary_cb *info, free(displaypath); free(src_abbrev); free(dst_abbrev); + strbuf_release(&errmsg_str); } static void prepare_submodule_summary(struct summary_cb *info, From patchwork Wed Jul 13 13:16:13 2022 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: 12916686 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 1C472C43334 for ; Wed, 13 Jul 2022 13:16:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236259AbiGMNQo (ORCPT ); Wed, 13 Jul 2022 09:16:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236215AbiGMNQh (ORCPT ); Wed, 13 Jul 2022 09:16:37 -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 11BD0E4F for ; Wed, 13 Jul 2022 06:16:34 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id z12so15472516wrq.7 for ; Wed, 13 Jul 2022 06:16:34 -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=QKY6NYDDq6NtOQXjMPNnhM2DPgBkcOaPOKNh9JVbgHw=; b=OVgszPq1KAZrHfyTHvl3mFp377w4OoLzNqDI9B+QBd2e4hy3oeZIpzlM/6Qei8kJOH aekd4w5SA2odEVb6VhYkb1cVuINPX7USp8JP6IUPmyc0In8EZ2yI+osDGSEI7BEVchrJ PbmAL9SqkPy+zcOHpyONEuRFldNtsQ+QUg5X5P8mnbOSU3SQqLqaH+5cqn1MFqe7fiSu SL6QSG47pob4Zljl4C+MDInVdmIMQanc8nk+trp92yA3OkfKdqvWqJ720JdgLtkDxsFM 9s+D7c7XAAIZqlsYkHAIaZrNFpjBhKH+ADojuXNqfZTRIQO+wJLjtsZRISlOAONxyqya cMSg== 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=QKY6NYDDq6NtOQXjMPNnhM2DPgBkcOaPOKNh9JVbgHw=; b=aQQrqee+OHmcILZuAdV9mSJj/2Cjfzucjcbb98/ifgsOFdw9vFipPhm2k82E5Hs93P ialJtirVByE6R1WgLOX9w0y8Ho58E6CsDw58G5aaJvPae7nOJyMQCZhpwAIOzU+5pUdG ZP4Cm/dFMtAFCTDX1xaVWPp3LmU1GBeuy5N2Hw5hty8j5YiKAjg9cEYjmLzom/0RBRQp 7AE0epiSNDOGXhP+dntjQh0n3qkTQHvmecNfPdcCm+P73BipNXBSnoEq74m1Hki+A5AN XboDtzs0P7VfyRZtTH2rB9qPnHnTZNoEtdQMYzCT+IIu7n2M1z8z3mSRjHZu7stWNIbm DFXg== X-Gm-Message-State: AJIora/kcb9rp7hYoJIJgMGRxigs9Tfejq020eV5z44NfXusYPYbYek7 5/sh1FV797H5z5A2b8tUNS14usUCICkHNA== X-Google-Smtp-Source: AGRyM1ty5B2BxkF4l8b78kCjrh6t/F9IhsCaprDn/C8IQVdluWEBx6L4mHtRXNdg3TrxgiyqzdYN+g== X-Received: by 2002:adf:d1e8:0:b0:21d:ac9c:983d with SMTP id g8-20020adfd1e8000000b0021dac9c983dmr3137382wrd.629.1657718193291; Wed, 13 Jul 2022 06:16:33 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id t63-20020a1c4642000000b003a2e05a81b3sm2216352wma.8.2022.07.13.06.16.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 06:16:32 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 08/11] submodule--helper: fix "sm_path" and other "module_cb_list" leaks Date: Wed, 13 Jul 2022 15:16:13 +0200 Message-Id: X-Mailer: git-send-email 2.37.0.932.g7b7031e73bc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix leaks in "struct module_cb_list" and the "struct module_cb" which it contains, these fixes leaks in e83e3333b57 (submodule: port submodule subcommand 'summary' from shell to C, 2020-08-13). The "sm_path" should always have been a "char *", not a "const char *", we always create it with xstrdup(). We can't mark any tests passing passing with SANITIZE=leak using "TEST_PASSES_SANITIZE_LEAK=true" as a result of this change, but "t7401-submodule-summary.sh" gets closer to passing as a result of this change. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index a05578a7382..2b44f391f15 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -828,9 +828,13 @@ struct module_cb { struct object_id oid_src; struct object_id oid_dst; char status; - const char *sm_path; + char *sm_path; }; #define MODULE_CB_INIT { 0 } +static void module_cb_release(struct module_cb *mcb) +{ + free(mcb->sm_path); +} struct module_cb_list { struct module_cb **entries; @@ -838,6 +842,19 @@ struct module_cb_list { }; #define MODULE_CB_LIST_INIT { 0 } +static void module_cb_list_release(struct module_cb_list *mcbl) +{ + int i; + + for (i = 0; i < mcbl->nr; i++) { + struct module_cb *mcb = mcbl->entries[i]; + + module_cb_release(mcb); + free(mcb); + } + free(mcbl->entries); +} + struct summary_cb { int argc; const char **argv; @@ -1183,6 +1200,7 @@ static int compute_summary_module_list(struct object_id *head_oid, cleanup: strvec_clear(&diff_args); release_revisions(&rev); + module_cb_list_release(&list); return ret; } From patchwork Wed Jul 13 13:16:14 2022 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: 12916689 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 4A85CC43334 for ; Wed, 13 Jul 2022 13:16:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235444AbiGMNQv (ORCPT ); Wed, 13 Jul 2022 09:16:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236185AbiGMNQk (ORCPT ); Wed, 13 Jul 2022 09:16:40 -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 953ED12D27 for ; Wed, 13 Jul 2022 06:16:36 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id z12so15472668wrq.7 for ; Wed, 13 Jul 2022 06:16:36 -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=k2IR5AYMQjDQMTEKCnHr8D5TPBFdEWrjobcPUsIQycw=; b=qp2r2y4U9hW9SsoAMh9vrM5F5f8KxieN/X39Oi26WCYK+MLH1NBBSS+Aajdx91pakF k6/atrFBMr1H9AhviyoSv6LqaCSgfMFFHFW3LBW+Rhgpk1DOVCoJLE647bQAj/c2c5bY suYNq3L81jSJ/PU6r2XKNbRR4hCK6HQJfcgnWsknoXwkwV/Bvbgdl+gYFiQQMgVwDhZd b5CFyEABI8/P4WOVpIpHUyFqkrFaMW6C/iCFaslnydj+jDvkNigFctHrEUuNKW9cOE0G 199jwxn8lGSLznlDBiQeEpYdiueZJvZNHntYXvoI9jYjLyuyeYOpUslnsLtHwvUgCtQ9 FPNA== 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=k2IR5AYMQjDQMTEKCnHr8D5TPBFdEWrjobcPUsIQycw=; b=OQdmA0C+76r6UBq6jxjdLZmSXsuHWBJsD6ezJc1LLHfCPcDgO4s3KeXjAcKfSGqKNW 3plIxbdNcLvj/XYI/ZwyZLR4YHxmv/Etb4I0KaLD63w3jr3rpLgI6JpbwGtHUHFZ40G9 mVgQTkRp4DiB+cejrQ9tRTHuIuyHSA9IAsgvNGMKFjgLowD+1EZpAeZhC0Og5V5yfD6r wLR4UYTlbVi3sQGkkSO29e6M3oL+Ont5cuAtZKpJaM92vVVea/OihpveGfxnydDPpvoN +EmRKtMncPQCY2Pbh4wj8mM2CeVlQPyuY4yemWys86MqTfuPnft3h5Tkg7U0tbeNk3T2 nRVg== X-Gm-Message-State: AJIora+kZZSDxmZjvnvigOYnhiOqUmLrNMLOh+4unuZJtt5EITIn9c5z 8xlT2u1otNrbzCmhnvOv3FdUMAtN8Ylpbg== X-Google-Smtp-Source: AGRyM1u1WVfgMSaTslp9Tlm1DCUWerd5woBTbgLELmuQnjPZ5GE+NFWU8+JLB4LFLgT2u9ZjxxdfDA== X-Received: by 2002:a5d:5985:0:b0:21d:b6aa:23f5 with SMTP id n5-20020a5d5985000000b0021db6aa23f5mr3385089wri.18.1657718194353; Wed, 13 Jul 2022 06:16:34 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id t63-20020a1c4642000000b003a2e05a81b3sm2216352wma.8.2022.07.13.06.16.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 06:16:33 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 09/11] submodule--helper: free "char *" in "struct update_data" Date: Wed, 13 Jul 2022 15:16:14 +0200 Message-Id: X-Mailer: git-send-email 2.37.0.932.g7b7031e73bc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Make the update_data_release() function free the "recursive_prefix" and "displaypath" members when appropriate. For the former it could come from either "argv" or from our own allocation, so we need to keep track of a "to_free" sibling seperately. For "displaypath" it's always ours, so the "const char *" type was wrong to begin with, it should be a "char *" instead. For update_submodule() we'll free() these as we go along, it's called in a loop by update_submodules(), and we'll need to free the "last" one. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 2b44f391f15..0bac39880d2 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1949,7 +1949,7 @@ static void submodule_update_clone_release(struct submodule_update_clone *suc) struct update_data { const char *prefix; - const char *displaypath; + char *displaypath; enum submodule_update_type update_default; struct object_id suboid; struct string_list references; @@ -1987,6 +1987,7 @@ struct update_data { static void update_data_release(struct update_data *ud) { + free(ud->displaypath); module_list_release(&ud->list); } From patchwork Wed Jul 13 13:16:15 2022 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: 12916688 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 9FD10C43334 for ; Wed, 13 Jul 2022 13:16:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236280AbiGMNQt (ORCPT ); Wed, 13 Jul 2022 09:16:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236181AbiGMNQj (ORCPT ); Wed, 13 Jul 2022 09:16:39 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58ED66335 for ; Wed, 13 Jul 2022 06:16:36 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id r10so9313734wrv.4 for ; Wed, 13 Jul 2022 06:16:36 -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=OmZbS6YzIAmUCogA+OdgBOA0PZ4LHSGCDj1zill1wG4=; b=qpdYHlVzGJenPL6fVS07mrUkbCur5xPteq2JX51xSI8kEEb8Fy0ydPddiuyqsldQsC XPw6IscIM5gZ30sARZEZG4LP8vHZnkmz/2oJcgvnodJAJKBAg8uSuKepxGkYbZPjqInS hDulfk+SyNDG09awsBGuukyH6h4oJ6VvWPwjDlOR6nfWf2a/8FCu8LIUJVeZPU/+qAEl 7QuqKQXfzYPGfhqRBhQja5g+hSF1OHsWuo7U8QWPfmtlGMw4U+LyC8FPSBKRMIBdG5CX 5JMCDAMWJGJnUBHsBkPxg3zmzQsPaQ4Ab9IrXDbkLkS3sEvgJM716n1qunL4QMsoabzo 4pHA== 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=OmZbS6YzIAmUCogA+OdgBOA0PZ4LHSGCDj1zill1wG4=; b=Hey5mNlvnRDqgqzohUDY4h3eAcIbEe6if8xvY/PDIdagbyZegINdtCjor2wC30rScI O9Gt86uxBDm+qzfvg5CQkiIJhT+MOhZNzKavD5n3ELXtbynBk0Uf+FtbOklxhXKv9n1s UDmGHVmuM7O/+h7/wmhB46JMOzG56flc6CI5eEN9kvuEBUFzGp/9naVfo1KZv9AgIW4W D4Sh5tpjEA8ywT75Hd02iKebjTeeD35afa3DXI3JEfBUdjdtWgTdyq4alAEHAekNQYDZ HfaorSAA9sGfHOnPWkeIbb4hxFeU1xzqCQXRw7QtY2m7UpI0j0Lj0ytXeMNv/OuTihqj oWxw== X-Gm-Message-State: AJIora9Ur7ajQYG+Ql8w17YSpNYK5Nqy3KvWVfHynYSKIjC9WfiwyV2X qY8F2sBZ1Voo0H5sdezwExqvk2kLG+5iWA== X-Google-Smtp-Source: AGRyM1u+Cn8l7J1B/r05ypc68M3gcSClChRxI7Q42cA218pe9Xsb0kIDOc/l0kF9eZEU2Ik9T/cZng== X-Received: by 2002:a05:6000:2cc:b0:21d:76d7:995d with SMTP id o12-20020a05600002cc00b0021d76d7995dmr3358116wry.339.1657718195559; Wed, 13 Jul 2022 06:16:35 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id t63-20020a1c4642000000b003a2e05a81b3sm2216352wma.8.2022.07.13.06.16.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 06:16:34 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 10/11] submodule--helper: fix a leak with repo_clear() Date: Wed, 13 Jul 2022 15:16:15 +0200 Message-Id: X-Mailer: git-send-email 2.37.0.932.g7b7031e73bc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Call repo_clear() in ensure_core_worktree() to free the "struct repository". Fixes a leak that's been here since 74d4731da1f (submodule--helper: replace connect-gitdir-workingtree by ensure-core-worktree, 2018-08-13). Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 1 + t/t2403-worktree-move.sh | 1 + t/t7412-submodule-absorbgitdirs.sh | 1 + 3 files changed, 3 insertions(+) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 0bac39880d2..d9fab5d77da 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2486,6 +2486,7 @@ static void ensure_core_worktree(const char *path) free(abs_path); strbuf_release(&sb); } + repo_clear(&subrepo); } static const char *submodule_update_type_to_label(enum submodule_update_type type) diff --git a/t/t2403-worktree-move.sh b/t/t2403-worktree-move.sh index a4e1a178e0a..1168e9f9982 100755 --- a/t/t2403-worktree-move.sh +++ b/t/t2403-worktree-move.sh @@ -2,6 +2,7 @@ test_description='test git worktree move, remove, lock and unlock' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t7412-submodule-absorbgitdirs.sh b/t/t7412-submodule-absorbgitdirs.sh index 1cfa150768d..2859695c6d2 100755 --- a/t/t7412-submodule-absorbgitdirs.sh +++ b/t/t7412-submodule-absorbgitdirs.sh @@ -6,6 +6,7 @@ This test verifies that `git submodue absorbgitdirs` moves a submodules git directory into the superproject. ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup a real submodule' ' From patchwork Wed Jul 13 13:16:16 2022 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: 12916690 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 44593C433EF for ; Wed, 13 Jul 2022 13:17:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236243AbiGMNRG (ORCPT ); Wed, 13 Jul 2022 09:17:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236239AbiGMNQl (ORCPT ); Wed, 13 Jul 2022 09:16:41 -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 C376F13D68 for ; Wed, 13 Jul 2022 06:16:38 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id o4so15483651wrh.3 for ; Wed, 13 Jul 2022 06:16:38 -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=tH0HbfKTIX82++Ibo08v5ScpLAoDuEKMMWqGUqrXI5Y=; b=YOg0GgQ2hE9srngwHfS6FEUrJ1mGQgzpRd9AK3qOq8RaPkuqU4kI6tS9kZK0xqejgO 9WyncqGAiWY6aBfyr3FYHZQAodNsCb4G1vepKHWhKCnifplB84Tv9GvmKWzMza73SgW4 JcEoEvZyIUVlV0tnvtlLgTkV8TikWM6CfY5n/An2+4kKXit8Zk3iseIWWv97uSi3Itp6 p9TnPCRzdnkBv2RwWD6kbDT5mg9XwAbnm25dWi6+NPQfZZjr6AP7goQu6J/RSo34oyQc uGg1g3JHgd/NB6c/wYBh+g5P61UEDw9nlWPWcPDUs880Rh7xDAXPKJrgDPb3DLxXMong NwlQ== 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=tH0HbfKTIX82++Ibo08v5ScpLAoDuEKMMWqGUqrXI5Y=; b=DsdCklY3qAO/951S+O769OW8FEkmqNldaNASVq8wMNxVlYRoxVGjpYncc+idlepRKV HP33qHo5NtIuzmACWD/t7AlUED7hn9hh5hLcinxIApr7vbQKo3e/Li9EmAs3P/0EMwB+ MA9VIADEMM2yHGDABArkykLMIgaexa6yYr/SkiCyCdLPjYvmt63XAbYbI4gRNkwwPoXo 9ZwiuFijP+pYfGitxcWGVFMjgpf/KrOY7WTBwBMjlDD3flr1ut9ux8KNPBJAW3ZZU3dm no6iz8G56KOOPqrm1dzJUIlpfH3dyG22kiylIaLJTxjv/eHO6X+uheqf4zkBd4CNvkyQ womw== X-Gm-Message-State: AJIora9B08k6XSGMcYJd/8Z3r8smDA/BEqADn1YLWskNXpKVzRVlXUjt 8q5WrXkMZBrpDPgCepOn1h5BGzfzqNXj3g== X-Google-Smtp-Source: AGRyM1vCznLg3jX1dBSB5cSf9pPGYyzRSdI+n6JITX2N4sz4nJf1Ezduj9HhmFTfNvhacUW3Sp3arg== X-Received: by 2002:adf:eed1:0:b0:21d:7052:278a with SMTP id a17-20020adfeed1000000b0021d7052278amr3416639wrp.170.1657718196656; Wed, 13 Jul 2022 06:16:36 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id t63-20020a1c4642000000b003a2e05a81b3sm2216352wma.8.2022.07.13.06.16.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 06:16:35 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Glen Choo , Atharva Raykar , Prathamesh Chavan , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 11/11] submodule--helper: fix "reference" leak is "module_clone_data" Date: Wed, 13 Jul 2022 15:16:16 +0200 Message-Id: X-Mailer: git-send-email 2.37.0.932.g7b7031e73bc In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix leaks in the "reference" member of "struct module_clone_data" that have been with us since 31224cbdc72 (clone: recursive and reference option triggers submodule alternates, 2016-08-17) and 8c8195e9c3e (submodule--helper: introduce add-clone subcommand, 2021-07-10). Those commits added an xstrdup()'d member of the STRING_LIST_INIT_NODUP'd "struct string_list". We need to free() those, but not the ones we get from argv, let's make use of the "util" member, if it has a pointer it's the pointer we'll need to free. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index d9fab5d77da..966f543fbd9 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1598,6 +1598,7 @@ struct module_clone_data { static void module_clone_data_release(struct module_clone_data *cd) { free(cd->path_free); + string_list_clear(&cd->reference, 1); } struct submodule_alternate_setup { @@ -1652,7 +1653,9 @@ static int add_possible_reference_from_superproject( sm_alternate = compute_alternate_path(sb.buf, &err); if (sm_alternate) { - string_list_append(sas->reference, xstrdup(sb.buf)); + char *p = strbuf_detach(&sb, NULL); + + string_list_append(sas->reference, p)->util = p; free(sm_alternate); } else { switch (sas->error_mode) { @@ -3194,9 +3197,11 @@ static int add_submodule(const struct add_data *add_data) clone_data.url = add_data->realrepo; clone_data.quiet = add_data->quiet; clone_data.progress = add_data->progress; - if (add_data->reference_path) - string_list_append(&clone_data.reference, - xstrdup(add_data->reference_path)); + if (add_data->reference_path) { + char *p = xstrdup(add_data->reference_path); + + string_list_append(&clone_data.reference, p)->util = p; + } clone_data.dissociate = add_data->dissociate; if (add_data->depth >= 0) clone_data.depth = xstrfmt("%d", add_data->depth);