From patchwork Tue Oct 2 14:58:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Philippe Blain via GitGitGadget X-Patchwork-Id: 10623809 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 7CD3D15A6 for ; Tue, 2 Oct 2018 14:58:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A5ED20246 for ; Tue, 2 Oct 2018 14:58:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5EFF320416; Tue, 2 Oct 2018 14:58:50 +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 7849320246 for ; Tue, 2 Oct 2018 14:58:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729026AbeJBVmg (ORCPT ); Tue, 2 Oct 2018 17:42:36 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:39766 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726178AbeJBVmg (ORCPT ); Tue, 2 Oct 2018 17:42:36 -0400 Received: by mail-pl1-f195.google.com with SMTP id w14-v6so1824767plp.6 for ; Tue, 02 Oct 2018 07:58:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:in-reply-to:references:from:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=rdM8CsWrGFbyF/WMo7PncykA222x6fhLBIpxan5tuxE=; b=EZZ84iEJ/Mm427h1TLWzxrOeHaBbLHNfAEXTfCafMu0bcmnFzoyRRPuLZPmiPAEHDm OtTh+UgDxHXyIbq3L5vnQTUjSgk1QwXXu8vZgdnkvmuEV7xRsrKLMQW1ouJFMTQ/865b 41Qh7krQm2ENTXNE8vQPlG5witBW1lSrwN2IV4V0uhTEagOD5euDM31Vk/W864uA00tc QnpAmthUuT5R7zEYJkfcwc3FKDmcUufPksD6SvfExw60Tpt2DNE7dTH2d6d95YEsa0iq uPlor3K6gS54ouJWJ54tPyBoIS+kjHOtdNSIosFUmrV7Lr6j90GedImmqyfwEbM5kd5D rYpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:in-reply-to:references:from :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=rdM8CsWrGFbyF/WMo7PncykA222x6fhLBIpxan5tuxE=; b=UCxPXgZAHxa3EsgbWhadhapEa3KKFJB5o6Dj62h6mWI4CWohkfxrL+ypia8mtUf/hk NXauDSXtimtl5lVVV9LalzEClXOOcSvrRwXb2/tKKlQmhZrXCOITpShn/JAPRT9J+hYh GwYwRJVTUbL6yTzPP34mFh9qRN4YbLJK8xMvQaVJInO6beVOqRaXRS3dO9rxDC457gDV G6oklLi2l2Qs7v6FbUjPVYyBq9kkLBWLoQ1GMycsW52LURLZdHoq8cqzjySDZeE+rgnb dpYYigJj28k5Zo7m9cjgXoXhxHsWSBlQtomzHFbPVMpKIKGPUM58/s1PU9X5j+dtXCUH AHjQ== X-Gm-Message-State: ABuFfoio/ozgjI4ZqC81zZHPClb/MtKWm6qC02d8Ygv0sA2lelUW0pTf OO9wcr+WlDOHr81q5F4hKSUNoQFX X-Google-Smtp-Source: ACcGV604oMxWHgjEJiBRiSioOlC9Gu5dol7Aex2wlbo1vZwo43+WHO/uwQre/Ft/ozYiRXbh5jg/Sw== X-Received: by 2002:a62:d046:: with SMTP id p67-v6mr16939625pfg.147.1538492326038; Tue, 02 Oct 2018 07:58:46 -0700 (PDT) Received: from [127.0.0.1] ([40.112.137.127]) by smtp.gmail.com with ESMTPSA id l3-v6sm21265435pff.8.2018.10.02.07.58.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Oct 2018 07:58:45 -0700 (PDT) Date: Tue, 02 Oct 2018 07:58:45 -0700 (PDT) X-Google-Original-Date: Tue, 02 Oct 2018 14:58:40 GMT Message-Id: <6906c25415eddf79cc3f71f905a77b140f2f66f0.1538492321.git.gitgitgadget@gmail.com> In-Reply-To: References: From: "Derrick Stolee via GitGitGadget" Subject: [PATCH 1/2] commit-graph: clean up leaked memory during write Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Derrick Stolee The write_commit_graph() method in commit-graph.c leaks some lits and strings during execution. In addition, a list of strings is leaked in write_commit_graph_reachable(). Clean these up so our memory checking is cleaner. Running 'valgrind --leak-check=full git commit-graph write --reachable' demonstrates these leaks and how they are fixed after this change. Signed-off-by: Derrick Stolee Reviewed-by: Martin Ă…gren --- commit-graph.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/commit-graph.c b/commit-graph.c index 2a24eb8b5a..7226bd6b58 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -698,6 +698,8 @@ void write_commit_graph_reachable(const char *obj_dir, int append, string_list_init(&list, 1); for_each_ref(add_ref_to_list, &list); write_commit_graph(obj_dir, NULL, &list, append, report_progress); + + string_list_clear(&list, 0); } void write_commit_graph(const char *obj_dir, @@ -846,9 +848,11 @@ void write_commit_graph(const char *obj_dir, compute_generation_numbers(&commits, report_progress); graph_name = get_commit_graph_filename(obj_dir); - if (safe_create_leading_directories(graph_name)) + if (safe_create_leading_directories(graph_name)) { + UNLEAK(graph_name); die_errno(_("unable to create leading directories of %s"), graph_name); + } hold_lock_file_for_update(&lk, graph_name, LOCK_DIE_ON_ERROR); f = hashfd(lk.tempfile->fd, lk.tempfile->filename.buf); @@ -893,6 +897,8 @@ void write_commit_graph(const char *obj_dir, finalize_hashfile(f, NULL, CSUM_HASH_IN_STREAM | CSUM_FSYNC); commit_lock_file(&lk); + free(graph_name); + free(commits.list); free(oids.list); oids.alloc = 0; oids.nr = 0;