From patchwork Thu Jul 21 19:12:57 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: 12925696 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 8E797C43334 for ; Thu, 21 Jul 2022 19:13:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233282AbiGUTNj (ORCPT ); Thu, 21 Jul 2022 15:13:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233176AbiGUTNh (ORCPT ); Thu, 21 Jul 2022 15:13:37 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A195188757 for ; Thu, 21 Jul 2022 12:13:35 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id v67-20020a1cac46000000b003a1888b9d36so3932650wme.0 for ; Thu, 21 Jul 2022 12:13:35 -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=/OJ7NIApgLVlls5zt0PNhmMbdxijbSDt9jjArUHUgck=; b=Opr/BXKv2wv5b3W8iedCiTCJIV8OLOShB+EgUzQzgVfZVhvNdOs9xmJBHLVSfj3T9v zzT6K3h68FoEZdXBZJ8O6lAbSBTrI9XSS3NqRHTMTCQTWgDMvej1+gCyTpo+inxhzJuo 8QZDf+o1VRzWJPb2ZQzvQi0lAXRU9QFfPrHryZ0SDfjgCwSf8PcMKBxraFwr7avnXjxX dG7TfKyG093chlwPoSWPk8NPHMUrG/+6MYB08WqcGKMIIC9DJElWy/Zz2L7xMHUS5boS cp+6NzMZOn6ZY04a4KXSOzC/sjvAJ0RJPIjDgLCwoUt9loYKk8ThLFTCB3S6R4pkOZtS GJTw== 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=/OJ7NIApgLVlls5zt0PNhmMbdxijbSDt9jjArUHUgck=; b=cbfdEogmvQUKZ6TozD4ZupZadLY8ak5ApQjxAdS0YBVYrItmrlH5VZf2eLK5gxQqIq irzv01LrEpfobLhhjMLOYfQSbc5ebqCD9Y1m/YO4U8hCXQKxg9fc/e7G/vhY0a9V9WKz U9JlLmF06CYFZxmj3VYWK/CqgwL4vgDOpvKGx4+7Yrex6qsgfRv2RYSiSNMEI41af88c qTEgHUMMmfyY+heYuJMQVkx07nJqGG9eX6Pwy5gs4HsSXKlE/jOBn26UZ4Xat5kBQLX2 PnIlX1Lof/Y1f4fkhjGexT7ZwUvpAI6kf55eHFiEuIN8EtYQSGTrm3RWUso+WDpUTjkL f6mw== X-Gm-Message-State: AJIora/zIUPdxbxTHwLreu44U92v/L3EuorZA32wVtY0uu4rf2bUy9Wp Ivrwk8uIndatT2Y8VkpPMe7wSDXuPO7Rkg== X-Google-Smtp-Source: AGRyM1u++Y5IwcjblFVRtKTVFwFuThYUJfwG1Os9l/2ltx7TUFJOsBLWQena6JGNSNgh2RemXZqqeA== X-Received: by 2002:a05:600c:3b91:b0:3a3:1cbe:d531 with SMTP id n17-20020a05600c3b9100b003a31cbed531mr9656995wms.159.1658430813605; Thu, 21 Jul 2022 12:13:33 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h13-20020a05600016cd00b0021e4e9f6450sm2630637wrf.84.2022.07.21.12.13.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 12:13: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 v3 01/26] submodule--helper: replace memset() with { 0 }-initialization Date: Thu, 21 Jul 2022 21:12:57 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1095.g0bd6f54ba8a 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 Thu Jul 21 19:12:58 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: 12925697 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 7DCB5C43334 for ; Thu, 21 Jul 2022 19:13:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232471AbiGUTNp (ORCPT ); Thu, 21 Jul 2022 15:13:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229692AbiGUTNl (ORCPT ); Thu, 21 Jul 2022 15:13:41 -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 D0E1988740 for ; Thu, 21 Jul 2022 12:13:37 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id b6so1569663wmq.5 for ; Thu, 21 Jul 2022 12:13:37 -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=TOqjhYU91jK04HUzdyOxH4z9EhSirbod/RbA74jUA3s=; b=BDfTsSqytQU5WvVF3oCxo6gGBqtUEQ47MrpofVOLc6qf9nnKFoXvydEXRWdM4+Zvrr +gGDVZA+SAUXWG8ArGV3P7jXm2JqxmDKpyLRm8OJer+Gw2FWYU9UlvCYA+/guLgx+G64 +vSDDtl+681Fe5UoiWVVjA1wQZVHXcWC0RvkE/46ls7ZWWLixZMP3UQSixHweVxrjgOV R96zWZsx+03RU93/sxI8ZQyavvIa8w25HlQ7e73TZ0T4PaPWSr9c+LYsHQwNoU4pZK79 EfxXZXwFmurUvWMw16WgCoENCjSIUPlrRtxCp+zDPf0TjUBr/X6u6mBQ9uumHKgZsW0T U7fQ== 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=TOqjhYU91jK04HUzdyOxH4z9EhSirbod/RbA74jUA3s=; b=xIcYxIuspW4gwe0ZKs7ihRNZPfVqkq6LRsgjxIC89PW5hxJ9GSg8uuHp0XeuOozxZK 4FuJ3+wTaAW2zonp9rwkHuT1KKVGgc233VW8aa5Psbl7QqLRMUTyXZcAThEmJ3C7xuzl vTuSxZdOM4Mcw0N6eTTS3jyf+PDa0O6xXZsB1waUD4kT4xgP1Wys/mpYeoQgscy4+vjp /2dMIhFUlEqZR220ZAWEhhnIi7PAyZ96a3fz7nlXv7EwN4mHBDuZon7LBuLiH++Yj04q pWwx1k3zjGIOTSpZiplQKxvGdtPMO6VYf4NRcWfbiY/oHr81asYcAhlKgDbTXZ4oSrVr wa1A== X-Gm-Message-State: AJIora+bC04WFFp+NN9NgtOEVaSs0ByLJ3AvRgJ8Fctjkxye86RolFde vyI780fv+/vucBa2ulIFaw1tgaZKT2S3Hg== X-Google-Smtp-Source: AGRyM1se/2V/sz+aFeVnnZncotgXsv+L42lh7i3FThtVSKiZBJhDmPa7t+GWABQyhRiYwFsv5QI7jw== X-Received: by 2002:a7b:c316:0:b0:3a3:c83:9001 with SMTP id k22-20020a7bc316000000b003a30c839001mr9737152wmj.105.1658430815639; Thu, 21 Jul 2022 12:13:35 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h13-20020a05600016cd00b0021e4e9f6450sm2630637wrf.84.2022.07.21.12.13.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 12:13: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 v3 02/26] submodule--helper: stop conflating "sb" in clone_submodule() Date: Thu, 21 Jul 2022 21:12:58 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1095.g0bd6f54ba8a In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Refactor the three uses of a "struct strbuf sb" such that each of them exists in its own scope. This makes the control flow clearer. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 73717be957c..29641690c8c 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1638,18 +1638,28 @@ static void prepare_possible_alternates(const char *sm_name, free(error_strategy); } -static int clone_submodule(struct module_clone_data *clone_data) +static char *clone_submodule_sm_gitdir(const char *name) { - char *p, *sm_gitdir; - char *sm_alternate = NULL, *error_strategy = NULL; struct strbuf sb = STRBUF_INIT; - struct child_process cp = CHILD_PROCESS_INIT; + char *sm_gitdir; - submodule_name_to_gitdir(&sb, the_repository, clone_data->name); + submodule_name_to_gitdir(&sb, the_repository, name); sm_gitdir = absolute_pathdup(sb.buf); - strbuf_reset(&sb); + strbuf_release(&sb); + + return sm_gitdir; +} + +static int clone_submodule(struct module_clone_data *clone_data) +{ + char *p; + char *sm_gitdir = clone_submodule_sm_gitdir(clone_data->name); + char *sm_alternate = NULL, *error_strategy = NULL; + struct child_process cp = CHILD_PROCESS_INIT; if (!is_absolute_path(clone_data->path)) { + struct strbuf sb = STRBUF_INIT; + strbuf_addf(&sb, "%s/%s", get_git_work_tree(), clone_data->path); clone_data->path = strbuf_detach(&sb, NULL); } else { @@ -1705,6 +1715,8 @@ static int clone_submodule(struct module_clone_data *clone_data) die(_("clone of '%s' into submodule path '%s' failed"), clone_data->url, clone_data->path); } else { + struct strbuf sb = STRBUF_INIT; + if (clone_data->require_init && !access(clone_data->path, X_OK) && !is_empty_dir(clone_data->path)) die(_("directory not empty: '%s'"), clone_data->path); @@ -1712,7 +1724,7 @@ static int clone_submodule(struct module_clone_data *clone_data) die(_("could not create directory '%s'"), clone_data->path); strbuf_addf(&sb, "%s/index", sm_gitdir); unlink_or_warn(sb.buf); - strbuf_reset(&sb); + strbuf_release(&sb); } connect_work_tree_and_git_dir(clone_data->path, sm_gitdir, 0); @@ -1734,7 +1746,6 @@ static int clone_submodule(struct module_clone_data *clone_data) free(sm_alternate); free(error_strategy); - strbuf_release(&sb); free(sm_gitdir); free(p); return 0; From patchwork Thu Jul 21 19:12:59 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: 12925698 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 BC44CCCA485 for ; Thu, 21 Jul 2022 19:13:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233455AbiGUTNq (ORCPT ); Thu, 21 Jul 2022 15:13:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230043AbiGUTNl (ORCPT ); Thu, 21 Jul 2022 15:13:41 -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 D156F8965A for ; Thu, 21 Jul 2022 12:13:39 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id n12so3605285wrc.8 for ; Thu, 21 Jul 2022 12:13:39 -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=iQ/2ULJGiXlS45ldDELsoLt/a8mNNcGpe8+e1Vposms=; b=cz5Vkb83qicgkcKiWCmnHrkKlXsgw3n/T0FJJ0tTBCMZFhzIIAaLa1/WVMBPAKInxx 0i+JcsgTpu3vqPOF3C6ZO1ZJ37ho0huuilD8cxNf087DSo0PpvzWfEoz0lNPQaZ9joDH 0dR6D7LtTUyTXW/TUeJ93bRWiQQvWhCnDEIOL7HKtMVFQ8WZwCIM084VINrDNOV4Q8Di ArYequqwm/Wj/cDCy3Z2IJVxx3GC2MoPwdWUfouZo32CTmKrs2/mv3AbeqnshamWlXeq XDOQHTe9UQWzwLoWAGrgLMbrpCjQ1ke2S56Sl6nHsrqPEe36rfNnGYFaw2xUT2I1MhmI HAPQ== 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=iQ/2ULJGiXlS45ldDELsoLt/a8mNNcGpe8+e1Vposms=; b=6eVi0rhuVxTtHWEZ3/oLzBLxXfC0RXjXv1LqSuUdYI2rGsRonn0e3W75UKuRzdVx9O EMN1gFD2tgXkrMoYeFvbmkKsbi6Aye3mPmZUcZkIS5kl2rEDNa15R5aSMWUFsD/siHju DaHbXauhs878ZQDqEJuTclCvbqOqchGqhLHOMlCQNo9k3IfTp45V6coQWVpAf/Gk3ee5 aXukH+HA2lhBPOyL0BLxzRtAN4EitlDLZQCvhQCKmJmNelI7rUtM+txDd/mGHIGmwvgf 2BU/S1udSz8o5MH+xRySobUCGHxFjLR0YhNA74j7hRKEv2b6THh80O7y8uMh8TQjAfd6 4Vmw== X-Gm-Message-State: AJIora9IWxwJ9Ix1DkeyiW+FnbeFzPPYPxHwU3DOoBro2vY3yxjVuCW5 Bfo6FgjwrOYdtOeZT6ll50XltI7nXQ4+ww== X-Google-Smtp-Source: AGRyM1tRhf1QNBmm51nZYE0vkuaradTfts5NTVW4edDmagE7R/516e02WGLEG56neRqEArpVCxWfag== X-Received: by 2002:a5d:598e:0:b0:21d:86b2:f35 with SMTP id n14-20020a5d598e000000b0021d86b20f35mr37277503wri.54.1658430817735; Thu, 21 Jul 2022 12:13:37 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h13-20020a05600016cd00b0021e4e9f6450sm2630637wrf.84.2022.07.21.12.13.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 12:13:37 -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 v3 03/26] submodule--helper: pass a "const struct module_clone_data" to clone_submodule() Date: Thu, 21 Jul 2022 21:12:59 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1095.g0bd6f54ba8a In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add "const" to the "struct module_clone_data" that we pass to clone_submodule(), which makes the ownership clear, and stops us from clobbering the "clone_data->path". We still need to add to the "reference" member, which is a "struct string_list". We could do this by having clone_submodule() create its own, and copy the contents over, but let's instead pass it as a separate parameter. The main point of doing this is to make it clear that e.g. "clone_data->path" always comes from the "argv", there's no ambiguity about whether we can eventually free() the "struct string_list". Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 38 +++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 29641690c8c..7d5ee6a6261 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1650,20 +1650,22 @@ static char *clone_submodule_sm_gitdir(const char *name) return sm_gitdir; } -static int clone_submodule(struct module_clone_data *clone_data) +static int clone_submodule(const struct module_clone_data *clone_data, + struct string_list *reference) { char *p; char *sm_gitdir = clone_submodule_sm_gitdir(clone_data->name); char *sm_alternate = NULL, *error_strategy = NULL; struct child_process cp = CHILD_PROCESS_INIT; + const char *clone_data_path; if (!is_absolute_path(clone_data->path)) { struct strbuf sb = STRBUF_INIT; strbuf_addf(&sb, "%s/%s", get_git_work_tree(), clone_data->path); - clone_data->path = strbuf_detach(&sb, NULL); + clone_data_path = strbuf_detach(&sb, NULL); } else { - clone_data->path = xstrdup(clone_data->path); + clone_data_path = xstrdup(clone_data_path); } if (validate_submodule_git_dir(sm_gitdir, clone_data->name) < 0) @@ -1674,7 +1676,7 @@ static int clone_submodule(struct module_clone_data *clone_data) if (safe_create_leading_directories_const(sm_gitdir) < 0) die(_("could not create directory '%s'"), sm_gitdir); - prepare_possible_alternates(clone_data->name, &clone_data->reference); + prepare_possible_alternates(clone_data->name, reference); strvec_push(&cp.args, "clone"); strvec_push(&cp.args, "--no-checkout"); @@ -1684,9 +1686,9 @@ static int clone_submodule(struct module_clone_data *clone_data) strvec_push(&cp.args, "--progress"); if (clone_data->depth && *(clone_data->depth)) strvec_pushl(&cp.args, "--depth", clone_data->depth, NULL); - if (clone_data->reference.nr) { + if (reference->nr) { struct string_list_item *item; - for_each_string_list_item(item, &clone_data->reference) + for_each_string_list_item(item, reference) strvec_pushl(&cp.args, "--reference", item->string, NULL); } @@ -1705,7 +1707,7 @@ static int clone_submodule(struct module_clone_data *clone_data) strvec_push(&cp.args, "--"); strvec_push(&cp.args, clone_data->url); - strvec_push(&cp.args, clone_data->path); + strvec_push(&cp.args, clone_data_path); cp.git_cmd = 1; prepare_submodule_repo_env(&cp.env); @@ -1713,25 +1715,25 @@ static int clone_submodule(struct module_clone_data *clone_data) if(run_command(&cp)) die(_("clone of '%s' into submodule path '%s' failed"), - clone_data->url, clone_data->path); + clone_data->url, clone_data_path); } else { struct strbuf sb = STRBUF_INIT; - if (clone_data->require_init && !access(clone_data->path, X_OK) && - !is_empty_dir(clone_data->path)) - die(_("directory not empty: '%s'"), clone_data->path); - if (safe_create_leading_directories_const(clone_data->path) < 0) - die(_("could not create directory '%s'"), clone_data->path); + if (clone_data->require_init && !access(clone_data_path, X_OK) && + !is_empty_dir(clone_data_path)) + die(_("directory not empty: '%s'"), clone_data_path); + if (safe_create_leading_directories_const(clone_data_path) < 0) + die(_("could not create directory '%s'"), clone_data_path); strbuf_addf(&sb, "%s/index", sm_gitdir); unlink_or_warn(sb.buf); strbuf_release(&sb); } - connect_work_tree_and_git_dir(clone_data->path, sm_gitdir, 0); + connect_work_tree_and_git_dir(clone_data_path, sm_gitdir, 0); - p = git_pathdup_submodule(clone_data->path, "config"); + p = git_pathdup_submodule(clone_data_path, "config"); if (!p) - die(_("could not get submodule directory for '%s'"), clone_data->path); + die(_("could not get submodule directory for '%s'"), clone_data_path); /* setup alternateLocation and alternateErrorStrategy in the cloned submodule if needed */ git_config_get_string("submodule.alternateLocation", &sm_alternate); @@ -1810,7 +1812,7 @@ static int module_clone(int argc, const char **argv, const char *prefix) usage_with_options(git_submodule_helper_usage, module_clone_options); - clone_submodule(&clone_data); + clone_submodule(&clone_data, &clone_data.reference); list_objects_filter_release(&filter_options); return 0; } @@ -3088,7 +3090,7 @@ 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)) + if (clone_submodule(&clone_data, &clone_data.reference)) return -1; prepare_submodule_repo_env(&cp.env); From patchwork Thu Jul 21 19:13:00 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: 12925699 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 1DB5BC433EF for ; Thu, 21 Jul 2022 19:13:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229658AbiGUTNs (ORCPT ); Thu, 21 Jul 2022 15:13:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233176AbiGUTNn (ORCPT ); Thu, 21 Jul 2022 15:13:43 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EFB18AB21 for ; Thu, 21 Jul 2022 12:13:41 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id bv24so3614007wrb.3 for ; Thu, 21 Jul 2022 12:13:41 -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=d7Wv8cbvbu5WQTD8J8Zt33E2UZj6Ng7pf5hJ4tlPb6Q=; b=A8+vfHq60saYYxV0i8b/gAi4z8HWGLce1/Xe9uSxi4zSFUAQyUx4dDjYzRmyeLLu6X ppGUUgaZ1x/+Gb7bTQX3HWydb2c4dSI5eri6Hpa+zfQENFA+OXnp21TZE445cy9ugzPD CEUrhdhzabw/XImdZHkfTNP86uUzsXKpwQ2/7Fng0W2c3Ymmrke+YBDpNUwwB/k9BQXW HxfQnTQ83cTFmdU1S36uyXoVwU1UajrK4/ByhT4kblm+yjGEU70oBkBnG3yD/fou8enL Na8zMT58VIuJ3WuFGpMCArBc6Xk7yQyM46oEkr1fcYKbfVEB6GgC0OLoS6VnlWgi05t9 PCKQ== 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=d7Wv8cbvbu5WQTD8J8Zt33E2UZj6Ng7pf5hJ4tlPb6Q=; b=6MxIhiZAyCDom/Y+07xxfgjT45Zauxj8pVValbFFkle5QmkJR9hwUuVnWGA5d0+H/O 49T9ULucjmzxJ/GEltCITArxz2G2gZDvAKboE2Zh7gNeO9hOmCB21VAFgme6NIzvxEta ibP/6xVCAgQjcxdodxUN53RlfrrpEI0NnAypCxSpWF4wWSFBeJue4sHhxhQZO24OWqA+ Gsog2k4b/tiLynk8Z6w1200fF8jTX78aeXo4dFDM7Q7UNWaZGVqrY7UdJhzo0n0VN+9p Uu9J/ta3Wp37QXMoJDgWj5hV16cSCx24aj8ZBJ59McxHlVTeSt5alrgpt6J7fUWo+JOG GzPA== X-Gm-Message-State: AJIora/nDrrmE2eG04mD0ElSfyMyf8LA0xc7YChuaUk6KboZUiEepYqO Se+xD7aqw2d00Nr57KkA3/4fkUFZyJDA2A== X-Google-Smtp-Source: AGRyM1usMCGDLiqGse96swOvoA5Nt9en9mtsOoVuRHPxqvM/YcX2b8ssiMDcz1XITCpF4pwa9QjZrQ== X-Received: by 2002:a5d:64ce:0:b0:21e:5064:a529 with SMTP id f14-20020a5d64ce000000b0021e5064a529mr5447906wri.213.1658430819364; Thu, 21 Jul 2022 12:13:39 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h13-20020a05600016cd00b0021e4e9f6450sm2630637wrf.84.2022.07.21.12.13.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 12:13:38 -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 v3 04/26] submodule--helper: fix a leak in "clone_submodule" Date: Thu, 21 Jul 2022 21:13:00 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1095.g0bd6f54ba8a In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a memory leak of the "clone_data_path" variable that we copy or derive from the "struct module_clone_data" in clone_submodule(). This code was refactored in preceding commits, but the leak has been with us since f8eaa0ba98b (submodule--helper, module_clone: always operate on absolute paths, 2016-03-31). For the "else" case we don't need to xstrdup() the "clone_data->path", and we don't need to free our own "clone_data_path". In the case of the module_clone() caller it's from "argv", and doesn't need to be free'd, and in the case of the add_submodule() caller we get a pointer to "sm_path", which doesn't need to be directly free'd either. 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 | 6 ++++-- t/t1500-rev-parse.sh | 1 + 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 ++ 6 files changed, 11 insertions(+), 2 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 7d5ee6a6261..1ddce8e19c1 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1658,14 +1658,15 @@ static int clone_submodule(const struct module_clone_data *clone_data, char *sm_alternate = NULL, *error_strategy = NULL; struct child_process cp = CHILD_PROCESS_INIT; const char *clone_data_path; + char *to_free = NULL; if (!is_absolute_path(clone_data->path)) { struct strbuf sb = STRBUF_INIT; strbuf_addf(&sb, "%s/%s", get_git_work_tree(), clone_data->path); - clone_data_path = strbuf_detach(&sb, NULL); + clone_data_path = to_free = strbuf_detach(&sb, NULL); } else { - clone_data_path = xstrdup(clone_data_path); + clone_data_path = clone_data->path; } if (validate_submodule_git_dir(sm_gitdir, clone_data->name) < 0) @@ -1750,6 +1751,7 @@ static int clone_submodule(const struct module_clone_data *clone_data, free(sm_gitdir); free(p); + free(to_free); return 0; } diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh index 1c2df08333b..0e13bcb4ebb 100755 --- a/t/t1500-rev-parse.sh +++ b/t/t1500-rev-parse.sh @@ -4,6 +4,7 @@ test_description='test git rev-parse' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_one () { 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 Thu Jul 21 19:13:01 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: 12925700 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 781E3C433EF for ; Thu, 21 Jul 2022 19:13:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233489AbiGUTNu (ORCPT ); Thu, 21 Jul 2022 15:13:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233462AbiGUTNo (ORCPT ); Thu, 21 Jul 2022 15:13:44 -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 77BF08AECE for ; Thu, 21 Jul 2022 12:13:43 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id z13so3589163wro.13 for ; Thu, 21 Jul 2022 12:13:43 -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=mnddJpSdd54BXlv0z6me5PLcjFXPrLFeaf9eDVC6A/E=; b=c1kiG4Hg/sApfohKPaB7ZEanzaz6qSEHI1nZnR4+4sLLpYUo7lcQPFaQORe7UZHHRo a95qFs75yCZ7Sba4r7HPpE5y/5o1MnNnHrq9bhLvbaKpqai9xrC4LwjaKn+tN394O+1U 6JTly7reDJH6q0GlSFP65X+UzsS33Bvl5dUGPxtuGd4NdabSvuns6v03VZE1zxdSdP0I syJf5mAxzLSrVVSqGyjh7PI628DNBwjBzn6njAJ90QEK/tgBvznbo52asJj60thwVvea TjRHbCSgB2Ff19E/2NC4r4BeuVer8wY8PaoAkZ9LShoCxZg1HJovAW9hkB9W0iN3meFX qDnQ== 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=mnddJpSdd54BXlv0z6me5PLcjFXPrLFeaf9eDVC6A/E=; b=fF5JRn1JgbcmWa9t9OKonxsMocU35mfujfNMtNyM7n173yyji3uIKopKSfMqM7l/b2 piSOHFSE/IeO9vnZQe/w7NEGQl836rcpszb5LurohAgO2q+6yenqfPnBwAouKzKyzl+L ZYqyJZ0KGReAZqGDvzKGiX8TazDtU6cB3DADc7fm5lEQ0Fzl2axmS19CZ4yegc5IbgKd aR1WNq16uu6ACWwGltbkDpBkpvU72pxrRQvYzxFF3B0594gT60sJow22N1W267HzkzI1 KJuxusBZXbkNC8OXJC2/jylKQGewVLBMF9rhSBWG1ScsaJA8otWosa3neG5WOePC8Jq3 PXZw== X-Gm-Message-State: AJIora+U6yx8vG5AXGUusYMjpgecpBZWPL+1Nh+5EglZjt+Iyh5Y2lWw CAjE9LYGmqq1k88Za6Vz+0nJt8OPYKRRlg== X-Google-Smtp-Source: AGRyM1uDygTcVLYb/NgZouSkfkG30CXimqHdtZ7+RsvGdDt4UnssTLAz0E3/weC9JaDUhQCgfmYLTA== X-Received: by 2002:a05:6000:1888:b0:21d:beeb:785c with SMTP id a8-20020a056000188800b0021dbeeb785cmr34177606wri.34.1658430821577; Thu, 21 Jul 2022 12:13:41 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h13-20020a05600016cd00b0021e4e9f6450sm2630637wrf.84.2022.07.21.12.13.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 12:13:40 -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 v3 05/26] submodule--helper: fix trivial get_default_remote_submodule() leak Date: Thu, 21 Jul 2022 21:13:01 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1095.g0bd6f54ba8a In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a leak in code added in 1012a5cbc3f (submodule--helper run-update-procedure: learn --remote, 2022-03-04), we need to free() the xstrdup()'d string. This gets e.g. t/t7419-submodule-set-branch.sh closer to passing under SANITIZE=leak. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 1ddce8e19c1..73ac1fcbb9c 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2486,6 +2486,8 @@ static int update_submodule(struct update_data *update_data) const char *branch = remote_submodule_branch(update_data->sm_path); char *remote_ref = xstrfmt("refs/remotes/%s/%s", remote_name, branch); + free(remote_name); + if (!update_data->nofetch) { if (fetch_in_submodule(update_data->sm_path, update_data->depth, 0, NULL)) From patchwork Thu Jul 21 19:13:02 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: 12925701 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 A839CC43334 for ; Thu, 21 Jul 2022 19:13:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233462AbiGUTNw (ORCPT ); Thu, 21 Jul 2022 15:13:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233454AbiGUTNq (ORCPT ); Thu, 21 Jul 2022 15:13:46 -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 050FF88765 for ; Thu, 21 Jul 2022 12:13:45 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id b26so3632981wrc.2 for ; Thu, 21 Jul 2022 12:13:44 -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=rNr9aRcaN4JdeKQzr/y6dLghAvimfsPNQXgFwthexRU=; b=N4zpgHx/Hkk6Nq7QdYW/E0ZEGNlkwbxWvuxROnFmwG5/KoJdCYMGkDhsh90TK0fWvE Cc7SapXJfc/iFKmpUeNACzX26wY/w0T9JJYqUKmYidyR9XdzSrPxgSzKn+rBoK4GQbQc K9pwsQAWQlmaDqIr1egMIWoOBzX4bq+yKZMxn5gzMzBfgcfLogSgk7rwzvq73jKttnyA S2O2u7wl03jNsA0tGyc63Vkkf6Ydubpz8t8kVuiaVoCDUhtERr4GVMFXNxhWT2YkYwjS jEh+6ZhtRMFV02GYc2xDTZMUJVzrvGxU6ICQW5J53b9d2ow4bebKGsttCHmjlyEB/Mtk g3cQ== 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=rNr9aRcaN4JdeKQzr/y6dLghAvimfsPNQXgFwthexRU=; b=FVonVnhhLrjE0DkvcU1KznHZL618YC3VuK1aoG0rklVGVzGKfJSDDa4X4pgBxqDXyL 9Wv4jfxMbZ7XSLg9qMYS/IL21Z8hn3a+reVJ3W6grQPrjY5O3gTAKDnajbJmzzj5w6VM 20Dl5o3PgvHAZol5L0hgfYWrEGl/8vBAX1pWtu052I5vpqKEmcljocBVeJkiY0T5PDg5 3VtOJuXJzDHjAMdqhcjXD3cMVdbzvm/I78LWQgU52gY56+pBjug5BCJFp+zS3fki33V2 JLY+NVwN0QT5AEdV/fjx3ru/P2yp8Em9ETu1pZtIioUatT8RW23iN2BkhFkDw6r7w/Ld 9F5A== X-Gm-Message-State: AJIora8hQHefMpvgCgonsCLTRSpw714epzJ7sjT9xumydnP+AhmBfk4O Q035Qh6X55+4dwuKXld8O7sdQCfqUWJdQw== X-Google-Smtp-Source: AGRyM1u2UVoHDCU0d/ZWheAqe+lId1YqmpgvZuriSz5vUe2lFHI/NWGwxSTOyluUvf6lX2J0UvHFyA== X-Received: by 2002:a5d:59a4:0:b0:21d:bdec:8a67 with SMTP id p4-20020a5d59a4000000b0021dbdec8a67mr35260724wrr.194.1658430823174; Thu, 21 Jul 2022 12:13:43 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h13-20020a05600016cd00b0021e4e9f6450sm2630637wrf.84.2022.07.21.12.13.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 12:13:42 -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 v3 06/26] submodule--helper: fix most "struct pathspec" memory leaks Date: Thu, 21 Jul 2022 21:13:02 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1095.g0bd6f54ba8a 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 | 84 +++++++++++++++++++++++++------------ 1 file changed, 58 insertions(+), 26 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 73ac1fcbb9c..a60dc6af178 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 = 1; const char *const git_submodule_helper_usage[] = { N_("git submodule--helper list [--prefix=] [...]"), @@ -288,7 +289,7 @@ static int module_list(int argc, const char **argv, const char *prefix) git_submodule_helper_usage, 0); if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0) - return 1; + goto cleanup; for (i = 0; i < list.nr; i++) { const struct cache_entry *ce = list.entries[i]; @@ -302,7 +303,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 +431,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 +445,13 @@ static int module_foreach(int argc, const char **argv, const char *prefix) N_("git submodule foreach [--quiet] [--recursive] [--] "), NULL }; + int ret = 1; 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; + goto cleanup; info.argc = argc; info.argv = argv; @@ -454,7 +459,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 +570,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 +583,13 @@ static int module_init(int argc, const char **argv, const char *prefix) N_("git submodule init [] []"), NULL }; + int ret = 1; 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; + goto cleanup; /* * If there are no path args and submodule.active is set then, @@ -595,7 +604,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 +752,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 +767,13 @@ static int module_status(int argc, const char **argv, const char *prefix) N_("git submodule status [--quiet] [--cached] [--recursive] [...]"), NULL }; + int ret = 1; 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; + goto cleanup; info.prefix = prefix; if (quiet) @@ -768,7 +781,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) @@ -1326,10 +1342,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 = 1; struct option module_sync_options[] = { OPT__QUIET(&quiet, N_("suppress output of synchronizing submodule url")), @@ -1347,7 +1364,7 @@ static int module_sync(int argc, const char **argv, const char *prefix) git_submodule_helper_usage, 0); if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0) - return 1; + goto cleanup; info.prefix = prefix; if (quiet) @@ -1357,7 +1374,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 +1484,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 +1501,7 @@ static int module_deinit(int argc, const char **argv, const char *prefix) N_("git submodule deinit [--quiet] [-f | --force] [--all | [--] [...]]"), NULL }; + int ret = 1; argc = parse_options(argc, argv, prefix, module_deinit_options, git_submodule_helper_usage, 0); @@ -1495,7 +1516,7 @@ static int module_deinit(int argc, const char **argv, const char *prefix) die(_("Use '--all' if you really want to deinitialize all submodules")); if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0) - return 1; + goto cleanup; info.prefix = prefix; if (quiet) @@ -1505,7 +1526,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 { @@ -2577,7 +2601,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; @@ -2656,8 +2680,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) @@ -2668,8 +2692,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, @@ -2686,7 +2712,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; } @@ -2770,9 +2798,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 = 1; struct option embed_gitdir_options[] = { OPT_STRING(0, "prefix", &prefix, @@ -2792,12 +2821,15 @@ static int absorb_git_dirs(int argc, const char **argv, const char *prefix) git_submodule_helper_usage, 0); if (module_list_compute(argc, argv, prefix, &pathspec, &list) < 0) - return 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 Thu Jul 21 19:13:03 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: 12925702 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 94E9CC43334 for ; Thu, 21 Jul 2022 19:14:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233542AbiGUTOC (ORCPT ); Thu, 21 Jul 2022 15:14:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233481AbiGUTNt (ORCPT ); Thu, 21 Jul 2022 15:13:49 -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 C2A198AECC for ; Thu, 21 Jul 2022 12:13:46 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id b26so3633114wrc.2 for ; Thu, 21 Jul 2022 12:13:46 -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=j+xqvdEZrR975tP4VoKUrffJo7UeeReNihPY1zsJ67A=; b=UNZ5i8+B25+SII8x0UrMOFDbG0fevDRTDpgP8jQgUEDulRLraYJwFu4Yxron1oujcd elzLo5J/SleQiF1o+hF2gQkMlgKmNt4bxgkdxc3/N/6d9GI2DauHUnBNLFuJXjq6W+zB Niot6yeB7wIAMUT/JHwK4Op9zQdS92YWewUDAYYqhNihVTnbsdekNIktQ4CGrJgKTYqV pKOyXHLiLVafR7hSaSe5JVEhw9Mr4zifWTFanFLsRqIxnoJmalMrsThSDaHH1twhjaTp 9GlC6rkSa2uABhGtkwTslGvejESYSU16YCtrICOzuyJSmAL8a91VtiIrDmhBQu4rPkSR UTDQ== 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=j+xqvdEZrR975tP4VoKUrffJo7UeeReNihPY1zsJ67A=; b=ULnicOcApNVTwGuRHtxcZRFZfMfBuRD/f5vo7sBrVSz2b01hXh1zXH1dT7vH5t+U/Z YrPAt4RkFTsr4plFEbJl7XVMhFTq4P64cM0l/FM8bzGTMrZoD0/by/rLAT0Q20VqKeAg w82fXialDdRO0p3EKwxn2wSaEHh3YPwXLh4MA2ncWS8DJXWCCPglojjoNM4UtmplMKrR ADDzBK+dNgDsTGgQwGd25QBZTNPWh5O8SGSnPEa9KtB7V9iAR+eRUajuE1X5pNGN/nex nTB1ahMGtzL9FsmOWL8oJF1MfzxNl8j+hlNMikKfFs+IPX90B8hn4ywSk4Wqhsu1nPcL BCVw== X-Gm-Message-State: AJIora94rIeVdX4IPc9k73zgv/jFcLam7XUbRozNYqA3vtW3BjT5kL5m UEdu7phrS1OohlPhqY3IUueHzuNwm9JWJw== X-Google-Smtp-Source: AGRyM1tM+ckkc4ailJdbX71uvWdt0fzGlfA85a/fZPTPKUIhNXyuTYjvkBAM2xHCzxo1E2TNgVzExw== X-Received: by 2002:a05:6000:180c:b0:21e:47f3:7e51 with SMTP id m12-20020a056000180c00b0021e47f37e51mr8037345wrh.226.1658430824918; Thu, 21 Jul 2022 12:13:44 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h13-20020a05600016cd00b0021e4e9f6450sm2630637wrf.84.2022.07.21.12.13.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 12:13:43 -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 v3 07/26] submodule--helper: "struct pathspec" memory leak in module_update() Date: Thu, 21 Jul 2022 21:13:03 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1095.g0bd6f54ba8a In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The module_update() function calls module_list_compute() twice, which in turn will reset the "struct pathspec" passed to it. Let's instead track two of them, and clear them both. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index a60dc6af178..f317236f016 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2602,6 +2602,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 = { 0 }; + struct pathspec pathspec2 = { 0 }; struct update_data opt = UPDATE_DATA_INIT; struct list_objects_filter_options filter_options = { 0 }; int ret; @@ -2692,7 +2693,7 @@ 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) { + &pathspec2, &list) < 0) { ret = 1; goto cleanup; } @@ -2715,6 +2716,7 @@ static int module_update(int argc, const char **argv, const char *prefix) cleanup: list_objects_filter_release(&filter_options); clear_pathspec(&pathspec); + clear_pathspec(&pathspec2); return ret; } From patchwork Thu Jul 21 19:13:04 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: 12925703 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 0D275CCA485 for ; Thu, 21 Jul 2022 19:14:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233395AbiGUTOF (ORCPT ); Thu, 21 Jul 2022 15:14:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233492AbiGUTNu (ORCPT ); Thu, 21 Jul 2022 15:13:50 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 455128CE8C for ; Thu, 21 Jul 2022 12:13:49 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id bk26so3601079wrb.11 for ; Thu, 21 Jul 2022 12:13:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WFCx+F/awxgEXhNSY8bBlS+abGVNw9yviB0kveRTiN0=; b=dh/jzfkDHJD5/NiQ1BA4MFJLSxZKfnykkx1C5gEEDyQyj2BjEXJzjdfod8b7el7Zqp oPqzVv1RYUVoswx35TjRacBRENjPaR9NpxJxwHm1EKujCZIoyiDzzARw0GAuRV0+jEHP nzC8ZCbYYPMDvWndVVRN4URKWVN2QgOX8C6VVmfp/5dDLym24+emeFH0qMlVLJPOUilG +421r6p+r8s/6HX7NXD5rC8RLgiO3o5vsSMPyLZWOFxW+Ps/zpPn+OJ2B+NAUjfFlWli B4cwQIp/8bhXMjYyzlpIHS0ufYLu75gReqUwG93K6ArvMz7p+QyCC2CQr5xog5ibSzMh 25GQ== 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=WFCx+F/awxgEXhNSY8bBlS+abGVNw9yviB0kveRTiN0=; b=h/b5zMjLSyl+hs2sgMMeW2VDbsejNl8/WB2QphOjs1O9TTjyVDRYJDMx/ajNUYhco0 +AWf6909KjtMrLVel2j/NDT5NY6+OFykBpwsFRVHMUsoxQcfqAwfJJCZpOhp81f3BjqZ dK6hwff/dctGbCHa7bx+DFVCoNutAmKghSgwGYWxVmx35JpAhqs6VCpfUR1Uf7igvkRV SU7m1B+kYMIjXt5K1jUBHoD/SeWhjwv5KR+r9Y0TFULkLthUxK4ZCx1Jcss30Y44MqJX IX3mBnsQxBbVPDXbRzjvNGDaIYmS2CIuEcmNPJBDa+coNVdiwp7ACrfSMuGwgl3lxQuD TuQA== X-Gm-Message-State: AJIora+huvc/dCTxViVSSegbHNO+3368k4fkMIaArb2swePy8t7FObCO +yMertem2EoziVmPfFf+TN9W4BVT/AnDMw== X-Google-Smtp-Source: AGRyM1s+zpUxPPGjMjUVedS3OT9X6LBo+EHXwJX1hEh7G6241cMIeLV33/ufaLhhZN7snvzmG4780Q== X-Received: by 2002:a5d:69ca:0:b0:21d:640c:79f6 with SMTP id s10-20020a5d69ca000000b0021d640c79f6mr35861712wrw.309.1658430827257; Thu, 21 Jul 2022 12:13:47 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h13-20020a05600016cd00b0021e4e9f6450sm2630637wrf.84.2022.07.21.12.13.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 12:13:45 -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 v3 08/26] submodule--helper: don't leak {run,capture}_command() cp.dir argument Date: Thu, 21 Jul 2022 21:13:04 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1095.g0bd6f54ba8a In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a memory leak in c51f8f94e5b (submodule--helper: run update procedures from C, 2021-08-24) and 3c3558f0953 (submodule--helper: run update using child process struct, 2022-03-15) by not allocating memory in the first place. The "dir" member of "struct child_process" will not be modified by that API, and it's declared to be "const char *". So let's not needlessly duplicate these strings. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index f317236f016..fb3102f024f 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2194,7 +2194,7 @@ static int is_tip_reachable(const char *path, struct object_id *oid) char *hex = oid_to_hex(oid); cp.git_cmd = 1; - cp.dir = xstrdup(path); + cp.dir = path; cp.no_stderr = 1; strvec_pushl(&cp.args, "rev-list", "-n", "1", hex, "--not", "--all", NULL); @@ -2212,7 +2212,7 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet, str prepare_submodule_repo_env(&cp.env); cp.git_cmd = 1; - cp.dir = xstrdup(module_path); + cp.dir = module_path; strvec_push(&cp.args, "fetch"); if (quiet) @@ -2267,7 +2267,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 = ud->sm_path; prepare_submodule_repo_env(&cp.env); if (run_command(&cp)) { switch (ud->update_strategy.type) { From patchwork Thu Jul 21 19:13:05 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: 12925704 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 3922CCCA487 for ; Thu, 21 Jul 2022 19:14:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233477AbiGUTOH (ORCPT ); Thu, 21 Jul 2022 15:14:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233454AbiGUTNx (ORCPT ); Thu, 21 Jul 2022 15:13:53 -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 32E538CEB7 for ; Thu, 21 Jul 2022 12:13:51 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id d16so3598277wrv.10 for ; Thu, 21 Jul 2022 12:13:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NG1uYFlSfij5PvvjFbSdYUDXQRes6sRhg7jrwV/nj1c=; b=MH7Dr3JAK4aLKiseY4P5F4eAgbl3f5sQ37QHlBEWc/RR/G++MfwIeQQ3Myd5Id/Z0i oraNkurAUiRl++ojLNE5nOKUhbttuJD0vlRMTSsajBMtu49SIPDJwnkqAx5JaVa5HOMS acoC5JN43ym7+oXpF+Wd7iFJs2uzxYzK2i4CGbVMjKnJ31kX99gT9hI+FEMJZn8ikqMV GaITNuKATPgOg4+lil5bxEWsETrw6XP9Dd3DfQB/rqNfYly5KRhRNd5iQxk7KMQi6RJg DYx/vTZ2IzM4//xflwZ8UED08f+gAm9ncSobAW9/pcd8E2LJywZ2wvpG73cFVwoITube rmbA== 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=NG1uYFlSfij5PvvjFbSdYUDXQRes6sRhg7jrwV/nj1c=; b=qKjd/gLTmVdlG+WhYxDB81HKjplr1XUSeVeF6tMBbrPLbAPUJ2PEGPaK16CGis1+50 FYSOoi/CYfvkSUbSg1cJRPPhzPk1QOsZHZmuB2QUNEhE8VAoF413IjEZd9ZxztN3WfFc RcYV7lt/OqElriuIZ8bcK/4M+K7lkXL/wzL15tHJNZoc94oKzMQUw1Xca1lvuDrPoxsA euDvhFH5s3pVR0pUCWCeu0Zm0BhBsVVcbiqLs/ka4NgX1DNwF7Q2v9wcPXetSc6yo5u/ 1pgZAt5cMAJgb7UQCcc4IMHHfCuxh7zBlfrVOQooQ31xb7b3AKqiwFwbcUApxaj1FXTW xv0A== X-Gm-Message-State: AJIora9jOaNhhYvRNJdTrOpVEW61FCC1M/WTBkJpfCQH9LuvCELfxGFO 4LCazmxKvkQu5arZDL94BMNIgDml17jcxQ== X-Google-Smtp-Source: AGRyM1vefyTvFjM98PQpY9ZgiLUloQGaIYsWMXLaLt3TuAFU7cUTiUS+aEKcfLYWmum14FDMQPMyqw== X-Received: by 2002:a05:6000:184f:b0:21d:a1fb:4581 with SMTP id c15-20020a056000184f00b0021da1fb4581mr36669805wri.651.1658430829111; Thu, 21 Jul 2022 12:13:49 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h13-20020a05600016cd00b0021e4e9f6450sm2630637wrf.84.2022.07.21.12.13.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 12:13:48 -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 v3 09/26] submodule--helper: add "const" to copy of "update_data" Date: Thu, 21 Jul 2022 21:13:05 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1095.g0bd6f54ba8a In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Glen Choo Add a "const" to the copy of "struct update_data" that's tracked by the "struct submodule_update_clone", as it neither owns nor modifies it. Signed-off-by: Glen Choo Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index fb3102f024f..3223c93f91a 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1889,7 +1889,7 @@ struct submodule_update_clone { int current; /* configuration parameters which are passed on to the children */ - struct update_data *update_data; + const struct update_data *update_data; /* to be consumed by update_submodule() */ struct update_clone_data *update_clone; @@ -1974,7 +1974,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce, const char *update_string; enum submodule_update_type update_type; char *key; - struct update_data *ud = suc->update_data; + const struct update_data *ud = suc->update_data; char *displaypath = get_submodule_displaypath(ce->name, ud->prefix); struct strbuf sb = STRBUF_INIT; int needs_cloning = 0; From patchwork Thu Jul 21 19:13: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: 12925705 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 14D47C43334 for ; Thu, 21 Jul 2022 19:14:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233499AbiGUTOM (ORCPT ); Thu, 21 Jul 2022 15:14:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233564AbiGUTOD (ORCPT ); Thu, 21 Jul 2022 15:14:03 -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 18AE18D5DE for ; Thu, 21 Jul 2022 12:13:53 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id ay11-20020a05600c1e0b00b003a3013da120so3900006wmb.5 for ; Thu, 21 Jul 2022 12:13:53 -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=7QSFgwic6tV5PG89CARSp/V82j71/gfwiS5SsCs21nA=; b=keViqC6UdrGhI5pC0FwsYc4s1x7X74ZErlwwLnw5+USR2NweyvNlZDAzxh/aH9hlRs kjRvco1Xm5EG+IIUd7HXyy09psrr8Ryi7oPD+boRLI1xXqbuF1zWNeqYvidbgLP+vM1i 7xRth2KdfGCAguTa8kzeQNY/IcI403qlW+6PBQMSXbc43cvsPYiH6mIMGvK5WtSAgjcS VwbV5+ST6vuAbQtxWriQSX6oSHlOk1/tgDAAokMIPRiK5wa27h2BJQwpS0ncFz2Ld9VT swsJpWIsJu8L+QQQssCRBlqt/Tt3YaW07gTnRUZoPqgeqm+NnERTg/lNkV/UXowzezbG Kfgw== 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=7QSFgwic6tV5PG89CARSp/V82j71/gfwiS5SsCs21nA=; b=CQH2g2tDXjqiOHSKhH0y9VfX4SQSsoF6erk7CRuZ6gLIgyXz6hkKz64LvGF1DR1K4F vBPkPi90jqr+/KeynO8tqf4xYxJ5VOdpwENQHic3BkEQUp0W2dd8NRdSfGRW4ECCKKox XLhpyInSUsDAjUdLzWWMGEk/q9f1Yucu6IV0AX2brfplN3eLn5z2UOR8cxmD+AcKNtk+ MS/SOIcoTyU2RN9aLuVYSwZXS50w9DuizVX1kDD0rbajzpXvbODq/Gvf/pRzHm7vVlZj 7uLV8oqQStehvMWn3zitalgtakKwnUd5EMpHqKc5kxN+FWvmBc21d70qfS8yumrXQNVW 8d9w== X-Gm-Message-State: AJIora82JPyeSAsGCVE0ivDboZD2/YEhODgCumfK2tNsR8ZICmgnq8YL zi1NLGLD/4hhGFmbwJfez82okZHhsbgAag== X-Google-Smtp-Source: AGRyM1udmMKqP6aHDbXo61vta1yODQJ0opRDQb6kiHHJ1/J3kVWwr2EspaJh5bRs+BEMoQ60797FZw== X-Received: by 2002:a1c:7209:0:b0:3a3:1f31:ef3a with SMTP id n9-20020a1c7209000000b003a31f31ef3amr9407184wmc.87.1658430831861; Thu, 21 Jul 2022 12:13:51 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h13-20020a05600016cd00b0021e4e9f6450sm2630637wrf.84.2022.07.21.12.13.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 12:13:50 -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 v3 10/26] submodule--helper: add and use *_release() functions Date: Thu, 21 Jul 2022 21:13:06 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1095.g0bd6f54ba8a 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". Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 29 ++++++++++++++++++++++++++++- t/t6134-pathspec-in-submodule.sh | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 3223c93f91a..21b3abb7b40 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; } @@ -305,6 +310,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; } @@ -461,6 +467,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; } @@ -606,6 +613,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; } @@ -783,6 +791,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; } @@ -1376,6 +1385,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; } @@ -1528,6 +1538,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; } @@ -1904,6 +1915,12 @@ struct submodule_update_clone { }; #define SUBMODULE_UPDATE_CLONE_INIT { 0 } +static void submodule_update_clone_release(struct submodule_update_clone *suc) +{ + free(suc->update_clone); + free(suc->failed_clones); +} + struct update_data { const char *prefix; const char *displaypath; @@ -1942,6 +1959,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) { @@ -2595,6 +2617,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; } @@ -2694,6 +2717,7 @@ static int module_update(int argc, const char **argv, const char *prefix) if (module_list_compute(argc, argv, opt.prefix, &pathspec2, &list) < 0) { + module_list_release(&list); ret = 1; goto cleanup; } @@ -2710,10 +2734,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); clear_pathspec(&pathspec2); @@ -2831,6 +2857,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 Thu Jul 21 19:13: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: 12925706 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 78346C43334 for ; Thu, 21 Jul 2022 19:14:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233582AbiGUTOT (ORCPT ); Thu, 21 Jul 2022 15:14:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233585AbiGUTOD (ORCPT ); Thu, 21 Jul 2022 15:14:03 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A91728D5F2 for ; Thu, 21 Jul 2022 12:13:56 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id bu1so3603147wrb.9 for ; Thu, 21 Jul 2022 12:13:56 -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=WkN7AXbY6pW5NTyz6u4UEUk39JBJrh4jAt8oUngcabA=; b=kmFVIC/X5Hf/Rioiw+3dJDwQCrjVoaMgXHIpsH9nDoTHOFyavRhoFC+v992ftcWDCx KUgefEK0s2NLqYu6QiAkpPgeFTNhvMnFoFzeA+uMIkFz8bsgphpgH9RsFbnXoVIvA6s+ RI/2QPGgHadaZAbH05ErzehWYWTayJJOA2p6yZwreADD6Lkccdrko1gFewG1eeXO6ial RQzpInVFTYKLjKosQlu0pQQEDAqALcS+bqEyjU5Z/p51jthqTlaUIQtH5f5KrmIOcl+i exRCR3TXKgxRUF9Bn0RoZ1tdNVbvugMSvhkpzn+h8CTLEShJbkTv1PVTp8iyOb50BQ74 HaAQ== 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=WkN7AXbY6pW5NTyz6u4UEUk39JBJrh4jAt8oUngcabA=; b=DmPPfDA2q9I9xe/KqI0RY33YQaILDF1q3Dc1rMUzWdmQHiM778ujCOiDEirs9lZYHM LFkfBCViAwfT7/pzppYXl/d/kdIYbt9K1solblJXb74PGvmX6ss8sPaIyORwgCSu4LUJ rRujCdFnM63BOqkpM14UAexETsL0dEFm5068KFo90ah1bX++e8+8XCh0INhTAXpgYoOt sYtr28PKdh/+5T/o6wFi7XXe9FuNx4tFPcHsboHSgwCks5YzR0F3UD9WTdJemDL+0Kmp LYC6EXPrSwaib2uCfrGncNaxq9plOAc7EpunonOEyouvXYMi4zEc0hRXQLsdf+2pKx6k vvYg== X-Gm-Message-State: AJIora/76mTAV7Zu3lZxQ+GKzGss7oKYRjz3npEqJ4sJa0QoHODJUXT3 PvH0EMQQZEUMtIDeGUZ2Mx/7ZO8QpTawRA== X-Google-Smtp-Source: AGRyM1vAvTWAQ8sZWvp/VXhFGWnbY4W6KHQD9eJHUKlRG8sS0SrZ3H5r4dWFZG+RBPa1JSaxKA1dqw== X-Received: by 2002:adf:e708:0:b0:21e:59c8:d2ea with SMTP id c8-20020adfe708000000b0021e59c8d2eamr2406462wrm.499.1658430834735; Thu, 21 Jul 2022 12:13:54 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h13-20020a05600016cd00b0021e4e9f6450sm2630637wrf.84.2022.07.21.12.13.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 12:13:52 -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 v3 11/26] submodule--helper: refactor "errmsg_str" to be a "struct strbuf" Date: Thu, 21 Jul 2022 21:13:07 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1095.g0bd6f54ba8a In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Glen Choo Refactor code added in e83e3333b57 (submodule: port submodule subcommand 'summary' from shell to C, 2020-08-13) so that "errmsg" and "errmsg_str" are folded into one. The distinction between the empty string and NULL is something that's tested for by e.g. "t/t7401-submodule-summary.sh". This is in preparation for fixing a memory leak the "struct strbuf" in the pre-image. Let's also pass a "const char *" to print_submodule_summary(), as it should not be modifying the "errmsg". Signed-off-by: Glen Choo Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 21b3abb7b40..f794d2b588b 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -866,7 +866,7 @@ static char *verify_submodule_committish(const char *sm_path, return strbuf_detach(&result, NULL); } -static void print_submodule_summary(struct summary_cb *info, char *errmsg, +static void print_submodule_summary(struct summary_cb *info, const char *errmsg, int total_commits, const char *displaypath, const char *src_abbrev, const char *dst_abbrev, struct module_cb *p) @@ -924,7 +924,7 @@ 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; + struct strbuf errmsg = STRBUF_INIT; int total_commits = -1; if (!info->cached && oideq(&p->oid_dst, null_oid())) { @@ -1024,23 +1024,21 @@ 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", + strbuf_addf(&errmsg, " Warn: %s doesn't contain commits %s and %s\n", displaypath, oid_to_hex(&p->oid_src), oid_to_hex(&p->oid_dst)); } else { - strbuf_addf(&errmsg_str, " Warn: %s doesn't contain commit %s\n", + strbuf_addf(&errmsg, " Warn: %s doesn't contain commit %s\n", displaypath, missing_src ? oid_to_hex(&p->oid_src) : oid_to_hex(&p->oid_dst)); } - errmsg = strbuf_detach(&errmsg_str, NULL); } } - print_submodule_summary(info, errmsg, total_commits, - displaypath, src_abbrev, + print_submodule_summary(info, errmsg.len ? errmsg.buf : NULL, + total_commits, displaypath, src_abbrev, dst_abbrev, p); free(displaypath); From patchwork Thu Jul 21 19:13: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: 12925707 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 D3E17C433EF for ; Thu, 21 Jul 2022 19:14:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233609AbiGUTOV (ORCPT ); Thu, 21 Jul 2022 15:14:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233608AbiGUTOE (ORCPT ); Thu, 21 Jul 2022 15:14:04 -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 344968D5FB for ; Thu, 21 Jul 2022 12:13:58 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id d8so3606659wrp.6 for ; Thu, 21 Jul 2022 12:13:58 -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=zE1HgMGbiQDnfhMoAXXCiKpHt1WDVAQ/nr4jIU8Mpgg=; b=IB3nF3rXEQtfQ55A+eyb1MuyJ0XrkEtzrtc/Ri7exyauntlv/9DsYv1SzPzc5+Abse LpkuRoSj5NFS3mlm1lz6lqq1/9wrLqU+ZRdQ+3agmDbIy0NrmDSglZWVkg923Evxrp2d IbuMbxjuEVT6xviCsSaaWco60Uc8QG5M+WOxRKrD8YxZnQgLF1m41HfIqYVIAmtiRLjN MEfCANNSHpsUF+YEaEc9KOXl8Kp4KjSHJZjRG5eS+vexmFzWtpGy36Gw/B4DkWL7kPFf HIabeevXGRfd3708SvWaXAUp7zE3leSF8FBsJ5El2fZi5pxgV21XfCxapNoK+AljqjYB IXoQ== 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=zE1HgMGbiQDnfhMoAXXCiKpHt1WDVAQ/nr4jIU8Mpgg=; b=EyLFjWHiLNmRYrpmXbbGu61hdrHZxb9QJJHhAlSdZxcUCBn/Uixwhkb5r1JV57MIjy X8XhbxiW4NvGCdbiSwTiWdztXTWvyPfp+oUOE0CPlBS+7AVkV8fhnCUDXvjID0AOoNwY +rhkZ3lHPBIBR8FgpevztV6p7nMqJKyjJ9LijiFT1UPxuTO2Y+YmPo30sNVsjGC3cy98 Flyq4zA+W70Gu3tg5lxeRoXehHN+nhFQw+kcPbQPSWZsO98O6Ck23or7nsVNdb0Pp5mi fQpgz3o9RmTW26+YV9bPLeYo65VD/E0MolJOJa/Y5d/56A+lLHcV8ThqycxlScm+Lou1 eqhQ== X-Gm-Message-State: AJIora8oyDxd4CSuKQ8tMkf4NQzPMsLFvP4PQ075b7N6lLxF8RTA58/x 0BvFR4VOgrcfC6pO8SXf7Qfn4eUvxlFWVQ== X-Google-Smtp-Source: AGRyM1ujlN6OOlYwfmDdn6uADiYmadoA0t/df11zVQojblLbwjE1S3i0dmzVS0MY2q/r/r3b8QLYxw== X-Received: by 2002:a5d:6d0a:0:b0:21d:6f28:5ead with SMTP id e10-20020a5d6d0a000000b0021d6f285eadmr34951196wrq.95.1658430836456; Thu, 21 Jul 2022 12:13:56 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h13-20020a05600016cd00b0021e4e9f6450sm2630637wrf.84.2022.07.21.12.13.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 12:13:55 -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 v3 12/26] submodule--helper: fix "errmsg_str" memory leak Date: Thu, 21 Jul 2022 21:13:08 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1095.g0bd6f54ba8a 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), we sometimes append to the "errmsg", and need to free the "struct strbuf". Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 1 + 1 file changed, 1 insertion(+) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index f794d2b588b..ad11ff20022 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1044,6 +1044,7 @@ static void generate_submodule_summary(struct summary_cb *info, free(displaypath); free(src_abbrev); free(dst_abbrev); + strbuf_release(&errmsg); } static void prepare_submodule_summary(struct summary_cb *info, From patchwork Thu Jul 21 19:13: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: 12925708 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 D8E06C43334 for ; Thu, 21 Jul 2022 19:14:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233637AbiGUTO3 (ORCPT ); Thu, 21 Jul 2022 15:14:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233629AbiGUTOE (ORCPT ); Thu, 21 Jul 2022 15:14:04 -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 055CB8E1C0 for ; Thu, 21 Jul 2022 12:13:59 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id m17so3327471wrw.7 for ; Thu, 21 Jul 2022 12:13:58 -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=uNx4urEnxYRsUVVoSPu1gr9ek4cEFoLS1upNocJRgwo=; b=JX2a0yM6hHqpZabc+QFfKr3d0myopuCqKT5mxIhz+UljpT+JaP/dTjXYvTYHmvdCwC OUq9D7yYfNFypOLp5ez6XMoU+qop6mM4b+uy9HOK8bl6lc+HKe3IiKvzlNQ0xQ21r88H qw/np2iIAQTR/ys4xq10KYcqqvK9O/6uj/GbY0QG30PxmoYVSkgpGYnRFlJfm206xS9W DxjPbSNOJc53fb7mMLM4YCPnN8PHCfUu7XwB8SUGYOkLw+1Bdc9/w76Qb5lAV1MH22qv q17sve2NvxTMsSPWqqbCRyj1X5+m11+gOj4UOfwR9QHJ2ncJdOgT9oB+5rxdqnRI1AHg EJTQ== 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=uNx4urEnxYRsUVVoSPu1gr9ek4cEFoLS1upNocJRgwo=; b=bnucsQELMfVZVXpzVyWhh1/u54bXw38HJLUu0c7gsDNnkvbFJNZ9dfEGdUA6YhPBeP Vqn6URpwUARoDJqIBf4bKq1uUjg2tpSrmNJ597+AvpVlbha/67fg7eHRZy7Jtp0HldXx iBu4gRWbfuHel2XEYa28Dj35a1MAaXuQEykshf3XIi6ex9rMmC/Ew8kmo1TbE1dZ5/FX qQDvLi+nsiMTwRJmbFf1RcZpvR5TuYyzUGsTIOxDjkpMfL4yYsE0FiMKE8g3ATphXjJL cZ06AFxv6H0gXkM71+zYR6ZS7xJC3XwCY4ihnPqPsEYB4nsQO66sC2pgk8+eRDx+v9hX bHtQ== X-Gm-Message-State: AJIora9dkdCWKjsyWBUx3OlgaWhQc+XYuQwUS6YyW7V4cWlWqjTNqUW8 PAYip9t7XMCKuJIbui/NCgeqAtSsjmxq0g== X-Google-Smtp-Source: AGRyM1vfwdX+IU1pBkJnMoMehUrSsgbsvyTQFc/2Bzcsp/uluMCnUzz7JoxDoP5Yqc9QdJr4MEv0Kw== X-Received: by 2002:a05:6000:1f0b:b0:21d:6dae:7d04 with SMTP id bv11-20020a0560001f0b00b0021d6dae7d04mr36151502wrb.414.1658430838263; Thu, 21 Jul 2022 12:13:58 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h13-20020a05600016cd00b0021e4e9f6450sm2630637wrf.84.2022.07.21.12.13.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 12:13:57 -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 v3 13/26] submodule--helper: fix "sm_path" and other "module_cb_list" leaks Date: Thu, 21 Jul 2022 21:13:09 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1095.g0bd6f54ba8a 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 | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index ad11ff20022..a5492c6d89a 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -820,16 +820,34 @@ 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; int alloc, nr; }; #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; @@ -1172,6 +1190,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 Thu Jul 21 19:13: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: 12925709 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 3DC01CCA485 for ; Thu, 21 Jul 2022 19:14:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229684AbiGUTOc (ORCPT ); Thu, 21 Jul 2022 15:14:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232411AbiGUTOG (ORCPT ); Thu, 21 Jul 2022 15:14:06 -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 924A18CE8C for ; Thu, 21 Jul 2022 12:14:05 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id id17so1580542wmb.1 for ; Thu, 21 Jul 2022 12:14:05 -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=yQ6uyQNX2Suui5juRKz5J57X9l+PRekZyvmbwm4mcsI=; b=ZDY/w4i0WUNmPd80RuXoZGt4LF3bnWQDoQUmv8UzsBxqAvkNxBpUieuepp/5rbCvTY UtzlEU+Ba6kuhQVJonsUoBvvnNqxKQjbieQbknVfNVzn0g5jS/lZfOAIE4Xpy7eguTEk VU33z2g0AL+twMdEC9gQSCUsmlNNLKO0bQXnxEO0ZDborTjn1veyy6wh6nbMIPiis2f9 HxfPA7OppzUDLTCpLMNT5uQHCVT/MOrdlAp2adHl3QRuXbTMgxmw9nthv5XmO4MKvxGR urcyY1i71V1w1uoG69xK6raQFrTLBGtp6a0sLhFHq+ZbZI+VquIAK1tGnrTpsWBiTiyP TV1A== 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=yQ6uyQNX2Suui5juRKz5J57X9l+PRekZyvmbwm4mcsI=; b=2XvK78KnmJGzG6EdfUtk6xLOyH79jWW+CvJj9nGXdV8SKknqN8NkJcv+l75Vi8PiZm JIo8fdYpOHvz6KSpA5t5h5+BJMqeETKVtsexhmYsJJwLyyVX1TiiLqXK0BDWa4pTmk7n VftPhEvgbhDEtInim92iljcKRW7DLWQ/N5BfXMRYGDpFWMavPTqMXew6uC6KHNEnG4KL n8uJO0AwKGz+3hgr6dkksK+Hms6DuCFm7I9VWqhp/zJ53gl+mxJxAkC5qyYrf9ixqBzU 73X3S/WnswCGT6ek7AQttqS87gZ368XkPT5XuEuUVMJZ4az1okZNiuWJEYDwaR8CNRz3 LYKQ== X-Gm-Message-State: AJIora/k4WZtapBFikJc3P516erBm0H9WLtHP8HhxLke7Eo3RNu9bLuj J0rQFTh367IQELSdWhu2BX3ZWrU0c0Q2OQ== X-Google-Smtp-Source: AGRyM1u/Drnlno2Bcd89+5sN5Fam/9hEuZXKcwCJ0kuvgp++Jd3YO9iVGBAZGsOo8Z627PMqz8kQ6g== X-Received: by 2002:a1c:c912:0:b0:3a3:20d5:8351 with SMTP id f18-20020a1cc912000000b003a320d58351mr9253095wmb.126.1658430843841; Thu, 21 Jul 2022 12:14:03 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h13-20020a05600016cd00b0021e4e9f6450sm2630637wrf.84.2022.07.21.12.13.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 12:14:01 -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 v3 14/26] submodule--helper: fix a leak with repo_clear() Date: Thu, 21 Jul 2022 21:13:10 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1095.g0bd6f54ba8a 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 + 1 file changed, 1 insertion(+) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index a5492c6d89a..a3de17754fd 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2458,6 +2458,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) From patchwork Thu Jul 21 19:13: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: 12925710 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 43E98C433EF for ; Thu, 21 Jul 2022 19:14:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232429AbiGUTOj (ORCPT ); Thu, 21 Jul 2022 15:14:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233498AbiGUTOJ (ORCPT ); Thu, 21 Jul 2022 15:14:09 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 616AB8D5DE for ; Thu, 21 Jul 2022 12:14:08 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id a18-20020a05600c349200b003a30de68697so4201083wmq.0 for ; Thu, 21 Jul 2022 12:14:08 -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=Yh+6/9bceYfLosADtVBmxs+gkRvxO4rQNtsDR0A5RNM=; b=Xkq1wr/PSazox3M4pxnua/JCx2zJDMAuWcnDU28gk/6PFEeEypSR22xhvQHGCQiyfa mygDYoRvW/leLAsLRg+ckTxHCxkDIExhdTs04YwAjODZaseYGUb/fQrMQDBhhEfVWTG4 MPLFTmFXVq9hvWzwjFJqUwWlKxz/WEUV6jd+OPPwhb/+Q5e3QnzOu+Bdyl1Fzxwd2vtL 3k4q67T1CLS4nbfXXng3ON5R9xUyVk4Jrpvtv3HjeXPrtt7Lc0CJVgp0Q3up8qvTc6bK YSld/c/2bvEfMwKI7+nxGSFr5rS7YtFYH8paMHmYURliSzCK2McVFosIJnYpcfpxgy5N vx1g== 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=Yh+6/9bceYfLosADtVBmxs+gkRvxO4rQNtsDR0A5RNM=; b=d/4SCezZYF7exHIyc3oPHQqmYhDuZbXtrE6861jEvY8EVzQ2mHfJ/9tx+H+T/LA7w1 ugNV70GUZrCPNhOn13nFhm3/wba2eH9j/MPmLH1sq9zIi5hlsX1HxVNQR1rCZ3bdxSaP E3k5gLd1uP3IXRpHfj9Un3ewQTqqeIrwZ1rHMu2NAI9w9XS/qlG9av32Q+2Gr3DlytP+ LtXf6JXQnVt2fBvGPJZQ+3t5KxS8sxlq8I2VvuhOD1cF2N2QNWRF/LuXPq4cB8m7g8zn joB7dYIVJZrm4uEuJS+8FzvxMujBQZGFvM4qaZDYvlqfL81DvQ6jdfMk/ClWSdLwSTq6 J+VQ== X-Gm-Message-State: AJIora/m/L0tcECaykDKRawCzMM1dNjX+czO5Xxmnxksg8Zekt8pJY/x LxcCaxYR+tznRROLJ01Vo/fBUlozBhAGHw== X-Google-Smtp-Source: AGRyM1v5RPTC+JGSYnLKq760kiHGRtLQPfhK4/RYxStUGPuzjtx0v8iGUpvESYpMVfSO+TeQvFZG7A== X-Received: by 2002:a1c:241:0:b0:3a3:142d:b65 with SMTP id 62-20020a1c0241000000b003a3142d0b65mr9392041wmc.171.1658430846508; Thu, 21 Jul 2022 12:14:06 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h13-20020a05600016cd00b0021e4e9f6450sm2630637wrf.84.2022.07.21.12.14.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 12:14:04 -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 v3 15/26] submodule--helper: fix a memory leak in get_default_remote_submodule() Date: Thu, 21 Jul 2022 21:13:11 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1095.g0bd6f54ba8a In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a memory leak in the get_default_remote_submodule() function added in a77c3fcb5ec (submodule--helper: get remote names from any repository, 2022-03-04), we need to repo_clear() the submodule we initialize. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index a3de17754fd..fe490c8d44d 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -62,9 +62,13 @@ static char *repo_get_default_remote(struct repository *repo) static char *get_default_remote_submodule(const char *module_path) { struct repository subrepo; + char *ret; repo_submodule_init(&subrepo, the_repository, module_path, null_oid()); - return repo_get_default_remote(&subrepo); + ret = repo_get_default_remote(&subrepo); + repo_clear(&subrepo); + + return ret; } static char *get_default_remote(void) From patchwork Thu Jul 21 19:13: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: 12925711 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 94262C43334 for ; Thu, 21 Jul 2022 19:14:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233525AbiGUTOl (ORCPT ); Thu, 21 Jul 2022 15:14:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233510AbiGUTOR (ORCPT ); Thu, 21 Jul 2022 15:14:17 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A0148E1CB for ; Thu, 21 Jul 2022 12:14:08 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id bv24so3615755wrb.3 for ; Thu, 21 Jul 2022 12:14:08 -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=JOuEn2p8EmsjJccZxrWBALydAr/Z+pOthem45msEB14=; b=ghuWAg/OVebIrHoQz8T19K3cHR9M9DWMkLjsKO+z2a0GkNAJKKk/JYxQkN0tYq3sff l39P4WMCn5DiScDHQA1wwdQHYuJRZ2jDyTldKs4d2fhiTypLesHZOiBy9uwYzyax0Fvq eiyHAGtx7EedBDZwCBeLd/lJgRRhRKnfIkdU3EvES2Cv6ZPJ+YiqLRUrB7Z9VctHSGQK rHpmsK3mXnd7+bpYlk2vpEbxj5iZXHZZm2FGAe+IMSdGOUflEbVu92DMMWBLR+hCAzsu aEM7KZfEv9zFlpTW6KgmWQYBmt5uGGvPLcWNxuj59Apf3ZkwA9GbmhbsyAKA102dx/nt 4kGg== 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=JOuEn2p8EmsjJccZxrWBALydAr/Z+pOthem45msEB14=; b=QRfDwq0kZ0gYIdZ3ObztxDbfxVaWf3IMA4tActily900OXLqSc59Yri2ElIihyOVTn Y9kVtIFYK3Wq6WFYHrc34J0tv/b4EQyOtuklTp/3Kg5XWL6or4/Q8txON8k/RtSFGVXp wWMCTql99KU0d1C7LPSGXsNFdE6tdoFeQnwkkhF1PhHIN+XRiUxuvsdbg5uYdw7x1JjF 3/Vb5NEaZToqcMvkIpbPOVZKOnGnajI/MLn3sJS0g3KWbQrwjCwcs4Hv5BZrRXorj3gi o7G6BSKZgkZyBYNkyuRrXKHFVTgLr6GiA4IVa8HUsp4kcWVh9g6AKDOWBLP97DY1jhLS ygCg== X-Gm-Message-State: AJIora/NZ9QPCfFvyuNkBbpYvkN48z2vX94972NZSItQTHol0+BCgPE8 h3XpnL8JIPiQKv9ssRBXIx1MR9Mu7Ng06A== X-Google-Smtp-Source: AGRyM1uRIBG07748ndyZEqwPBsV1gsSEvwL6Vhh8IMBJAlCcHHRgeGdOvBuB5UajgLBtov2J4eZrgg== X-Received: by 2002:a05:6000:508:b0:21d:4105:caf9 with SMTP id a8-20020a056000050800b0021d4105caf9mr37017845wrf.699.1658430848094; Thu, 21 Jul 2022 12:14:08 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h13-20020a05600016cd00b0021e4e9f6450sm2630637wrf.84.2022.07.21.12.14.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 12:14:07 -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 v3 16/26] submodule--helper: fix "reference" leak is "module_clone_data" Date: Thu, 21 Jul 2022 21:13:12 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1095.g0bd6f54ba8a 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, otherwise it'll be NULL (i.e. from argv). To fix this create a 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). We only need to add it to add_submodule() to fix the leak, but let's add it to module_clone() as well for consistency. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index fe490c8d44d..80c1c1d4918 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1584,6 +1584,11 @@ struct module_clone_data { .single_branch = -1, \ } +static void module_clone_data_release(struct module_clone_data *cd) +{ + string_list_clear(&cd->reference, 1); +} + struct submodule_alternate_setup { const char *submodule_name; enum SUBMODULE_ALTERNATE_ERROR_MODE { @@ -1636,7 +1641,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) { @@ -1873,6 +1880,7 @@ static int module_clone(int argc, const char **argv, const char *prefix) clone_submodule(&clone_data, &clone_data.reference); list_objects_filter_release(&filter_options); + module_clone_data_release(&clone_data); return 0; } @@ -3117,6 +3125,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 = -1; /* perhaps the path already exists and is already a git repo, else clone it */ if (is_directory(add_data->sm_path)) { @@ -3171,15 +3180,17 @@ 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); if (clone_submodule(&clone_data, &clone_data.reference)) - return -1; + goto cleanup; prepare_submodule_repo_env(&cp.env); cp.git_cmd = 1; @@ -3198,7 +3209,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) From patchwork Thu Jul 21 19:13: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: 12925712 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 7F85DC433EF for ; Thu, 21 Jul 2022 19:14:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233559AbiGUTOu (ORCPT ); Thu, 21 Jul 2022 15:14:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233561AbiGUTOT (ORCPT ); Thu, 21 Jul 2022 15:14:19 -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 886BD8E1DF for ; Thu, 21 Jul 2022 12:14:10 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id b26so3634558wrc.2 for ; Thu, 21 Jul 2022 12:14:10 -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=+96UJwVCBGEHTJTdAEL2CjrRbrH+GdBWKcuziYdEIWk=; b=n5Xw5hCsc5ULmR5zYVE/lg98/EFiXuz7JLzZZq2bFWDBUdf8PJS41L8Awx9F+n9cYM /bkF0jOlbIi1yW+Bq9XuEfHOzNa9ug4xs4JYDPj/f5xSoXEQ7qyc0SZDvfY8J1MI/hCK LA0QSFG6cMADMbfeayXxeQs5bXPhOc8bGmRXt0GPW5Ax64qZiWq/RYbNCuPJw37rYBMn tW97OuBXvv+ccZAPixBcLKER16qiJvmMi1ap32lz6vq11pS1kC7KWtJyGYiRMfjK/yf1 yyhd0GrMnDypLDZFD5OuPUBRb1v8F6EWVklFAajhNJ0nNg1LeQtgfjqUBZu4RlnWjzzU ce3g== 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=+96UJwVCBGEHTJTdAEL2CjrRbrH+GdBWKcuziYdEIWk=; b=Vqt0B6n5/YtogzbUmkF7RAhtPmDr0Y13YBmjWd8holRRUhlydL2MQ+9TyqjFOjW+RX KojRSsmyTW7xRiyQmfHu4yA/TjuDaXNjas4rTu+rLlov2hwl83kQ+mKJt2naphqrVkYL ksJdluUkVh/Sngzy5N29u+VTiPs7TO89X3zLu57Ehw4bG0nPukN2ihYuLXb4oVjrr+oS V/RU5G107ctA3SkZJAhYdgSK1BcY8tukfUFrE2PoKKk1f0/SoYwQJm9KHwnBv5htQ8zw fFGxIq8MCyOqzlTGdh5IQ4yFzIJNTTTTYnAJgAe4lf2FAen1od2vuRzanMqR/Fhs3p3F 70+A== X-Gm-Message-State: AJIora8q9JUXTE7k60ViecBD+oeuN1WTbI58sQzVRwgeHizIvWH+AdQA lQyuCMwhmjrm8soAvb49ITWrgZ5YDXTifQ== X-Google-Smtp-Source: AGRyM1swnV4qnSA/BN/ptfnQiDArSWfRaPmwtNn8SYIUe7UO5yQMN/5+O7KIvsEaY28X/0Nr53IA8A== X-Received: by 2002:a5d:44d1:0:b0:21d:7471:2094 with SMTP id z17-20020a5d44d1000000b0021d74712094mr36148308wrr.374.1658430849663; Thu, 21 Jul 2022 12:14:09 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h13-20020a05600016cd00b0021e4e9f6450sm2630637wrf.84.2022.07.21.12.14.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 12:14:08 -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 v3 17/26] submodule--helper: fix obscure leak in module_add() Date: Thu, 21 Jul 2022 21:13:13 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1095.g0bd6f54ba8a In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix an obscure leak in module_add()< if the "git add" command we were piping to failed we'd fail to strbuf_release(&sb). This fixes a leak introduced in a6226fd772b (submodule--helper: convert the bulk of cmd_add() to C, 2021-08-10). In fixing it move to a "goto cleanup" pattern, and since we need to introduce a "ret" variable to do that let's also get rid of the intermediate "exit_code" variable. The initialization to "-1" in a6226fd772b has always been redundant, we'd only use the "exit_code" value after assigning the return value of pipe_command() to it. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 80c1c1d4918..04b5141c0f9 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -3352,6 +3352,8 @@ static int module_add(int argc, const char **argv, const char *prefix) int force = 0, quiet = 0, progress = 0, dissociate = 0; struct add_data add_data = ADD_DATA_INIT; char *to_free = NULL; + struct strbuf sb = STRBUF_INIT; + int ret = 1; struct option options[] = { OPT_STRING('b', "branch", &add_data.branch, N_("branch"), @@ -3423,20 +3425,16 @@ static int module_add(int argc, const char **argv, const char *prefix) die_on_repo_without_commits(add_data.sm_path); if (!force) { - int exit_code = -1; - struct strbuf sb = STRBUF_INIT; struct child_process cp = CHILD_PROCESS_INIT; cp.git_cmd = 1; cp.no_stdout = 1; strvec_pushl(&cp.args, "add", "--dry-run", "--ignore-missing", "--no-warn-embedded-repo", add_data.sm_path, NULL); - if ((exit_code = pipe_command(&cp, NULL, 0, NULL, 0, &sb, 0))) { + if ((ret = pipe_command(&cp, NULL, 0, NULL, 0, &sb, 0))) { strbuf_complete_line(&sb); fputs(sb.buf, stderr); - free(add_data.sm_path); - return exit_code; + goto cleanup; } - strbuf_release(&sb); } if(!add_data.sm_name) @@ -3451,15 +3449,17 @@ static int module_add(int argc, const char **argv, const char *prefix) add_data.progress = !!progress; add_data.dissociate = !!dissociate; - if (add_submodule(&add_data)) { - free(add_data.sm_path); - return 1; - } + if (add_submodule(&add_data)) + goto cleanup; configure_added_submodule(&add_data); + + ret = 0; +cleanup: free(add_data.sm_path); free(to_free); + strbuf_release(&sb); - return 0; + return ret; } #define SUPPORT_SUPER_PREFIX (1<<0) From patchwork Thu Jul 21 19:13: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: 12925713 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 AE5B4C43334 for ; Thu, 21 Jul 2022 19:14:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233585AbiGUTOx (ORCPT ); Thu, 21 Jul 2022 15:14:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233588AbiGUTOT (ORCPT ); Thu, 21 Jul 2022 15:14: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 193998E1F4 for ; Thu, 21 Jul 2022 12:14:13 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id k11so3161807wrx.5 for ; Thu, 21 Jul 2022 12:14:12 -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=3RNlS1TR4hBewdyukg+RzozAukrveUc4ncZ7hug1a3Q=; b=LhjmClWdd1bfHaHtUca8XaS9Ct0z39JeZgPVhfX7Vjd2rRDDFkslLXQIRjqQjI4bMY Ihp3uDgTGgRyPgdrl/WKtJ3DeK91Zz+TD3s/hOUf2fMkXj57A5Wi3j0McvOOYUKiCZoc w/zd14F09dD9b8Jl6zBm++mVFSvCLINVlLArXF1MmstDF9sT+hWwaSXj+/ohd0oLFKHi f4j+sXH0bp+6ZqkybJPvz8R9GGEyCXYKcN4RzYrb9J3MvfMzEEXwQvwuHsdjXaMNpRsu lXnzphxHwGnYRjf7Jx2kiFZ4wkQ/v8klFSjt3uwblh+I9tBvTzoRijpuzkYwBa9zA555 NkIQ== 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=3RNlS1TR4hBewdyukg+RzozAukrveUc4ncZ7hug1a3Q=; b=xtZTJSaqsLeFGcmqWJIKf28HPlUscujEAgA03DEGzG0/AmqjNWWFw8U/DNsujL+Lhw vf53ZqZs4BttHMyi+CR9cbd3dNKvSH0f8uQGjw4lAIlHQJLNbuZp8MgFI9hW/trvzeHJ 16A7t7s16zBfhlsynvtnPusU2hDJLM/2eOWgCIUiry4KuE6W6SORkoYOoVu+SUP8ln4m cyYai9uaDdgh+hcRZ/13EO3kc29hTJAvrdANCiqHq9i5LnbHRk0Y4Lqy8DJGpIuMIGVz 27IzyBTkrKfRB7V+GmG3uz89O5naxxCPtP5Kaf3SSsrTegr5jdrx3nbIXUFYYMMsLlNm CfIQ== X-Gm-Message-State: AJIora+2YPyzJ+XKk+z8P7D+U+KYCrCdlFZzfY4NZB/MeO7lCjoaBdoq JVLWQvM4piRHVgwiky4k/IpCzFcFRb9p/Q== X-Google-Smtp-Source: AGRyM1tAAE/cE0gZTL5pLumK4CKmgqbfOVZqbAeNmCBDpQbagdH6RWdwhRX1ve7+dQKmz6dl58+PBw== X-Received: by 2002:adf:f548:0:b0:21e:4348:3991 with SMTP id j8-20020adff548000000b0021e43483991mr10290306wrp.130.1658430851184; Thu, 21 Jul 2022 12:14:11 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h13-20020a05600016cd00b0021e4e9f6450sm2630637wrf.84.2022.07.21.12.14.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 12:14:10 -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 v3 18/26] submodule--helper: fix a leak in module_add() Date: Thu, 21 Jul 2022 21:13:14 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1095.g0bd6f54ba8a In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a leak in module_path(), since a6226fd772b (submodule--helper: convert the bulk of cmd_add() to C, 2021-08-10), we've been freeing add_data.sm_path, but in this case we clobbered it, and didn't free the value we clobbered. This makes test 28 of "t/t7400-submodule-basic.sh" ("submodule add in subdirectory") pass when we're compiled with SANITIZE=leak.. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 04b5141c0f9..0fb720d3a16 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -3395,8 +3395,11 @@ static int module_add(int argc, const char **argv, const char *prefix) else add_data.sm_path = xstrdup(argv[1]); - if (prefix && *prefix && !is_absolute_path(add_data.sm_path)) - add_data.sm_path = xstrfmt("%s%s", prefix, add_data.sm_path); + if (prefix && *prefix && !is_absolute_path(add_data.sm_path)) { + char *sm_path = add_data.sm_path; + add_data.sm_path = xstrfmt("%s%s", prefix, sm_path); + free(sm_path); + } if (starts_with_dot_dot_slash(add_data.repo) || starts_with_dot_slash(add_data.repo)) { From patchwork Thu Jul 21 19:13: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: 12925714 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 A6299C43334 for ; Thu, 21 Jul 2022 19:14:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233603AbiGUTO6 (ORCPT ); Thu, 21 Jul 2022 15:14:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233610AbiGUTOV (ORCPT ); Thu, 21 Jul 2022 15:14:21 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68B188E4C8 for ; Thu, 21 Jul 2022 12:14:15 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id 8-20020a05600c024800b003a2fe343db1so1332125wmj.1 for ; Thu, 21 Jul 2022 12:14:15 -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=myLC+ZqfQqTXEIgftN8DvdkREXdtkzgV+aYv8VPorLA=; b=PRv0oueqLVcPERAgcgRKNSXHmuWkIFDW7nM+yMa1h+FOvvlGfJYIZtCQeuueAkcPff sA4w3vuOCUsM26YbDuqQb/9caakeggf/f8A8Ix7pHJqwp68glw6khO1BnirQgKIRt4a5 mG2WnZ7awxILKcd2YLfaNcJZmqZYRH1VT6UdZze6Qt3iuFjl4Y0FMinf7iodDgaN4v+t HUarTdUqLWE0lx6NXztHbqRH4/Z9aZ0E0njffBv1iVkkYXgaX+0Zfh9CtcARk6CtMYms DW5oFc+fEqIza+4bzFQV02Ogi11wX4qUDp9NSc5bMbiVv1CyzcBtefMuKW203RRsAo6J 8VHg== 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=myLC+ZqfQqTXEIgftN8DvdkREXdtkzgV+aYv8VPorLA=; b=k/62WjHKBlFlbdOfM4sYVLvz/b31/ATHalDjE2XPe4WYAgpW3JZDkseXlTrIuux5o1 KrFBgCTgDvxn7o+dEY/vwOZCYW4hwywNt0jV72dyc1XD+piWuzRCG2MVdhBCnNmWMFK8 XWyhH4SpudDXx8JUAyRJp0G3ul28q9Z1aeA/NYFLl7xVt1TfCL0vcSuTTzKMghXkyE2/ Gr7xav19DpLc0eaFA9/fiojduX/LbDiOyapIBgN/hrnVrgJ+EoHUYkC3OAxLkT5dTZKC H8ZWP9TNRV6CC+2lNz0DCz3i683S4UUBObo/FnjIcNIPfPeaAVM/4r0k3rIYQFNlx390 93IA== X-Gm-Message-State: AJIora9vAEuFt5N3/NU/FKXQKCRIre+Jl978YWMYcZH4uCERa/lRYgAI UVV/nJvzZbI19zUppbVxwTi49+XyHMYpsA== X-Google-Smtp-Source: AGRyM1uruA23abTru56albnyMmkHzr0C5jjZAIKxdQ4K1Dq9ZQ8pYqS0ryynw1sStJgbxpYfjzN/8Q== X-Received: by 2002:a05:600c:1c83:b0:3a3:1f70:25a5 with SMTP id k3-20020a05600c1c8300b003a31f7025a5mr9541783wms.54.1658430853384; Thu, 21 Jul 2022 12:14:13 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h13-20020a05600016cd00b0021e4e9f6450sm2630637wrf.84.2022.07.21.12.14.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 12:14:11 -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 v3 19/26] submodule--helper: fix a memory leak in print_status() Date: Thu, 21 Jul 2022 21:13:15 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1095.g0bd6f54ba8a In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a leak in print_status(), the compute_rev_name() function implemented in this file will return a strbuf_detach()'d value, or NULL. This leak has existed since this code was added in a9f8a37584a (submodule: port submodule subcommand 'status' from shell to C, 2017-10-06), but in 0b5e2ea7cf3 (submodule--helper: don't print null in 'submodule status', 2018-04-18) we added a "const" intermediate variable for the return value, that "const" should be removed. 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 0fb720d3a16..4decbdcdc5c 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -637,10 +637,11 @@ static void print_status(unsigned int flags, char state, const char *path, printf("%c%s %s", state, oid_to_hex(oid), displaypath); if (state == ' ' || state == '+') { - const char *name = compute_rev_name(path, oid_to_hex(oid)); + char *name = compute_rev_name(path, oid_to_hex(oid)); if (name) printf(" (%s)", name); + free(name); } printf("\n"); From patchwork Thu Jul 21 19:13: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: 12925715 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 F04C2C43334 for ; Thu, 21 Jul 2022 19:15:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233652AbiGUTPC (ORCPT ); Thu, 21 Jul 2022 15:15:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233656AbiGUTO2 (ORCPT ); Thu, 21 Jul 2022 15:14:28 -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 9C6078E4D9 for ; Thu, 21 Jul 2022 12:14:16 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id b26so3634890wrc.2 for ; Thu, 21 Jul 2022 12:14:16 -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=E4h2siDrQDNXEtig58zecJxF3gBab2/L/AEPMJKpXKQ=; b=P5HPUGLIAikFh5Grg8NjMorqkHHyOSifM7UnLM3NIaKVxu3KSKnDqOEaUyS16Fnblq TE/c0gqBOH7be2HRdwui2LCvJ19rsXGysuLvDCT/QeZml8E4n6sEne9dJZl+zvksYKmF FEpLtRtf//nuD8ZSNM7Uv3cTKOWkoELHOCdyX/u6R/M2VdQiVLFTtRqlEO50vUKHg8XA bi8e6yIWmlgEYjYuOEyEXMIy9fqxo7JmTvNGHnZzCQbMEeFzb8d7zfMNSpp67BLHDm2D h9BfwvzwduBEA8pWjJ4lhDnfmhE4sXGPYM00a1eMPQunmr+137dFK3papGwyJkpqjGJY f1zg== 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=E4h2siDrQDNXEtig58zecJxF3gBab2/L/AEPMJKpXKQ=; b=F7/5zQsWqNvkgaobYPob75YpXiPNpikvEBHKmDnFoZHMgwh6hIHUXrl+zdKVJ7Y2CJ i28VsUBCsTbq4K+jwXfNiO+kVEwWlUltxAO5BX8O68jw48RDqSSiVYXOXdzqdxxQHR5d cgqUH7THZcPYhBrzc0Rws7CTecK2tP9ksDmghy35YzPWWhCA8FLldlWfMoYsBCiCh+DN MmT3JgIkp/zi2U4RDqD71gPyt9ETMmoX5qOJV6ZMpgmV5wyzIxjqz2pnD1+2siVOUzbd CS0zzR8Z/y9/24DpP9hFCtePPiBKVpznjW6xdLwbEUsKR/cRBirWmqM70zKO29KWBgg5 ePlA== X-Gm-Message-State: AJIora+aJzm7pdrYAQbUEN4/mroBS6qdjvDh43iY4TXo/S/tCf3yPl7H pSr1TmzqCcJAb+7eTb/1+qHHeb2yaIPPdA== X-Google-Smtp-Source: AGRyM1t79E9qyKTQ42dISvgi9w+sHHZGrptQLaPFmI2EhWMiJxm774NuBWEet98QZb6GgUXy3peUPQ== X-Received: by 2002:a05:6000:1d86:b0:21d:6433:1455 with SMTP id bk6-20020a0560001d8600b0021d64331455mr36337529wrb.514.1658430855746; Thu, 21 Jul 2022 12:14:15 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h13-20020a05600016cd00b0021e4e9f6450sm2630637wrf.84.2022.07.21.12.14.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 12:14:14 -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 v3 20/26] submodule--helper: free some "displaypath" in "struct update_data" Date: Thu, 21 Jul 2022 21:13:16 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1095.g0bd6f54ba8a 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 "displaypath" member when appropriate. The "displaypath" member is always ours, the "const" on the "char *" was wrong to begin with. This leaves a leak of "displaypath" in update_submodule(), which as we'll see in subsequent commits is harder to deal with than this trivial fix. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 3 ++- t/t2403-worktree-move.sh | 1 + t/t7412-submodule-absorbgitdirs.sh | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 4decbdcdc5c..378f85e37fa 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1954,7 +1954,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; @@ -1992,6 +1992,7 @@ struct update_data { static void update_data_release(struct update_data *ud) { + free(ud->displaypath); module_list_release(&ud->list); } 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 Thu Jul 21 19:13:17 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: 12925716 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 55C8FC433EF for ; Thu, 21 Jul 2022 19:15:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233682AbiGUTPJ (ORCPT ); Thu, 21 Jul 2022 15:15:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233678AbiGUTO3 (ORCPT ); Thu, 21 Jul 2022 15:14:29 -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 91F928D5E9 for ; Thu, 21 Jul 2022 12:14:19 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id p26-20020a1c545a000000b003a2fb7c1274so3920102wmi.1 for ; Thu, 21 Jul 2022 12:14:19 -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=aqWlHNlN2hfcBaap+tKLkkWT1gjuPPB+lAQMe+hl1D4=; b=A6MCq04YFjCZgFFFDq9EJDaF314qtxXgvZzNGp5nfAMWnitDT6M2faBx0XfauvCVqa vL2TPWoLm0LAfU5ebo7kVHGxWamIMRWPczGPEQ3zrL8/CbSd1G/8JvqtF3u3A9Fp0Os7 S6R+kBbCAjm9JFH9uvHR1YJSCkoJxKEf8+FjX5USb5U2Ex1rqvQ71pEnDvzrSCwirSf3 G5h3oB/ejJ3GI+w/pobOc4rIBdxYPT4O3ZCOiLLW8nJTuw5daC4iyqcgqZL+flPmcw24 crllwM4ymsADWlyYnH5YfrslmjsXklu1hWuHdQTR+SuBCejSXbCv4Xya9f0fBRZokwR3 diKw== 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=aqWlHNlN2hfcBaap+tKLkkWT1gjuPPB+lAQMe+hl1D4=; b=vDJUlkZsdhoYOK8NNQpncU/6gxM4i5JJBLFblUMsr2DrymB3GOxD2Mykp8+vwOth66 Y2Zx9ukW6BwX1q3EfCcgeh/bdJYQKOVqeXB7w4j7z4LNEZQExgrEqqObYEOhjCLDI0HB 69sW6R9cL45CXrxMj2VsnCKN2H/V6RztsPrpTRLCdPNJicJESk9TtqDOW7JAPyTQx4pB DYKsYla716cww7qInNZ4Hx7n0uZyoWvpg2neX/IJ4+smt9NXUMN3rhpV9XSl5OKdtlZA /JFjrqsRaZBhmIiZJ5fyMf9I530llyw85HzfuHV+o+pDPVN+9sh1eJQ9UgMUDkkYrDlJ OESQ== X-Gm-Message-State: AJIora8YIyawEnRIjg2y7RKR0tgN94Q/Ga9TQ4PyS5CHph+7/oBopVOT Yh3YnBenFk0yIQ+8wN4K67Ywvp2kDlQKyQ== X-Google-Smtp-Source: AGRyM1v5i+ira/N8dLqctN314ce+bWsTWzCmi8jNR34tMRVCM+2QLJYsqcSLv58IOfwJrvWTQ7dg/g== X-Received: by 2002:a05:600c:4f05:b0:3a3:18ed:6cda with SMTP id l5-20020a05600c4f0500b003a318ed6cdamr9754277wmq.34.1658430857885; Thu, 21 Jul 2022 12:14:17 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h13-20020a05600016cd00b0021e4e9f6450sm2630637wrf.84.2022.07.21.12.14.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 12:14:16 -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 v3 21/26] submodule--helper: rename "int res" to "int ret" Date: Thu, 21 Jul 2022 21:13:17 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1095.g0bd6f54ba8a In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Rename the "res" variable added in b3c5f5cb048 (submodule: move core cmd_update() logic to C, 2022-03-15) to "ret", which is the convention in the rest of this file. Subsequent commits will change this code to a "goto cleanup" pattern, let's have the post image look consistent with the rest. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 378f85e37fa..94eec34c595 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2588,7 +2588,7 @@ static int update_submodule(struct update_data *update_data) if (update_data->recursive) { struct child_process cp = CHILD_PROCESS_INIT; struct update_data next = *update_data; - int res; + int ret; next.prefix = NULL; oidcpy(&next.oid, null_oid()); @@ -2600,14 +2600,14 @@ static int update_submodule(struct update_data *update_data) update_data_to_args(&next, &cp.args); /* die() if child process die()'d */ - res = run_command(&cp); - if (!res) + ret = run_command(&cp); + if (!ret) return 0; die_message(_("Failed to recurse into submodule path '%s'"), update_data->displaypath); - if (res == 128) - exit(res); - else if (res) + if (ret == 128) + exit(ret); + else if (ret) return 1; } From patchwork Thu Jul 21 19:13:18 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: 12925717 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 25AD6C43334 for ; Thu, 21 Jul 2022 19:15:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232865AbiGUTPM (ORCPT ); Thu, 21 Jul 2022 15:15:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233691AbiGUTOa (ORCPT ); Thu, 21 Jul 2022 15:14:30 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 811358D5FA for ; Thu, 21 Jul 2022 12:14:21 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id z13so3591591wro.13 for ; Thu, 21 Jul 2022 12:14:21 -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=Mql5+u/XqNeByiUP0iOQP0yFNSEZMBXbVpoUl3NXryk=; b=mkMy7Jwbe5le3XrTCleU6CZ4oZqDsN6+3Elrt29t6DyhVqQrl4dcPZtjSQzBF32i03 HsviJuIujuZAYLtEjdLeQEw3P/HVOZ8PLRo7L3Zbau7gLAfh22kxZnTOn5oS3RB5pUT2 wfGA7AlDqO2vv/HKYYSBa7AUhVBJVU6SCmZSDt078/NJ+w8pqqvsquiqCGg3hJ12ZTEi LTsA3EqTCEZSNVROTOHbqBpuzprsaNSArCf0wU9oeUJc4iwqLZWq/6C6QD9sW+GyrTUN g/9yAeAfHyDfCWH+ttdOgdvTp6vb/7spZbdD3w+UCobZQHrBctHjirWv8N3eZ5q8h6pE av/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=Mql5+u/XqNeByiUP0iOQP0yFNSEZMBXbVpoUl3NXryk=; b=z+d6A5E0zhMW/UUNnwTMuJK9PERghLQHvMg+T26LAhOzC18kSMeyyBOygj+0dZC1gy Jk6vbhQM1aIC/ppot91tAxN3EITr/M68jbmpQaUqmTdhrXcYKWXIjlGJAKtmftMYrz90 sudF/n/3o/fLJfNnoK4sa/cRD+tU8ICZYqYj5O6yTymSMbnL1jagM2ckIHCHDms4tiKz h28NpNBNsi1oNOy9CJxICf0so+HOn0ETZMDdte2Jnh8qAlfB4yBTZdj/w4XDMjGfpSTY YrqZC0fyoSYjFgoTzZkbRwdiHrS5C78tf9nmnYWAJW54mWv1iq3qQEPzUOrr3H/TyKNp vMGQ== X-Gm-Message-State: AJIora/wN9gt0yV9WOJPAd0GkdRjvqHrWYc1MkW8K+rtH9kkYiI28jfY josAN0YXNyM41BNUxERXohK8E1qQnccaig== X-Google-Smtp-Source: AGRyM1tAa69tbDKtydSLeE6YeBhUNJ5ZWgMoQeUMRjaWikpTgqL9ox6RU0rG9dp9LYOilT5PzVru+Q== X-Received: by 2002:a05:6000:18c1:b0:21e:4712:b284 with SMTP id w1-20020a05600018c100b0021e4712b284mr8583894wrq.545.1658430859548; Thu, 21 Jul 2022 12:14:19 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h13-20020a05600016cd00b0021e4e9f6450sm2630637wrf.84.2022.07.21.12.14.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 12:14:18 -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 v3 22/26] submodule--helper: add skeleton "goto cleanup" to update_submodule() Date: Thu, 21 Jul 2022 21:13:18 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1095.g0bd6f54ba8a In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a skeleton "goto cleanup" pattern to update_submodule(), rather than having branches in it "return". This is in preparation for doing something useful with the "cleanup" label, but for now we're using it as the equivalent of a "done" label. The "exit()" branch is not handled yet, and neither is the exit() that run_update_procedure() might invoke. That'll be handled in a subsequent commit. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 94eec34c595..790f0ccb82e 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2545,6 +2545,8 @@ static void update_data_to_args(struct update_data *update_data, struct strvec * static int update_submodule(struct update_data *update_data) { + int ret = 1; + ensure_core_worktree(update_data->sm_path); update_data->displaypath = get_submodule_displaypath( @@ -2581,14 +2583,14 @@ static int update_submodule(struct update_data *update_data) free(remote_ref); } - if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force) + if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force) { if (run_update_procedure(update_data)) - return 1; + goto cleanup; + } if (update_data->recursive) { struct child_process cp = CHILD_PROCESS_INIT; struct update_data next = *update_data; - int ret; next.prefix = NULL; oidcpy(&next.oid, null_oid()); @@ -2602,16 +2604,20 @@ static int update_submodule(struct update_data *update_data) /* die() if child process die()'d */ ret = run_command(&cp); if (!ret) - return 0; + goto cleanup; die_message(_("Failed to recurse into submodule path '%s'"), update_data->displaypath); - if (ret == 128) + if (ret == 128) { exit(ret); - else if (ret) - return 1; + } else if (ret) { + ret = 1; + goto cleanup; + } } - return 0; + ret = 0; +cleanup: + return ret; } static int update_submodules(struct update_data *update_data) From patchwork Thu Jul 21 19:13:19 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: 12925718 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 4415DC433EF for ; Thu, 21 Jul 2022 19:15:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233697AbiGUTPO (ORCPT ); Thu, 21 Jul 2022 15:15:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233492AbiGUTOa (ORCPT ); Thu, 21 Jul 2022 15:14:30 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81FE78E4E8 for ; Thu, 21 Jul 2022 12:14:22 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id c22so1580310wmr.2 for ; Thu, 21 Jul 2022 12:14:22 -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=y0p78tp0cQ1nimRWu78Wr+IAzeR2L++QSAxatdTTwpc=; b=P8D6oangFH7cbsDNwDjbKyTBYjiciUWQlkCxn3eYwinsoP36VUF+rkbsLv6CXTHHr+ EP9BL8PD8EGigfiIVUfx34L2xCecCvJ8di2kJMqKHxq/S/fWBK09XHA+dqJ/Cc04hM/w 1/oUry9hM1v59dTsV9UavufgUaO6dIaMOvEmGPQS2dvJk95RPmkWjxpaTBAIOwiSBLF2 CjPuLtokc2LOQqK8wn/svUDUSS4PVq217++7Gdkr/ItwDpEYTxVYYNs/Xb363mNdcRq8 kRfJF9O9Vib1k7r0pSg9FJEWlrfKTIucpFYoIbeEYeTQpEXEOs++EHoHj7k+upbzFbzv BXhw== 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=y0p78tp0cQ1nimRWu78Wr+IAzeR2L++QSAxatdTTwpc=; b=WstDB3x1rO5SRiaBYPp/SnCPzBhXx1aSnz4JTJKw0ROy9wqBFqmuo5wMFSDxA32leN RSx3oGl5D4RwcPrV293hm1OISCspnJ2Y/0SasoIhowrBYiWwEcTBYcDEOkonzJ8tOhbD tNqj0GSEarsqripQ+cTNuHagh5JMWzudUGt2+8GNMnLC/aB0S2VOY52k7kcFUT8WYOsu wnusyR0VI8htQEFQDDEgvkbvBKxr0rkLMxprxIL3jj9qPsv3C6fc/6wqtY3r8IMPBDVU gH9eCbfiO9DlV7Toi4wTsNcYzYBONMnTeRbLXNyPCJkcDmmvUUjteo313gfeVOukiueF WQRw== X-Gm-Message-State: AJIora8jzlxPglrBInY19+Rk5RxLmE9BtoY8rd88HWf6zON0Rl+FAyAP Zj62MtPAIKsOJxrAsTY5u0lJu3ZeHpcAQw== X-Google-Smtp-Source: AGRyM1t7CmGLjnIoWcKBZnKj4l9QgZQPypMZlku8zJWAGFUTlAurBuuBXYh4rL+IUdheE2SRHnh6JA== X-Received: by 2002:a1c:f719:0:b0:3a3:15d4:5752 with SMTP id v25-20020a1cf719000000b003a315d45752mr9780684wmh.194.1658430860746; Thu, 21 Jul 2022 12:14:20 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h13-20020a05600016cd00b0021e4e9f6450sm2630637wrf.84.2022.07.21.12.14.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 12:14:20 -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 v3 23/26] submodule--helper: don't exit() on failure, return Date: Thu, 21 Jul 2022 21:13:19 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1095.g0bd6f54ba8a In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change code downstream of module_update() to short-circuit and return to the top-level on failure, rather than calling exit(). To do so we need to diligently check whether we "must_die_on_failure", which is a pattern started in c51f8f94e5b (submodule--helper: run update procedures from C, 2021-08-24), but which hadn't been completed to the point where we could avoid calling exit() here. This introduces no functional changes, but makes it easier to both call these routines as a library in the future, and to avoid leaking memory. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 790f0ccb82e..b65665105e7 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2283,7 +2283,8 @@ static int fetch_in_submodule(const char *module_path, int depth, int quiet, str return run_command(&cp); } -static int run_update_command(struct update_data *ud, int subforce) +static int run_update_command(struct update_data *ud, int subforce, + int *must_die_on_failurep) { struct child_process cp = CHILD_PROCESS_INIT; char *oid = oid_to_hex(&ud->oid); @@ -2345,8 +2346,10 @@ static int run_update_command(struct update_data *ud, int subforce) BUG("unexpected update strategy type: %s", submodule_strategy_to_string(&ud->update_strategy)); } - if (must_die_on_failure) - exit(128); + if (must_die_on_failure) { + *must_die_on_failurep = 1; + return 128; + } /* the command failed, but update must continue */ return 1; @@ -2380,7 +2383,8 @@ static int run_update_command(struct update_data *ud, int subforce) return 0; } -static int run_update_procedure(struct update_data *ud) +static int run_update_procedure(struct update_data *ud, + int *must_die_on_failure) { int subforce = is_null_oid(&ud->suboid) || ud->force; @@ -2407,7 +2411,7 @@ static int run_update_procedure(struct update_data *ud) ud->displaypath, oid_to_hex(&ud->oid)); } - return run_update_command(ud, subforce); + return run_update_command(ud, subforce, must_die_on_failure); } static const char *remote_submodule_branch(const char *path) @@ -2543,7 +2547,8 @@ static void update_data_to_args(struct update_data *update_data, struct strvec * "--no-single-branch"); } -static int update_submodule(struct update_data *update_data) +static int update_submodule(struct update_data *update_data, + int *must_die_on_failure) { int ret = 1; @@ -2584,8 +2589,13 @@ static int update_submodule(struct update_data *update_data) } if (!oideq(&update_data->oid, &update_data->suboid) || update_data->force) { - if (run_update_procedure(update_data)) + ret = run_update_procedure(update_data, must_die_on_failure); + if (ret && *must_die_on_failure) { + goto cleanup; + } else if (ret) { + ret = 1; goto cleanup; + } } if (update_data->recursive) { @@ -2608,7 +2618,8 @@ static int update_submodule(struct update_data *update_data) die_message(_("Failed to recurse into submodule path '%s'"), update_data->displaypath); if (ret == 128) { - exit(ret); + *must_die_on_failure = 1; + goto cleanup; } else if (ret) { ret = 1; goto cleanup; @@ -2646,13 +2657,18 @@ static int update_submodules(struct update_data *update_data) for (i = 0; i < suc.update_clone_nr; i++) { struct update_clone_data ucd = suc.update_clone[i]; + int code; + int must_die_on_failure = 0; oidcpy(&update_data->oid, &ucd.oid); update_data->just_cloned = ucd.just_cloned; update_data->sm_path = ucd.sub->path; - if (update_submodule(update_data)) - res = 1; + code = update_submodule(update_data, &must_die_on_failure); + if (code) + res = code; + if (must_die_on_failure) + goto cleanup; } cleanup: From patchwork Thu Jul 21 19:13:20 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: 12925719 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 DD778C43334 for ; Thu, 21 Jul 2022 19:15:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232880AbiGUTPP (ORCPT ); Thu, 21 Jul 2022 15:15:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233501AbiGUTOl (ORCPT ); Thu, 21 Jul 2022 15:14:41 -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 B2F838E4F2 for ; Thu, 21 Jul 2022 12:14:23 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id ay11-20020a05600c1e0b00b003a3013da120so3900647wmb.5 for ; Thu, 21 Jul 2022 12:14:23 -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=2MN89kynP+OI7l+sbC7jW/yKXu8GTXx757i9WAu1IM0=; b=qkf/lGD8FuhoLZyCjhI/y6xx8+l1G9t9QZF/0swjXyQic6U6ajOFRubbQ5erwPX4zo 71COtqkqnOZRyTibvDVb5Q47ruUgL5RzLR9aaGpjcijE5iOsT9gEvx7MdEAEeEZPIZXT GoWSvsnvJcMvpNs+mRaLjpZEui6hht2prebOJsNw3znMnBpNex0vNkR3C53tJ0VzSEkL mJ51kPenMQzOfMg8PTq+YMLBSUPhkpfBurrjuF0e//XT0htch1NEgaE4mKhIK0LCGBNh Iqxi9NhzEm/z5U49a7PxZ3hV6UQs+N1A7cXhd2pHXqrKOUT9UjIqyQwrsOG5Ul4fI5oT wWgw== 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=2MN89kynP+OI7l+sbC7jW/yKXu8GTXx757i9WAu1IM0=; b=gqxHXsLcwV/rw46bE7sUR3iV9xFtQUmtXh4Pa+DFTb4CODTjftBfjd2B7BXRmfsu49 Kt/maancixM6qXrYcel1NK8LVyeukC2bZvCn1ssxSbVK1cVfZvPcCZ0Xni+Qy0uErQhJ 28GrSF3ox42TnzNs2+rNEgWifgb8Y8wSTTOrux7weTdgpZ/Qg3gnsvtVGksjW+gkKPDz mBGXRo8PhXGyvpMezOCyg0/6x8eellOjDqv2u0Kcj1Z1jCC0pVqNdbSzT1P/5fIXh063 ZZa0qqZt7JrANbAoXhEcBq710ahRKNNvbB6h/7TzosJz+atgUJ378QK4dJTxuLLPKEQk ieFA== X-Gm-Message-State: AJIora/e3Hushb2wxv+eR174bCuFcjCpp0KnXuCpZr2sNqWZ0WFywJRO I1Iz1gxdv9kut/E6oi6a2ys6cEimUZAg6w== X-Google-Smtp-Source: AGRyM1vpYK+7Fchk97TzasMRKXWSjao234Ypu3PwbNPnrQpPhbVehgUahSXQuvyzNUamYe2CMB341A== X-Received: by 2002:a05:600c:3510:b0:3a3:34e7:cff5 with SMTP id h16-20020a05600c351000b003a334e7cff5mr2770483wmq.191.1658430862895; Thu, 21 Jul 2022 12:14:22 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h13-20020a05600016cd00b0021e4e9f6450sm2630637wrf.84.2022.07.21.12.14.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 12:14:21 -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 v3 24/26] submodule--helper: free rest of "displaypath" in "struct update_data" Date: Thu, 21 Jul 2022 21:13:20 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1095.g0bd6f54ba8a In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a leak in code added in c51f8f94e5b (submodule--helper: run update procedures from C, 2021-08-24), we clobber the "displaypath" member of the passed-in "struct update_data" both so that die() messages in this update_submodule() function itself can use it, and for the run_update_procedure() called within this function. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index b65665105e7..4e70a74357c 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -2551,10 +2551,11 @@ static int update_submodule(struct update_data *update_data, int *must_die_on_failure) { int ret = 1; + char *to_free, *restore = update_data->displaypath; ensure_core_worktree(update_data->sm_path); - update_data->displaypath = get_submodule_displaypath( + update_data->displaypath = to_free = get_submodule_displaypath( update_data->sm_path, update_data->prefix); determine_submodule_update_strategy(the_repository, update_data->just_cloned, @@ -2628,6 +2629,9 @@ static int update_submodule(struct update_data *update_data, ret = 0; cleanup: + free(to_free); + update_data->displaypath = restore; + return ret; } From patchwork Thu Jul 21 19:13:21 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: 12925720 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 D092CC433EF for ; Thu, 21 Jul 2022 19:15:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233365AbiGUTP1 (ORCPT ); Thu, 21 Jul 2022 15:15:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233548AbiGUTOt (ORCPT ); Thu, 21 Jul 2022 15:14:49 -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 EC1898E6C6 for ; Thu, 21 Jul 2022 12:14:26 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id bk26so3603174wrb.11 for ; Thu, 21 Jul 2022 12:14:26 -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=YSqePTZev0IASomKKnjjyMtKvYhqKAFObsgE+A1MjEY=; b=iB1hira8BijK8W7Lx8yr5tzy4weYB6EWk/e8if/r+fv1iJK74igdF0Tgy/JZfjNVjt ZknpAJCYoi1OotfJL4q+XnHcoIHj4LfLweecT5BoP7aDgLFipp9N5oPnSGimRzX0/J1D VGwuwTLjvrzOkgiMIUgCq2rSD6bo1BdhbSyW+HsUBqCgQJTvszonclVdx/dqgAsmf6io uzmDKfHOPjo3CPt/ibI2O9rMicHNlwoOzN4Wk4ZNBKL5YQ+iEE09tCF2CS2iyRB1wdm3 GNjYueeEq4+FwdnQvC3gHCxnpOkMZUvMqfr/+YWArlvYRF1meOHyq1UhJs2EdnCMZztI KdVw== 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=YSqePTZev0IASomKKnjjyMtKvYhqKAFObsgE+A1MjEY=; b=XuQArT6iT7FW+ClAZrGszsF4t1WcvUWsusDdZM1RJ/3xPTFokU0kpeKk7W5WkokBYj fY95egU2Jl05ANiksn8Uvs1EmUsVxHXI0l+NLkiEt4Q59w+fhXj+6JQhbmsQjTXg5hpm 3REyQl3aGbY/FFnX92zXryDe4KvqqoV8LO7I5tb7ZJ7VGznK3Zed02xyWY3ujrHYYbi4 hzQxkwGLs35he7kAgcFX0wgo8QJWUz71XPaDMCxaka4FwqmitIUAtylU/NIhEu9Q3MBV o/yAgb01vn5nZVgPbj+vBJawwW50QcM9gWiQhPN2Q+IndtZ2IOYu9HscY+1anB/cmEwb KwNw== X-Gm-Message-State: AJIora/+UtqTiMYxGOKFJdQtyT6zW8DJla056Ck6bqjzSJonMDM4/uXo 7hWlZQ8bzibT6zaMD72D3BPB/FWl4+uAiQ== X-Google-Smtp-Source: AGRyM1vrZGtH/JQKXrgweck/Gd/eWvq6TVygoN5FADyYC8C8QRCWoRpmXBRG8+xVi/FPeo9h8Gqqng== X-Received: by 2002:a5d:6489:0:b0:21d:a9a1:3511 with SMTP id o9-20020a5d6489000000b0021da9a13511mr34777177wri.626.1658430864882; Thu, 21 Jul 2022 12:14:24 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h13-20020a05600016cd00b0021e4e9f6450sm2630637wrf.84.2022.07.21.12.14.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 12:14:23 -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 v3 25/26] submodule--helper: fix bad config API usage Date: Thu, 21 Jul 2022 21:13:21 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1095.g0bd6f54ba8a In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix bad config API usage added in a452128a36c (submodule--helper: introduce add-config subcommand, 2021-08-06). After git_config_get_string() returns successfully we know the "char **dest" will be non-NULL. A coccinelle patch that transforms this turns up a couple of other such issues, one in fetch-pack.c, and another in upload-pack.c: @@ identifier F =~ "^(repo|git)_config_get_string(_tmp)?$"; identifier V; @@ !F(..., &V) - && (V) But let's focus narrowly on submodule--helper for now, we can fix those some other time. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 4e70a74357c..37c145b3ede 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -3306,7 +3306,7 @@ static void configure_added_submodule(struct add_data *add_data) * is_submodule_active(), since that function needs to find * out the value of "submodule.active" again anyway. */ - if (!git_config_get_string("submodule.active", &val) && val) { + if (!git_config_get_string("submodule.active", &val)) { /* * If the submodule being added isn't already covered by the * current configured pathspec, set the submodule's active flag From patchwork Thu Jul 21 19:13:22 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: 12925721 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 BD8E8C43334 for ; Thu, 21 Jul 2022 19:15:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229719AbiGUTP3 (ORCPT ); Thu, 21 Jul 2022 15:15:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233560AbiGUTOu (ORCPT ); Thu, 21 Jul 2022 15:14:50 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E557D8D5F7 for ; Thu, 21 Jul 2022 12:14:28 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id h206-20020a1c21d7000000b003a2fa488efdso1329875wmh.4 for ; Thu, 21 Jul 2022 12:14: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=0qX+2Kje057Xg7xHBIA7J9T8jY8Egoygt24/m7iQF0w=; b=g7iH/unb2C7oILssr3FgDdVVObWQjKOrUUBg+JBl6Fu5de7Nbyg3wRL+DdqsTpap2U 4O6GsNT6JKKuTxeKjSgBSVmSeLEyN3Yq8BIO5VDWxPe1b6afEnI4fcaPZ91viy20681/ sLwC3dvseB9FOW/zwhny7rdGhhyuvpXxD8/KuoHQcjmxen6QuJ1AYUPLuhTM1IUHoILO PI3q8kB+GIP7GtAwqd0rQMSZkBsKPnBzu7o8BN371Bj2ld3adeYpPXkzF9e8lb0mkjzG wWinRcQOW/VSI2Eajk4rxbsJhFC3bCMilzASwULzQkE4K/r+dhJ8bkaubCNtRsE2acYc dl/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=0qX+2Kje057Xg7xHBIA7J9T8jY8Egoygt24/m7iQF0w=; b=zyDpGlQnzxam1RjyY07H9k5wXJNDQTGLW9YpTK0ffYHaqEUEtQjLH2c3fJfAvrdN2a Ry/M1eR4z+C2FNXSE1ZuIhs0NkMg8GT6ZoAhs07cWCHp71yCNxjJ6MZlNmrdYkQlekY6 VOvIkxQsKjm+s0L6pOZNWarHgnRqxPBkA1AcKhUgc+SLnVIa0qDPEjWNGQuT6pVTJUon lKKCTchzBsU2RUCGvsfQHE/Lb7Pm6Up1VuyslkE8jUnBEaiOvQyurLgty/HR/8IQP+8I PUnJalBpqXCILanJaqcSkrT+R3MPb5bf87wwTIki/IwtGQRXqUYwhA65RgaYi1YT2Omx MyBg== X-Gm-Message-State: AJIora8L/VG4VGNFolZ5wOXvPpAfT13W6tOoHPSnakd3aoKY9XpxUVu4 LzRqTXXP5qEJLCEDjI1crSDtm6XC1QlPDA== X-Google-Smtp-Source: AGRyM1u9tGTNYLh0uVmTt0P+8pAwAiWTmN18mPduwnO6epyKG6MjqKFF8ef5bXTacsh6Op6RjEuUHQ== X-Received: by 2002:a05:600c:2116:b0:3a3:7f:f3cc with SMTP id u22-20020a05600c211600b003a3007ff3ccmr9638095wml.28.1658430867189; Thu, 21 Jul 2022 12:14:27 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id h13-20020a05600016cd00b0021e4e9f6450sm2630637wrf.84.2022.07.21.12.14.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 12:14: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 v3 26/26] submodule--helper: fix a configure_added_submodule() leak Date: Thu, 21 Jul 2022 21:13:22 +0200 Message-Id: X-Mailer: git-send-email 2.37.1.1095.g0bd6f54ba8a In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix config API a memory leak added in a452128a36c (submodule--helper: introduce add-config subcommand, 2021-08-06) by using the *_tmp() variant of git_config_get_string(). In this case we're only checking whether the (repo|git)_config_get_string() call is telling us that the "submodule.active" key exists. As with the preceding commit we'll find many other such patterns in the codebase if we go fishing. E.g. "git gc" leaks in the code added in 61f7a383d3b (maintenance: use 'incremental' strategy by default, 2020-10-15). Similar code in "git gc" added in b08ff1fee00 (maintenance: add --schedule option and config, 2020-09-11) doesn't leak, but we could avoid the malloc() & free() in that case. A coccinelle rule to find those would find and fix some leaks, and cases where we're doing needless malloc() + free()'s but only care about the key existence, or are copying the (repo|git)_config_get_string() return value right away. But as with the preceding commit let's punt on all of that for now, and just narrowly fix this specific case in submodule--helper. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/submodule--helper.c | 4 ++-- t/t7413-submodule-is-active.sh | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 37c145b3ede..fdf96c5d424 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -3261,7 +3261,7 @@ static int config_submodule_in_gitmodules(const char *name, const char *var, con static void configure_added_submodule(struct add_data *add_data) { char *key; - char *val = NULL; + const char *val; struct child_process add_submod = CHILD_PROCESS_INIT; struct child_process add_gitmodules = CHILD_PROCESS_INIT; @@ -3306,7 +3306,7 @@ static void configure_added_submodule(struct add_data *add_data) * is_submodule_active(), since that function needs to find * out the value of "submodule.active" again anyway. */ - if (!git_config_get_string("submodule.active", &val)) { + if (!git_config_get_string_tmp("submodule.active", &val)) { /* * If the submodule being added isn't already covered by the * current configured pathspec, set the submodule's active flag diff --git a/t/t7413-submodule-is-active.sh b/t/t7413-submodule-is-active.sh index c8e7e983317..c4c1f86f3d2 100755 --- a/t/t7413-submodule-is-active.sh +++ b/t/t7413-submodule-is-active.sh @@ -6,6 +6,7 @@ This test verifies that `git submodue--helper is-active` correctly identifies submodules which are "active" and interesting to the user. ' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' '