From patchwork Tue Apr 7 14:27:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denton Liu X-Patchwork-Id: 11478167 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 34667112C for ; Tue, 7 Apr 2020 14:28:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 10C8620801 for ; Tue, 7 Apr 2020 14:28:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FkE8W4DJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729075AbgDGO2Z (ORCPT ); Tue, 7 Apr 2020 10:28:25 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:36381 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728943AbgDGO2Y (ORCPT ); Tue, 7 Apr 2020 10:28:24 -0400 Received: by mail-qt1-f196.google.com with SMTP id m33so2787638qtb.3 for ; Tue, 07 Apr 2020 07:28:23 -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=S0aG82s5CcnkkAJmRuKrOrhMfbEmERigVtMxWONZzI8=; b=FkE8W4DJ7L0oZ7K6alXBZW8houe/WokQ89n42jaiDP3Wjy4RWc1+enhZ5GJ+y5iiYG gdhtLMVASIlfrgVim9mhAx979k5s9/5m2GL8VlD088sYcL6g+YNsfm03R+eZ/Q18tewc RPJ4Q87CiRN+FkDgVVoaJsQaDLEt5R3q8lQElheD8gJUKqkCZfnyJ/lbOLU1XEyVGOCn 0Fq0UAwj8vfWqd0uCwQVEtQeY0S6uZLTnqZRYrN9dbbPNIYqN/lhshL4UHc3tpqlQU/s /jkzkUmE9YWF/UDrK84EkV/filmKCvyZeabEKBZuPfj6Fns1eAdrFt45shcK0HQw58DV vzpA== 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=S0aG82s5CcnkkAJmRuKrOrhMfbEmERigVtMxWONZzI8=; b=FvhnqzCacWHsPL1eKolzt7LJNeyfKtXh5RCp9hXNrXObf4CIoVdaW1uzQrZbwA8le/ K0lZCwZfN+oKhka0b1zGsraCOuF6P3CYsLEgZoVni6wRJAlh8b556XJkMXwtketYxYdf nYLByIk2EOyl3oGEeEJgVwdrNv9AtcruuhVspOw/D8Atg/WRJcL1uULXEGSQx6zN5iBO 0hNiNCmm6aWwe/PgCQs60YjeCzQSya9W/sqakxOOsxHTy69hN/kfpwyScOXqxMG41dY0 xirvDVx5x16AX6iwTj5QOAeCVYck0zeoWtvZnpUzWPTk5XLjYC5UQtRNit3kpWcV6HOr UfLg== X-Gm-Message-State: AGi0PubqFcQ5Nzk/Ai4/Fwnf7E3rL/3+NXMR0mg1X8BKdzAtzXUp9+fI KDcduAHDkgNTlyG2Zb/5WvqvvcVm X-Google-Smtp-Source: APiQypI/5xAXttBaYEjAmOWTVFt+kgDG8GETjn4OfxOseWA2Gjgf87rxpCBG9YXPIeTLAfFtFJbCbg== X-Received: by 2002:ac8:6890:: with SMTP id m16mr2475359qtq.5.1586269701882; Tue, 07 Apr 2020 07:28:21 -0700 (PDT) Received: from archbookpro.lan ([199.249.110.29]) by smtp.gmail.com with ESMTPSA id j6sm17051736qti.25.2020.04.07.07.28.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 07:28:21 -0700 (PDT) From: Denton Liu To: Git Mailing List Cc: Alban Gruin , Johannes Schindelin , Junio C Hamano , Phillip Wood Subject: [PATCH v5 03/22] sequencer: stop leaking buf Date: Tue, 7 Apr 2020 10:27:50 -0400 Message-Id: <76585e5b1367a3adf18d761b2af9356ee64b46fd.1586269543.git.liu.denton@gmail.com> X-Mailer: git-send-email 2.26.0.159.g23e2136ad0 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 In read_populate_opts(), we call read_oneliner() _after_ calling strbuf_release(). This means that `buf` is leaked at the end of the function. Always clean up the strbuf by going to `done_rebase_i` whether or not we return an error. Signed-off-by: Denton Liu --- sequencer.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sequencer.c b/sequencer.c index e528225e78..faab0b13e8 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2485,6 +2485,7 @@ static int read_populate_opts(struct replay_opts *opts) { if (is_rebase_i(opts)) { struct strbuf buf = STRBUF_INIT; + int ret = 0; if (read_oneliner(&buf, rebase_path_gpg_sign_opt(), 1)) { if (!starts_with(buf.buf, "-S")) @@ -2525,7 +2526,7 @@ static int read_populate_opts(struct replay_opts *opts) opts->keep_redundant_commits = 1; read_strategy_opts(opts, &buf); - strbuf_release(&buf); + strbuf_reset(&buf); if (read_oneliner(&opts->current_fixups, rebase_path_current_fixups(), 1)) { @@ -2538,12 +2539,16 @@ static int read_populate_opts(struct replay_opts *opts) } if (read_oneliner(&buf, rebase_path_squash_onto(), 0)) { - if (get_oid_hex(buf.buf, &opts->squash_onto) < 0) - return error(_("unusable squash-onto")); + if (get_oid_hex(buf.buf, &opts->squash_onto) < 0) { + ret = error(_("unusable squash-onto")); + goto done_rebase_i; + } opts->have_squash_onto = 1; } - return 0; +done_rebase_i: + strbuf_release(&buf); + return ret; } if (!file_exists(git_path_opts_file()))