From patchwork Thu Dec 15 09:11: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: 13073990 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 61645C4332F for ; Thu, 15 Dec 2022 09:11:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229847AbiLOJL2 (ORCPT ); Thu, 15 Dec 2022 04:11:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229836AbiLOJLW (ORCPT ); Thu, 15 Dec 2022 04:11:22 -0500 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 C92222AE2F for ; Thu, 15 Dec 2022 01:11:20 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id w15so2329979wrl.9 for ; Thu, 15 Dec 2022 01:11:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YEM3FoOczQjc+wy/BvQDfEildMyd0yaFHUJLtP1qUis=; b=YKjPZ3vu2jxo+X5LlRljwZbAzK2CCBNf//GWOyy86rV+r5ViDtStLO9R+09PRgVSd/ nllCMI+aalXlC0Rk0W2sCtKv3mDEo4tMuBXLv6PrP7aNs5+dlAjJZx6htVXIPToqTPPX /+mvlzBJRfRB06L8c59QqDIMlDn5qbBljYA6a164li73Hij5GZ4Qq6fUfTvzRcId0HDM 0UV9TE/POeHaFu31+lzYyTBVijsMToLFfx8pCwT1Ei5qVSiZsYFthsX3ERp1bIa0ZT9M BSbPd9XJ2n4o+Mwv/kBpbEaHzLnMhnyymGVwEC+u94RW67rjc/7ud2POdf/R3EPrzFTS kMdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YEM3FoOczQjc+wy/BvQDfEildMyd0yaFHUJLtP1qUis=; b=yaByu43wZ3aANXzMD1ek5pVS2sC7Q0wMPKzkmiXqEeFJb3cNRjBMxFpAjAfLSmqDv5 4IcI8cAwIiZzEid2Qbe3WY4y9isO38X1DYok/OgO4wcaeQXdTZn62lXquW1J3KeZLiA2 iEFCbM1+Tr/BEnL4osDd+e0pmbF7k8eSSduS7igCI+Da8K+ajoXFQ+AWgKK071k4v8Tl HFZY6wLff954Q+z58ipLblO9jbT87sKzeO8/x9e/quqUR3MOJvIttNfRVLr0uscixojr yEhN8aAIkGas73Yv5bQeHVTlauCaeyfky/2aCQgL+o2MwcH41AWTRp4ERZiXcPJRT9Rl ZUrQ== X-Gm-Message-State: ANoB5pkTiKtSpFTNSDu+OUxcr4861yH4+z8GAw3Ja0AivRHIEwOruwB2 sFH6BG8veguJDnsDBjha0FQOCvekzY7vqg== X-Google-Smtp-Source: AA0mqf7jIwpL6Sjan0dvZXf9b+0/LFuBPC4lmJiAaNLj72q4SjdYzeGbu5SGc8G9g9xdXiwZOFeZ4w== X-Received: by 2002:a5d:4745:0:b0:242:2fa:fa49 with SMTP id o5-20020a5d4745000000b0024202fafa49mr17786885wrs.18.1671095478919; Thu, 15 Dec 2022 01:11:18 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id m7-20020a056000024700b002366f9bd717sm6193835wrz.45.2022.12.15.01.11.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 01:11:18 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [RFC PATCH 1/5] builtin/annotate.c: simplify for strvec API Date: Thu, 15 Dec 2022 10:11:07 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b In-Reply-To: References: <221214.86ilie48cv.gmgdl@evledraar.gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When this code was migrated to "struct strvec" (or rather, its predecessor API) in 8c2cfa55446 (annotate: use argv_array, 2014-07-16) it didn't take full advantage of what we were given: * We are always passed the name "annotate" as argv[0] here, so we don't need to re-hardcode it. We've already declared it in "struct cmd_struct commands" in git.c. * We are guaranteed to get at least one argument, so rather than looping here ourselves let's have strvec_pushv() handle that. If we only have one argument we'll pass the terminating NULL to it, making it a NOOP. This change helps to make the subsequent commit smaller, and as a bonus removes the type discrepancy between "int" and "size_t". Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/annotate.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/builtin/annotate.c b/builtin/annotate.c index 58ff977a231..e37b269196f 100644 --- a/builtin/annotate.c +++ b/builtin/annotate.c @@ -7,16 +7,12 @@ #include "builtin.h" #include "strvec.h" -int cmd_annotate(int argc, const char **argv, const char *prefix) +int cmd_annotate(int argc UNUSED, const char **argv, const char *prefix) { struct strvec args = STRVEC_INIT; - int i; - strvec_pushl(&args, "annotate", "-c", NULL); - - for (i = 1; i < argc; i++) { - strvec_push(&args, argv[i]); - } + strvec_pushl(&args, argv[0], "-c", NULL); + strvec_pushv(&args, &argv[1]); return cmd_blame(args.nr, args.v, prefix); } From patchwork Thu Dec 15 09:11: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: 13073989 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 8C3F1C4708D for ; Thu, 15 Dec 2022 09:11:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229841AbiLOJL0 (ORCPT ); Thu, 15 Dec 2022 04:11:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229835AbiLOJLW (ORCPT ); Thu, 15 Dec 2022 04:11:22 -0500 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 9BCE72A96B for ; Thu, 15 Dec 2022 01:11:20 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id h16so2311294wrz.12 for ; Thu, 15 Dec 2022 01:11:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rgabFXxI8mpq5+3P+Tb0jVqbo3Ptu9bBfUUaApTNQTQ=; b=DvfcKGgHgq0ZAzvm9aBQ6YhxEOYVO7EoCrP+NXpbQ/o7ad0zshG1kcBQZMu18HrtA2 3UMom3v//F+wJHs0dL2NklG71FUwePBMD4TL4yTl0MKyICIIcWATf3PZeMVBTWR74JN5 iqzY24TBfWD/PPJgS1VXGY3yB6qTlU+ccicv8Y7cxcYdGOYBnOt02zObr6VbMsHJ+Qiq esCrrcdSOrRCgYrYr9osmNe/0PYlFTjJ7LTewBiMwb0QsbJmASsoX495KRX+Cq5eKWz0 356upSEzztdrudnN/65N/pv+ogAo3WPPly/ctOrTj/neeLVg3wm3yRZpPkzzKuuYyIMW gT3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rgabFXxI8mpq5+3P+Tb0jVqbo3Ptu9bBfUUaApTNQTQ=; b=WxgdTpd7B+vKKf4e+CVfTAGulamqI2SgVRVWrsewEQOKrjZSQFDvsJDLIRSlBduAnn 2UbN3w0kFIyBBTGqJGByZpqAWo+5G1IpvberwOpev88bQrrVGTs9uqQfvOMt5PeihfR4 +sjVfNacTvP3Q+v81Z0iXBdQqq6rWkOuGp+uocfZT2wA84vIFkGCurEp41ZWHxGv7Ex7 qbmiCIrDzkKFj8llxhIHo0kV/yXbYlqmJgs0mXV+ifUFMs8puT29nW8WqAbbf46cxpwQ FKU0wM/s7/MI0j1VXqUdVd47RDWZsYtQES/mbF5B4zC+Hf+MtexPttT9qGid4XjHgtmb reIQ== X-Gm-Message-State: ANoB5pleeZW1ZxjT9i59geXj37524ZltxzDyREEx2EyqG1Q2PuzkwyLx EaUqZFEYfPdQsPT2py/V1bRgMR1brVts8A== X-Google-Smtp-Source: AA0mqf7IwESjgR94p3qmxwPOLWb++3eRS6imXMEk6sia8m+PWgf3t9ZDZE+2jXSlbkzbQvbI0Z/Bjg== X-Received: by 2002:a5d:404f:0:b0:242:7c7a:7ee7 with SMTP id w15-20020a5d404f000000b002427c7a7ee7mr17959181wrp.53.1671095479906; Thu, 15 Dec 2022 01:11:19 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id m7-20020a056000024700b002366f9bd717sm6193835wrz.45.2022.12.15.01.11.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 01:11:19 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [RFC PATCH 2/5] various: add missing strvec_clear() Date: Thu, 15 Dec 2022 10:11:08 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b In-Reply-To: References: <221214.86ilie48cv.gmgdl@evledraar.gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix or partially fix memory leaks that happened because a strvec_clear() was missing. The "partially" will be addressed in a subsequent commit, we'll still leak in cases where the function we're calling munges our "v" member. In the case of "builtin/describe.c" let's change it to use the macro initializer rather than the strvec_init() while we're at it. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/annotate.c | 5 ++++- builtin/describe.c | 8 +++++--- builtin/stash.c | 6 +++++- builtin/upload-archive.c | 7 +++++-- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/builtin/annotate.c b/builtin/annotate.c index e37b269196f..de58deadfc7 100644 --- a/builtin/annotate.c +++ b/builtin/annotate.c @@ -10,9 +10,12 @@ int cmd_annotate(int argc UNUSED, const char **argv, const char *prefix) { struct strvec args = STRVEC_INIT; + int ret; strvec_pushl(&args, argv[0], "-c", NULL); strvec_pushv(&args, &argv[1]); - return cmd_blame(args.nr, args.v, prefix); + ret = cmd_blame(args.nr, args.v, prefix); + strvec_clear(&args); + return ret; } diff --git a/builtin/describe.c b/builtin/describe.c index eea1e330c00..cb205f6b561 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -597,9 +597,9 @@ int cmd_describe(int argc, const char **argv, const char *prefix) if (contains) { struct string_list_item *item; - struct strvec args; + struct strvec args = STRVEC_INIT; + int ret; - strvec_init(&args); strvec_pushl(&args, "name-rev", "--peel-tag", "--name-only", "--no-undefined", NULL); @@ -616,7 +616,9 @@ int cmd_describe(int argc, const char **argv, const char *prefix) strvec_pushv(&args, argv); else strvec_push(&args, "HEAD"); - return cmd_name_rev(args.nr, args.v, prefix); + ret = cmd_name_rev(args.nr, args.v, prefix); + strvec_clear(&args); + return ret; } hashmap_init(&names, commit_name_neq, NULL, 0); diff --git a/builtin/stash.c b/builtin/stash.c index bb0fd861434..e504e22e0b9 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -961,6 +961,7 @@ static int show_stash(int argc, const char **argv, const char *prefix) ret = diff_result_code(&rev.diffopt, 0); cleanup: strvec_clear(&stash_args); + strvec_clear(&revision_args); free_stash_info(&info); release_revisions(&rev); if (do_usage) @@ -1838,6 +1839,7 @@ int cmd_stash(int argc, const char **argv, const char *prefix) OPT_SUBCOMMAND_F("save", &fn, save_stash, PARSE_OPT_NOCOMPLETE), OPT_END() }; + int ret; git_config(git_stash_config, NULL); @@ -1861,5 +1863,7 @@ int cmd_stash(int argc, const char **argv, const char *prefix) /* Assume 'stash push' */ strvec_push(&args, "push"); strvec_pushv(&args, argv); - return !!push_stash(args.nr, args.v, prefix, 1); + ret = !!push_stash(args.nr, args.v, prefix, 1); + strvec_clear(&args); + return ret; } diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c index 945ee2b4126..6ef0d06ee8b 100644 --- a/builtin/upload-archive.c +++ b/builtin/upload-archive.c @@ -21,6 +21,7 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix) { struct strvec sent_argv = STRVEC_INIT; const char *arg_cmd = "argument "; + int ret; if (argc != 2 || !strcmp(argv[1], "-h")) usage(upload_archive_usage); @@ -45,8 +46,10 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix) } /* parse all options sent by the client */ - return write_archive(sent_argv.nr, sent_argv.v, prefix, - the_repository, NULL, 1); + ret = write_archive(sent_argv.nr, sent_argv.v, prefix, + the_repository, NULL, 1); + strvec_clear(&sent_argv); + return ret; } __attribute__((format (printf, 1, 2))) From patchwork Thu Dec 15 09:11: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: 13073991 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 2FB77C00145 for ; Thu, 15 Dec 2022 09:11:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229852AbiLOJL3 (ORCPT ); Thu, 15 Dec 2022 04:11:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229818AbiLOJLY (ORCPT ); Thu, 15 Dec 2022 04:11:24 -0500 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 9FC982AE03 for ; Thu, 15 Dec 2022 01:11:22 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id h10so2356282wrx.3 for ; Thu, 15 Dec 2022 01:11:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2ZTFFb1dffd99B1a97mLIYawUwX7lmGi5sVbF0X8A6o=; b=HW1rF1YS1l0alakwKYidK4rduCMu90mht43GAE+LZydkqXJQBcGcqd2Fd8wc2DAXex 7+PcxysUSo8LiVeXRH+DAoEarG6nOIQ6Blokay9XsseFFb+WnNpKpCvPML/WkI/qTatI B1Q8UJwWHH/XnDRsTj3XTAuNT7zP456GCF1vdSAv+a9ItR0/LU51fXNOd90hz/nS/OU1 O9JmOZeuAWUvmT5CgWIRjWO3FM7xolyXwy0C/HljHDVQVfgg6G0STPJGKBbwYChXW36t N8xkDZ/CHHwglsBWxVD3k1csO7PLaskOdkv5XVZxmj7kKlXLwjLNKQSMfy/Qfj4mrpdU uChw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2ZTFFb1dffd99B1a97mLIYawUwX7lmGi5sVbF0X8A6o=; b=wD5Pc5Z4A4ex72hwYKEvigXqmhBmZOLIIbhQthQXzy8gWHpowZp2Inf4Vz+/f9Ckn2 m4hZWkUf61f10ntevH+OwlmHyTE/TheonMtM6h2BhW9OM6EHj/RhmKxUGWxnw3C+LMS/ dtKqxTVdn0+tFAVKP5PO+czDGcjR0a76Q9hi5RDSbGXdMC6+VWoRUKrpIZlSln8ivm7o gz2/HKOrryr4KdUDf0e+5jPpgTG/yUndLCTh/wsa64luC2PAX0KyocVd3FpUdPDHPjth toLci+uPSMPOOA3W9I3GYuVkb9QTJozsfTAfVq+QSLJoC/NfnkGrx09TUetDVsZoZk8x m9yQ== X-Gm-Message-State: ANoB5pkErZLR88Pp4Xka8v10vXP6ge/tZ3IWCbLqxjaMnhCEJkpHARsm SXO6wM34R/kLToinvgH7cXcUARCoSYGcDw== X-Google-Smtp-Source: AA0mqf7FfkavqQtZsK52RFnOl3/GXkis6lV4RsCx4JGVwvl47hhXT0ZHWvga/1w7q2HsCmOBriWmbw== X-Received: by 2002:a5d:4e03:0:b0:242:37e3:1747 with SMTP id p3-20020a5d4e03000000b0024237e31747mr16335820wrt.21.1671095480792; Thu, 15 Dec 2022 01:11:20 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id m7-20020a056000024700b002366f9bd717sm6193835wrz.45.2022.12.15.01.11.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 01:11:20 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [RFC PATCH 3/5] strvec API: add a "STRVEC_INIT_NODUP" Date: Thu, 15 Dec 2022 10:11:09 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b In-Reply-To: References: <221214.86ilie48cv.gmgdl@evledraar.gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We have various tricky cases where we'll leak a "struct strvec" even when we call strvec_clear(), these happen because we'll call setup_revisions(), parse_options() etc., which will munge our "v" member. There's various potential ways to deal with that, see the extensive on-list discussion at [1]. One way would be to pass a flag to ask the underlying API to free() these, as was done for setup_revisions() in [2]. But we don't need that complexity for many common cases, which are pushing fixed strings to the "struct strvec". Let's instead add a flag analogous to the "strdup_strings" flag in the "struct string_list". A subsequent commit will make use of this API. Implementation notes: The BUG_unless_dup() is implemented as a macro so we'll report the correct line number on BUG(). The "nodup_strings" flag could have been named a "strdup_strings" for consistency with the "struct string_list" API, but to do so we'd have to be confident that we've spotted all callers that assume that they can memset() a "struct strvec" to zero. 1. https://lore.kernel.org/git/221214.86ilie48cv.gmgdl@evledraar.gmail.com/ 2. f92dbdbc6a8 (revisions API: don't leak memory on argv elements that need free()-ing, 2022-08-02) Signed-off-by: Ævar Arnfjörð Bjarmason --- strvec.c | 20 ++++++++++++++++++-- strvec.h | 30 +++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/strvec.c b/strvec.c index 61a76ce6cb9..721f8e94a50 100644 --- a/strvec.c +++ b/strvec.c @@ -10,6 +10,16 @@ void strvec_init(struct strvec *array) memcpy(array, &blank, sizeof(*array)); } +void strvec_init_nodup(struct strvec *array) +{ + struct strvec blank = STRVEC_INIT_NODUP; + memcpy(array, &blank, sizeof(*array)); +} + +#define BUG_unless_dup(array, fn) \ + if ((array)->nodup_strings) \ + BUG("cannot %s() on a 'STRVEC_INIT_NODUP' strvec", (fn)) + static void strvec_push_nodup(struct strvec *array, const char *value) { if (array->v == empty_strvec) @@ -22,7 +32,9 @@ static void strvec_push_nodup(struct strvec *array, const char *value) const char *strvec_push(struct strvec *array, const char *value) { - strvec_push_nodup(array, xstrdup(value)); + const char *to_push = array->nodup_strings ? value : xstrdup(value); + + strvec_push_nodup(array, to_push); return array->v[array->nr - 1]; } @@ -31,6 +43,8 @@ const char *strvec_pushf(struct strvec *array, const char *fmt, ...) va_list ap; struct strbuf v = STRBUF_INIT; + BUG_unless_dup(array, "strvec_pushf"); + va_start(ap, fmt); strbuf_vaddf(&v, fmt, ap); va_end(ap); @@ -67,6 +81,8 @@ void strvec_pop(struct strvec *array) void strvec_split(struct strvec *array, const char *to_split) { + BUG_unless_dup(array, "strvec_pushf"); + while (isspace(*to_split)) to_split++; for (;;) { @@ -89,7 +105,7 @@ void strvec_clear(struct strvec *array) { if (array->v != empty_strvec) { int i; - for (i = 0; i < array->nr; i++) + for (i = 0; !array->nodup_strings && i < array->nr; i++) free((char *)array->v[i]); free(array->v); } diff --git a/strvec.h b/strvec.h index 9f55c8766ba..b122b87b369 100644 --- a/strvec.h +++ b/strvec.h @@ -26,29 +26,51 @@ extern const char *empty_strvec[]; * member contains the actual array; the `nr` member contains the * number of elements in the array, not including the terminating * NULL. + * + * When using `STRVEC_INIT_NODUP` to initialize it the `nodup_strings' + * member is set, and individual members of the "struct strvec" will + * not be free()'d by strvec_clear(). This is for fixed string + * arguments to parse_options() and others that might munge the "v" + * itself. */ struct strvec { const char **v; size_t nr; size_t alloc; + unsigned int nodup_strings:1; }; #define STRVEC_INIT { \ .v = empty_strvec, \ } +#define STRVEC_INIT_NODUP { \ + .v = empty_strvec, \ + .nodup_strings = 1, \ +} + /** * Initialize an array. This is no different than assigning from * `STRVEC_INIT`. */ void strvec_init(struct strvec *); +/** + * Initialize a "nodup" array. This is no different than assigning from + * `STRVEC_INIT_NODUP`. + */ +void strvec_init_nodup(struct strvec *); + /* Push a copy of a string onto the end of the array. */ const char *strvec_push(struct strvec *, const char *); /** * Format a string and push it onto the end of the array. This is a * convenience wrapper combining `strbuf_addf` and `strvec_push`. + * + * This is incompatible with arrays initialized with + * `STRVEC_INIT_NODUP`, as pushing the formatted string requires the + * equivalent of an xstrfmt(). */ __attribute__((format (printf,2,3))) const char *strvec_pushf(struct strvec *, const char *fmt, ...); @@ -70,7 +92,13 @@ void strvec_pushv(struct strvec *, const char **); */ void strvec_pop(struct strvec *); -/* Splits by whitespace; does not handle quoted arguments! */ +/** + * Splits by whitespace; does not handle quoted arguments! + * + * This is incompatible with arrays initialized with + * `STRVEC_INIT_NODUP`, as pushing the elements requires an xstrndup() + * call. + */ void strvec_split(struct strvec *, const char *); /** From patchwork Thu Dec 15 09:11: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: 13073993 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 05FA9C4332F for ; Thu, 15 Dec 2022 09:11:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229543AbiLOJLg (ORCPT ); Thu, 15 Dec 2022 04:11:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229832AbiLOJLZ (ORCPT ); Thu, 15 Dec 2022 04:11:25 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8667E2AE26 for ; Thu, 15 Dec 2022 01:11:23 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id i7so2335761wrv.8 for ; Thu, 15 Dec 2022 01:11:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tc/AVdeBNo/O4MFtSmnlLl/fOt0AG45CEfP9RBQJuJ4=; b=lOR70rqyFe9anwDRhg/xsb2Jc9JjFUbjwEMOkhRN8C6LczbKY57j0f+GLBJ2nAzckl mWBetnNrTXLXReQ3EwZeU4Is3wVlH/1S0HupLsBnHeiDboujCVlPvoYhGQlSude0v1Qi W2NSnbn9VaVg8NJsl5VaVAdTywLHxONGUTqJF1VgWcAuf0EyL+4Zezsm44YFiGXaAHyi Fo3YaOlx1LCOfb+/EhqxJb0dG1yd8vxhS0LgFbpdTl5RwRmAThnwsiVcRjQaevjk/++e aHid0n7V/788BltXxpD+uGYxsVMBlqxG/giNpQii6eLHGFzOCWJ1tQf4WeEvb6/DGCLC R8Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tc/AVdeBNo/O4MFtSmnlLl/fOt0AG45CEfP9RBQJuJ4=; b=QfSNtOk3VQSTJOtYvcaV0VoLvXmzFkwW02CwngukDPyg7eBHrNzdmuCtcZVDZc4Ups YR7Dwj7vOtqqZNq2nkSQhgEVjAXCGhYdAZkzYbY7Eqt+MYvBRT3bh+x0XAkk6WWUtHHI aQQrI5buOMDYAl1jaUbdlgYJ/epNmTYABFfkzoohs69O8q0rH4osNiUHUh5gORTVWRIU YrqK/ks2X58YnkbDJyDtdXvfkrUxAd8x5S5c59FwcrI4/o6BKwLLH6FUEQS4lSxzpbby 1OOQCUsfAcyT4PXiTbNdQwW1WHEftwwTXUJvFlW8UbxK/mrDerEWeJxInRRdhZUz6nji kzog== X-Gm-Message-State: ANoB5plMZwIrFU3WRDrvJL2eI9iJZoDcOIOsno2UEYNTFMePMR7ONs3Y 4iCVf1vpM91yJ8nIFNg/fjXqcPguzikTow== X-Google-Smtp-Source: AA0mqf7oJjm23vgmY9agPhCf0WDTGpO3gb/r6I0U1CeBl+ECLH+K4ncxE1LvuGJHN1dNqeESj070mQ== X-Received: by 2002:adf:f212:0:b0:242:192c:9b34 with SMTP id p18-20020adff212000000b00242192c9b34mr17161209wro.59.1671095481736; Thu, 15 Dec 2022 01:11:21 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id m7-20020a056000024700b002366f9bd717sm6193835wrz.45.2022.12.15.01.11.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 01:11:20 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [RFC PATCH 4/5] strvec API users: fix leaks by using "STRVEC_INIT_NODUP" Date: Thu, 15 Dec 2022 10:11:10 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b In-Reply-To: References: <221214.86ilie48cv.gmgdl@evledraar.gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org For these cases where all of the strings we're pushing to the "struct strvec" are fixed strings we can fix widespread memory leaks by skipping the xstrdup() on strvec_push(). More in-tree users could benefit from this to save needless xstrdup()-ing, but for all of these we were munging the "v" member, so the subsequent strvec_clear() wouldn't free the memory. Now there's no need to free the individual elements, but we'll still need to free the container with the strvec_clear(). Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/am.c | 2 +- builtin/annotate.c | 2 +- builtin/stash.c | 2 +- t/t0023-crlf-am.sh | 1 + t/t4152-am-subjects.sh | 2 ++ t/t4254-am-corrupt.sh | 2 ++ t/t4256-am-format-flowed.sh | 1 + t/t4257-am-interactive.sh | 2 ++ t/t5403-post-checkout-hook.sh | 1 + 9 files changed, 12 insertions(+), 3 deletions(-) diff --git a/builtin/am.c b/builtin/am.c index 30c9b3a9cd7..691ec1d152d 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1471,7 +1471,7 @@ static int parse_mail_rebase(struct am_state *state, const char *mail) static int run_apply(const struct am_state *state, const char *index_file) { struct strvec apply_paths = STRVEC_INIT; - struct strvec apply_opts = STRVEC_INIT; + struct strvec apply_opts = STRVEC_INIT_NODUP; struct apply_state apply_state; int res, opts_left; int force_apply = 0; diff --git a/builtin/annotate.c b/builtin/annotate.c index de58deadfc7..99d97c1a8c0 100644 --- a/builtin/annotate.c +++ b/builtin/annotate.c @@ -9,7 +9,7 @@ int cmd_annotate(int argc UNUSED, const char **argv, const char *prefix) { - struct strvec args = STRVEC_INIT; + struct strvec args = STRVEC_INIT_NODUP; int ret; strvec_pushl(&args, argv[0], "-c", NULL); diff --git a/builtin/stash.c b/builtin/stash.c index e504e22e0b9..b15dd2ebb3c 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -1823,7 +1823,7 @@ int cmd_stash(int argc, const char **argv, const char *prefix) { pid_t pid = getpid(); const char *index_file; - struct strvec args = STRVEC_INIT; + struct strvec args = STRVEC_INIT_NODUP; parse_opt_subcommand_fn *fn = NULL; struct option options[] = { OPT_SUBCOMMAND("apply", &fn, apply_stash), diff --git a/t/t0023-crlf-am.sh b/t/t0023-crlf-am.sh index f9bbb91f64e..575805513a3 100755 --- a/t/t0023-crlf-am.sh +++ b/t/t0023-crlf-am.sh @@ -2,6 +2,7 @@ test_description='Test am with auto.crlf' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh cat >patchfile <<\EOF diff --git a/t/t4152-am-subjects.sh b/t/t4152-am-subjects.sh index 4c68245acad..9f2edba1f83 100755 --- a/t/t4152-am-subjects.sh +++ b/t/t4152-am-subjects.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='test subject preservation with format-patch | am' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh make_patches() { diff --git a/t/t4254-am-corrupt.sh b/t/t4254-am-corrupt.sh index 54be7da1611..45f1d4f95e5 100755 --- a/t/t4254-am-corrupt.sh +++ b/t/t4254-am-corrupt.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='git am with corrupt input' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh make_mbox_with_nul () { diff --git a/t/t4256-am-format-flowed.sh b/t/t4256-am-format-flowed.sh index 2369c4e17ad..1015273bc82 100755 --- a/t/t4256-am-format-flowed.sh +++ b/t/t4256-am-format-flowed.sh @@ -2,6 +2,7 @@ test_description='test format=flowed support of git am' +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' diff --git a/t/t4257-am-interactive.sh b/t/t4257-am-interactive.sh index aed8f4de3d6..f26d7fd2dbd 100755 --- a/t/t4257-am-interactive.sh +++ b/t/t4257-am-interactive.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='am --interactive tests' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'set up patches to apply' ' diff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh index 978f240cdac..cfaae547398 100755 --- a/t/t5403-post-checkout-hook.sh +++ b/t/t5403-post-checkout-hook.sh @@ -7,6 +7,7 @@ test_description='Test the post-checkout hook.' 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 ' From patchwork Thu Dec 15 09:11: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: 13073992 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 593DCC4332F for ; Thu, 15 Dec 2022 09:11:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229610AbiLOJLc (ORCPT ); Thu, 15 Dec 2022 04:11:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229798AbiLOJLZ (ORCPT ); Thu, 15 Dec 2022 04:11:25 -0500 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 618302AE1E for ; Thu, 15 Dec 2022 01:11:23 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id h16so2311407wrz.12 for ; Thu, 15 Dec 2022 01:11:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zRyxpIWW+z3OydWyjnLV2szstKc/52/russrvwVr2S0=; b=ZzlqKc7GLMQNRaIUmJEa2QC9+kQXkqJoqTNVdog2rFnU57e1NNBuEovHjmT/Sp/FUY MVBrKM0ifCBmWfEJi0gjtC5jv9rAtN51olfvmE6k05vqmoPE7Hrs750rL8Ojju7bdAqT skCnQ9e1xLqRWKnubU9MNwV5E2l/QSW/etabOTaIchyzoJdMqeTRSgP+H0rfHufEt+6I 1Zl5KTC7MRTrB2RfbpJXxLGtiZUMtq1KUf4XuUVfKsFF35QXKGQFL2/aIUe1jAyKs1rR TdPf5FoH890XMA7YyEKiQa8EGq6j9MvC8rIs6q/C36Roynl6gSQETuKK/Q0jpSRqyqoJ WvtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zRyxpIWW+z3OydWyjnLV2szstKc/52/russrvwVr2S0=; b=B/2K/iMLoVE6l3BJD8oLZf3OwYf4BCV1KZvGLHKDhctNQB9OIALe2832uSNdfdEqvc vw3q+yOt/hMoFcaOineb3Wmkt9JUFpcB8SF3M8d9e1bDnTA/LOMRvYvGEtmhnMGvUbUJ uHYAzXA2g4n0VkK5rtaImAW4znG/7Qapn2PPVR332wpvCz8isHXpv34dgJdaaTUZGiLs VsO0OIYDwmNi6v4MvYpcLad5VVtaBfDwz9hA8512wGSox0RGBeTnYL3Nx+SkHHrViyj8 SCl+HXa2LaGjQYROKKqCk4x8P7ghnQDBU7+Tg5XOPWZ+dB4V5nnSFh+CZKUpX9cpmv+C t79g== X-Gm-Message-State: ANoB5plQS9W/+hmfrHljABS+z7tbmqHxTxXrk6B4buG/tMnqznVK+zhB URi7CtYFdjTvmLXZACUbameSChAN/sbjHw== X-Google-Smtp-Source: AA0mqf5aFL0sNolYSwfuQSjlo2E2hkFXCZkg2rBYFNyb8djGTQk+uSJO4zGSTWx+Gg9O/qAsklWPEA== X-Received: by 2002:a5d:4578:0:b0:242:7248:fbe with SMTP id a24-20020a5d4578000000b0024272480fbemr19145680wrc.25.1671095482645; Thu, 15 Dec 2022 01:11:22 -0800 (PST) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id m7-20020a056000024700b002366f9bd717sm6193835wrz.45.2022.12.15.01.11.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 01:11:21 -0800 (PST) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: =?utf-8?q?Ren=C3=A9_Scharfe?= , Junio C Hamano , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [RFC PATCH 5/5] strvec API users: fix more leaks by using "STRVEC_INIT_NODUP" Date: Thu, 15 Dec 2022 10:11:11 +0100 Message-Id: X-Mailer: git-send-email 2.39.0.rc2.1048.g0e5493b8d5b In-Reply-To: References: <221214.86ilie48cv.gmgdl@evledraar.gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org For these cases where most of the the strings we were pushing to the "struct strvec" were fixed strings, but others are dynamically allocated. For the latter we keep around a "to_free" list of them. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/describe.c | 22 +++++++++++++++++----- builtin/upload-archive.c | 9 +++++++-- t/t5003-archive-zip.sh | 1 + 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/builtin/describe.c b/builtin/describe.c index cb205f6b561..eda59ebb19a 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -596,8 +596,10 @@ int cmd_describe(int argc, const char **argv, const char *prefix) die(_("options '%s' and '%s' cannot be used together"), "--long", "--abbrev=0"); if (contains) { + struct string_list to_free = STRING_LIST_INIT_DUP; struct string_list_item *item; - struct strvec args = STRVEC_INIT; + struct strvec args = STRVEC_INIT_NODUP; + int ret; strvec_pushl(&args, "name-rev", @@ -607,10 +609,19 @@ int cmd_describe(int argc, const char **argv, const char *prefix) strvec_push(&args, "--always"); if (!all) { strvec_push(&args, "--tags"); - for_each_string_list_item(item, &patterns) - strvec_pushf(&args, "--refs=refs/tags/%s", item->string); - for_each_string_list_item(item, &exclude_patterns) - strvec_pushf(&args, "--exclude=refs/tags/%s", item->string); + for_each_string_list_item(item, &patterns) { + char *str = xstrfmt("--refs=refs/tags/%s", item->string); + const char *item = string_list_append_nodup(&to_free, str)->string; + + strvec_push(&args, item); + } + for_each_string_list_item(item, &exclude_patterns) { + char *str = xstrfmt("--exclude=refs/tags/%s", item->string); + + const char *item = string_list_append_nodup(&to_free, str)->string; + + strvec_push(&args, item); + } } if (argc) strvec_pushv(&args, argv); @@ -618,6 +629,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix) strvec_push(&args, "HEAD"); ret = cmd_name_rev(args.nr, args.v, prefix); strvec_clear(&args); + string_list_clear(&to_free, 0); return ret; } diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c index 6ef0d06ee8b..95c6cdc4be0 100644 --- a/builtin/upload-archive.c +++ b/builtin/upload-archive.c @@ -19,7 +19,8 @@ static const char deadchild[] = int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix) { - struct strvec sent_argv = STRVEC_INIT; + struct string_list to_free = STRING_LIST_INIT_DUP; + struct strvec sent_argv = STRVEC_INIT_NODUP; const char *arg_cmd = "argument "; int ret; @@ -34,6 +35,7 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix) /* put received options in sent_argv[] */ strvec_push(&sent_argv, "git-upload-archive"); for (;;) { + struct string_list_item *item; char *buf = packet_read_line(0, NULL); if (!buf) break; /* got a flush */ @@ -42,13 +44,16 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix) if (!starts_with(buf, arg_cmd)) die("'argument' token or flush expected"); - strvec_push(&sent_argv, buf + strlen(arg_cmd)); + + item = string_list_append(&to_free, buf + strlen(arg_cmd)); + strvec_push(&sent_argv, item->string); } /* parse all options sent by the client */ ret = write_archive(sent_argv.nr, sent_argv.v, prefix, the_repository, NULL, 1); strvec_clear(&sent_argv); + string_list_clear(&to_free, 0); return ret; } diff --git a/t/t5003-archive-zip.sh b/t/t5003-archive-zip.sh index fc499cdff01..cc1ce060558 100755 --- a/t/t5003-archive-zip.sh +++ b/t/t5003-archive-zip.sh @@ -2,6 +2,7 @@ test_description='git archive --format=zip test' +TEST_PASSES_SANITIZE_LEAK=true TEST_CREATE_REPO_NO_TEMPLATE=1 . ./test-lib.sh