From patchwork Wed Oct 3 15:36:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_=C3=85gren?= X-Patchwork-Id: 10625049 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9FF82112B for ; Wed, 3 Oct 2018 15:36:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DE6528E3B for ; Wed, 3 Oct 2018 15:36:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81F1728E3F; Wed, 3 Oct 2018 15:36:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3931828E3B for ; Wed, 3 Oct 2018 15:36:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726964AbeJCWZl (ORCPT ); Wed, 3 Oct 2018 18:25:41 -0400 Received: from mail-lf1-f66.google.com ([209.85.167.66]:46391 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726748AbeJCWZl (ORCPT ); Wed, 3 Oct 2018 18:25:41 -0400 Received: by mail-lf1-f66.google.com with SMTP id q2-v6so4458774lfc.13 for ; Wed, 03 Oct 2018 08:36:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fhWwyWt2lYelCmdazSYsoQ4sUh5+tGcY0PsW1zEh3yA=; b=Jf1Mkjv5ylyBOAzZyiyqcCB9+5rVOMlXdTMbGu622tkK53/kQelOZ/wZdgeSg1+M6E g0V3qD+ZcKHrGFndMF1p5LMMzqm2L5YJxAv8rmruacPSO3r+kR1o6P5BIgbbQZixY4tp n8WFY9YNhTOqHP7tKg72l2Fx1mM6Ca9x7owmObnlzJXOUlvw6Xvoy4Jn4N+ny/rfB6Nx L7ZgxbTsuILFiZZHh9iAP9HpqcVS2UOVZb0CgWfhlB+qzDHTSBYswj1xzM5/a4SQ4Im1 jn9R1wCdW6a2v68uk4jqix5j7GsE+WBo/QKZ/MaF9h3Tf0VBb827gHwc71LEMkE7t6SV kfAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fhWwyWt2lYelCmdazSYsoQ4sUh5+tGcY0PsW1zEh3yA=; b=tOQeRM0bBBjeLBbLTLbG6tXbwQOTbtqAYKvr1gMO2wvxpz+LJlhLobg7G03Jz4QrwQ ANoVEifTPaNwZm6RhAI5Cmzk0h4XHeAlLoNFg8nwW7M8bHeu9QlS8a5WzR1ow54x2ywI fLNUbBq2vNExM4vdR9zugaX3Kx6uRWLAoEZvctiI3gsrCdfkWwlL4+J31ESq/PZZcFC5 udNlgVbLcjpLlfOLXUgQVBSgPjMZiJVGrh+1QIKjv1gPD6vLXkXiUtBPSrHwwzm9RYQn m/oV2ND058KP0C8yx8t/5OT4DobPkuZovHiXz5UQqRcM2mK8LJU7fZvHA1KC1M7x6OA3 i8tA== X-Gm-Message-State: ABuFfoj6jFEmduCu9A8aDcctsQbATucrviHUu7Gz08T3jpIR43n5U9UW qFxjBlBQ6shJGwCiWK/mlWmmT1q+ X-Google-Smtp-Source: ACcGV61I8yFPbUOtAYaI7TCND7b6KSVLlk2ADBmW1kdATbrkXRs4B/GKQ19BQLF7AkOo/75Xc4hF2g== X-Received: by 2002:a19:4d8d:: with SMTP id a135-v6mr1393972lfb.60.1538581006252; Wed, 03 Oct 2018 08:36:46 -0700 (PDT) Received: from localhost.localdomain (31-211-229-121.customers.ownit.se. [31.211.229.121]) by smtp.gmail.com with ESMTPSA id u196-v6sm471838lja.42.2018.10.03.08.36.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 03 Oct 2018 08:36:45 -0700 (PDT) From: =?utf-8?q?Martin_=C3=85gren?= To: Derrick Stolee Cc: Stefan Beller , Jeff King , gitgitgadget@gmail.com, git@vger.kernel.org, Junio C Hamano , Derrick Stolee Subject: [PATCH 1/2] commit-graph: free `struct packed_git` after closing it Date: Wed, 3 Oct 2018 17:36:22 +0200 Message-Id: <84a5957ab8a38ac18c432843a3717c0afd0fbea9.1538579441.git.martin.agren@gmail.com> X-Mailer: git-send-email 2.19.0.329.g76f2f5c1e3 In-Reply-To: References: <1686b309-e0af-5518-0fa5-4635b2f481b9@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP `close_pack(p)` does not free the memory which `p` points to, so follow up with a call to `free(p)`. All other users of `close_pack()` look ok. Signed-off-by: Martin Ågren --- commit-graph.c | 1 + 1 file changed, 1 insertion(+) diff --git a/commit-graph.c b/commit-graph.c index 3d644fddc0..9b481bcd06 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -766,6 +766,7 @@ void write_commit_graph(const char *obj_dir, die(_("error opening index for %s"), packname.buf); for_each_object_in_pack(p, add_packed_commits, &oids, 0); close_pack(p); + free(p); } stop_progress(&oids.progress); strbuf_release(&packname); From patchwork Wed Oct 3 15:36:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_=C3=85gren?= X-Patchwork-Id: 10625051 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EBAE6112B for ; Wed, 3 Oct 2018 15:36:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA18A28E3B for ; Wed, 3 Oct 2018 15:36:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE6E828E3F; Wed, 3 Oct 2018 15:36:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7472428E3B for ; Wed, 3 Oct 2018 15:36:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726989AbeJCWZo (ORCPT ); Wed, 3 Oct 2018 18:25:44 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:42063 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726748AbeJCWZo (ORCPT ); Wed, 3 Oct 2018 18:25:44 -0400 Received: by mail-lj1-f193.google.com with SMTP id y71-v6so5538405lje.9 for ; Wed, 03 Oct 2018 08:36:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4p5x2geL/GLeSfknLVaIJCGegABo7aQf/tABNhnxc3g=; b=oNeElJj5OqeiVMpsvdP1KkTUTJDmMiqmvE2VOA885mqzxGyeb6zIuyYjpgQ9kgQsUL ERRz3+w9UQkUvrW0ncyipjno4wOS4e0tnLmFWN6nWzsIPrkCpctlR1B77i2KhwUyNQly GVOPgkZ5TVa6C1gY6PiKn3CKCOvPkxub6g+A2RGSxJXhWIF7fp6wp+yyMmVKTfqJqoNM d9gG0Nxvd8i/YvSNVRDUwTeeBFJy7RqY49Pzk2VeaUXsaARayNJGlgXjQSgkoaSfxwxp toMGlUYoCZ0wnT6IhhvKyxJIx7M8hgu21FrcT02agcKmv32gtBdAxjvhKOp0SRSncoE6 xywg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4p5x2geL/GLeSfknLVaIJCGegABo7aQf/tABNhnxc3g=; b=iGTD6edRg0Xxci1RA1Sbt8s2dGI4hnYJVcj7BKQ2099JNrd8spGry3IzDxe+N7fGP7 Xjgk//iif16Rkv81G7HnJDESYffGxzJSuFWarxKMpdj2JIlAzhRFb77xSAFyi99m5imW hYPpx/aVuejQk0dsaxyXmAi2BE6YSb9Aa/Qr4OJxqS4v/Z2AATmXd42/3MsG0kJ2Ite/ oqYVD7ZNKane6pwhcPFb0TNPi50QBgeMawSew8+GwI5wQgrpFiE/jTscH0e5kboVzY0a YbrmMlC7cv24dii0AXpLYU6ATNEnVfJzzq3BJfdfN+lbc/RF7gp4mAIU/dujrSpoaU3y tIvQ== X-Gm-Message-State: ABuFfohcsWBW1dliAtIpKttJSRY55RvJNTifocmDTVQ8Z2Cb/zPLCH+R P6KQAOqkiSM8gRIkGU89qQ0= X-Google-Smtp-Source: ACcGV61eGTpmVL8BTDEbrjnPdipbXJq6KklMpmKgvgr6ExKpba/2sWf1uDOMorrrOjtr3lxVR+vzSA== X-Received: by 2002:a2e:9b04:: with SMTP id u4-v6mr1508349lji.29.1538581009119; Wed, 03 Oct 2018 08:36:49 -0700 (PDT) Received: from localhost.localdomain (31-211-229-121.customers.ownit.se. [31.211.229.121]) by smtp.gmail.com with ESMTPSA id u196-v6sm471838lja.42.2018.10.03.08.36.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 03 Oct 2018 08:36:48 -0700 (PDT) From: =?utf-8?q?Martin_=C3=85gren?= To: Derrick Stolee Cc: Stefan Beller , Jeff King , gitgitgadget@gmail.com, git@vger.kernel.org, Junio C Hamano , Derrick Stolee Subject: [PATCH 2/2] builtin/commit-graph.c: UNLEAK variables Date: Wed, 3 Oct 2018 17:36:23 +0200 Message-Id: <5d260588675f6446079efc05b00492f2c99948a3.1538579441.git.martin.agren@gmail.com> X-Mailer: git-send-email 2.19.0.329.g76f2f5c1e3 In-Reply-To: References: <1686b309-e0af-5518-0fa5-4635b2f481b9@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP `graph_verify()`, `graph_read()` and `graph_write()` do the hard work of `cmd_commit_graph()`. As soon as these return, so does `cmd_commit_graph()`. `strbuf_getline()` may allocate memory in the strbuf, yet return EOF. We need to release the strbuf or UNLEAK it. Go for the latter since we are close to returning from `graph_write()`. `graph_write()` also fails to free the strings in the string list. They have been added to the list with `strdup_strings` set to 0. We could flip `strdup_strings` before clearing the list, which is our usual hack in situations like this. But since we are about to exit, let's just UNLEAK the whole string list instead. UNLEAK `graph` in `graph_verify`. While at it, and for consistency, UNLEAK in `graph_read()` as well, and remove an unnecessary UNLEAK just before dying. Signed-off-by: Martin Ågren --- builtin/commit-graph.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index bc0fa9ba52..66f12eb009 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -64,6 +64,7 @@ static int graph_verify(int argc, const char **argv) if (!graph) return 0; + UNLEAK(graph); return verify_commit_graph(the_repository, graph); } @@ -89,10 +90,8 @@ static int graph_read(int argc, const char **argv) graph_name = get_commit_graph_filename(opts.obj_dir); graph = load_commit_graph_one(graph_name); - if (!graph) { - UNLEAK(graph_name); + if (!graph) die("graph file %s does not exist", graph_name); - } FREE_AND_NULL(graph_name); @@ -115,7 +114,7 @@ static int graph_read(int argc, const char **argv) printf(" large_edges"); printf("\n"); - free_commit_graph(graph); + UNLEAK(graph); return 0; } @@ -166,6 +165,8 @@ static int graph_write(int argc, const char **argv) pack_indexes = &lines; if (opts.stdin_commits) commit_hex = &lines; + + UNLEAK(buf); } write_commit_graph(opts.obj_dir, @@ -174,7 +175,7 @@ static int graph_write(int argc, const char **argv) opts.append, 1); - string_list_clear(&lines, 0); + UNLEAK(lines); return 0; }