From patchwork Tue Jan 22 21:45:46 2019 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: 10776319 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 61F2113B4 for ; Tue, 22 Jan 2019 21:46:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A7742AC31 for ; Tue, 22 Jan 2019 21:46:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3AAEA2AC77; Tue, 22 Jan 2019 21:46:06 +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 D9B6F2AC31 for ; Tue, 22 Jan 2019 21:46:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726411AbfAVVqE (ORCPT ); Tue, 22 Jan 2019 16:46:04 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:42277 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726225AbfAVVqE (ORCPT ); Tue, 22 Jan 2019 16:46:04 -0500 Received: by mail-lf1-f68.google.com with SMTP id l10so32299lfh.9 for ; Tue, 22 Jan 2019 13:46:03 -0800 (PST) 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=lm5HEqshLwRM1eBa7UFHoTEdBow9z3iPjArXjM0dLSc=; b=JhAuBo8x1+OPvqMGdTm2x0FjOTIPoFv2u27UMeJFsuDzaT9mAFh5FnS6NUfhSbCPHU M/xbHv8VrZtPzwafAo2lSwKnR+1/k1MEcivLRwbsgeaFMPhUjBNRDLFy+G05ZteirHAa 30EsbXaT5Ko0hI4ZIBmU4iO6LYJRFKxQbxQ90ZKDqNcuKN73Fx58AcPmnXDVMSaShRBl GzvyUn7W8oksKZqlX+q5srK/9/Bb8q1oyfoiwcs9L6WdejEQJAnZGaDUaneOL/O4N0g5 xXbSB1KO75gjKTY2PZ/kLwT6/Sr4qiv3JSamhxUFqqwsz6HPI01JAGO1/Nb3SI1+u+2o IEKA== 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=lm5HEqshLwRM1eBa7UFHoTEdBow9z3iPjArXjM0dLSc=; b=bLJxlWeauBM1xxT7DZLO65ZgrSHNTG++bjaDKlTH3PYAAc1+ncV3eWUV0yega0xtMX bmzgDauPxCWoCoQ13wlQR+JMWwmay8AYl3Yu0pDCGqIyBzGRxVKlPTSAmzy4nf7rRz+e QsDS9nxKY25/Sl5c1Tj6yLiNdw8TdMc53isan+kGl/FshiCBzXS2CAB3mY4kZg1uXPvV sq59EF8uV+AK2kEGHlR7QFtFaa6XXWBY7GFHwQSV0SUYjOZ+2jsOPAR8iI9ZSSuzWcaJ N0YFS+rWZAYgTa8l1XVHlTl4ZVvPtKpZky9GPHXcYW2i6Voy3ygvmnYdU3M59WKx5ZGl 85Og== X-Gm-Message-State: AJcUukdlrfUAsnsjGoetPW+9La9cBFKzx2JZ+RTRtUp1/fzSZLjU+1Nu 8cXysCEgHMePn69Xp23+goHxUC9w X-Google-Smtp-Source: ALg8bN7gqSZrg1LE5gUBp/S+KLUU/sUJSTmJcI7JsgrH0oEEjWT/Pl0/JDu21f8dp+n/094/i83T4g== X-Received: by 2002:a19:be16:: with SMTP id o22mr21762504lff.22.1548193561952; Tue, 22 Jan 2019 13:46:01 -0800 (PST) Received: from localhost.localdomain (31-211-229-121.customers.ownit.se. [31.211.229.121]) by smtp.gmail.com with ESMTPSA id k3-v6sm188706lja.8.2019.01.22.13.46.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Jan 2019 13:46:01 -0800 (PST) From: =?utf-8?q?Martin_=C3=85gren?= To: git@vger.kernel.org Cc: Jeff King , "brian m . carlson" Subject: [PATCH v3 0/2] setup: fix memory leaks with `struct repository_format` Date: Tue, 22 Jan 2019 22:45:46 +0100 Message-Id: X-Mailer: git-send-email 2.20.1.98.gecbdaf0899 In-Reply-To: References: 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 On Tue, 22 Jan 2019 at 14:34, Martin Ågren wrote: > > On Tue, 22 Jan 2019 at 08:07, Jeff King wrote: > > > For the record, I can live with it either way. There are so many funky > > little setup corner cases in the code already, and we don't even really > > have a real-world case to dissect at this point. So the right thing may > > also just be to finish this patch series as quickly as possible and move > > on to something more useful. :) > > I rebased the "something like this?" into this series yesterday and I > think the end result is better, but also that the way there is clearer, > mostly because this patch is then gone. I wanted to double-check it > tonight and submit it. I'll do that tonight. Here's that reroll. I now reset the entire struct in the error path of `clear_...()`. Thus, the user that is reading `repo_fmt.hash_algo` despite not being supposed to, can keep reading it, now knowing that the value has a default value. I also expanded on the documentation a little to point out that we'll reset to the default struct state if we don't find any "core.repositoryformatversion". Martin Martin Ågren (2): setup: free old value before setting `work_tree` setup: fix memory leaks with `struct repository_format` cache.h | 27 ++++++++++++++++++++++++--- builtin/init-db.c | 3 ++- repository.c | 3 ++- setup.c | 33 +++++++++++++++++++++------------ worktree.c | 4 +++- 5 files changed, 52 insertions(+), 18 deletions(-)