From patchwork Mon Aug 17 21:33:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff King X-Patchwork-Id: 11719235 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F0CE6618 for ; Mon, 17 Aug 2020 21:33:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E2AAC2065D for ; Mon, 17 Aug 2020 21:33:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728458AbgHQVdW (ORCPT ); Mon, 17 Aug 2020 17:33:22 -0400 Received: from cloud.peff.net ([104.130.231.41]:33590 "EHLO cloud.peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728445AbgHQVdP (ORCPT ); Mon, 17 Aug 2020 17:33:15 -0400 Received: (qmail 6730 invoked by uid 109); 17 Aug 2020 21:33:15 -0000 Received: from Unknown (HELO peff.net) (10.0.1.2) by cloud.peff.net (qpsmtpd/0.94) with ESMTP; Mon, 17 Aug 2020 21:33:15 +0000 Authentication-Results: cloud.peff.net; auth=none Received: (qmail 22310 invoked by uid 111); 17 Aug 2020 21:33:14 -0000 Received: from coredump.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.2) by peff.net (qpsmtpd/0.94) with (TLS_AES_256_GCM_SHA384 encrypted) ESMTPS; Mon, 17 Aug 2020 17:33:14 -0400 Authentication-Results: peff.net; auth=none Date: Mon, 17 Aug 2020 17:33:13 -0400 From: Jeff King To: git@vger.kernel.org Cc: Junio C Hamano , Eric Sunshine Subject: [PATCH v2 6/7] config: fix leak in git_config_get_expiry_in_days() Message-ID: <20200817213313.GF1854722@coredump.intra.peff.net> References: <20200817213228.GA1854603@coredump.intra.peff.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200817213228.GA1854603@coredump.intra.peff.net> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We use git_config_get_string() to retrieve the expiry value in a newly allocated string. But after parsing it, we never free it, leaking the memory. We could fix this with a free() obviously, but there's an even better solution: we can use the non-allocating "tmp" variant of the function; we only need it to be valid for the lifetime of our parse function. Signed-off-by: Jeff King --- config.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.c b/config.c index f0367c76ad..2bdff4457b 100644 --- a/config.c +++ b/config.c @@ -2300,11 +2300,11 @@ int git_config_get_expiry(const char *key, const char **output) int git_config_get_expiry_in_days(const char *key, timestamp_t *expiry, timestamp_t now) { - char *expiry_string; + const char *expiry_string; intmax_t days; timestamp_t when; - if (git_config_get_string(key, &expiry_string)) + if (git_config_get_string_tmp(key, &expiry_string)) return 1; /* no such thing */ if (git_parse_signed(expiry_string, &days, maximum_signed_value_of_type(int))) {