From patchwork Wed Oct 20 18:27:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12572997 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC37CC433F5 for ; Wed, 20 Oct 2021 18:27:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D5C9960FF2 for ; Wed, 20 Oct 2021 18:27:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231261AbhJTS3q (ORCPT ); Wed, 20 Oct 2021 14:29:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231222AbhJTS3o (ORCPT ); Wed, 20 Oct 2021 14:29:44 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1715C06161C for ; Wed, 20 Oct 2021 11:27:29 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id i12so47778wrb.7 for ; Wed, 20 Oct 2021 11:27:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CNbYrr8CmPMd96TaIzIjXGWpXvlhU+deDilQmXDMAiU=; b=pAw8wZh37dzIiuiLRVypGheaHyKjXe4FiPSX/qn4/yAG9uzIn2NSMtxp9rlVGC9m4w zPCWIWMRqn5imouqBNreCiq+R0zn92TDAtKiQ8epPcGhI87XjQgx4x/hzBH0r0WMaK3F 4pS1lp0b+/l9OjItC4tVZKJDKi4RlD+t86awznUO0OqKG4kXy0PAlQOxCjGSohcubwHa qOzfb6gR4RKv9wlKb07ZssiUudq9younfEcrEy/htiUZ7kBJ8wcRntGXmwUOfzuEcLtD f8wzHL4JTKFB1iWxZTFkObtxKalj1CtxY5Y0izPo1YaXMWCUnTwykUVrH/yF9Ikk8nS+ Me6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CNbYrr8CmPMd96TaIzIjXGWpXvlhU+deDilQmXDMAiU=; b=sPwJEGG94RKhP3NgFP5y9Vb1rvT1FKYKxoF8OJc+spSYRXGzdpE8MhmD9SIZjkdePg ibxQwObvh49s8t8Gf6jS7/R2ybYzlZOUQomG+HksQSILrblx3Rp6KLP4SfRUOemraQqN xr8/C8g7xaLqYdoX9agp5DBn+UubF76CFuBGub9QKm24DmOiAnt2cqhLUYTTzwld5CMf O4B1t3HfQBjCr0j5FCWSwmgZZDV3rJ2UjCjk5AEQgsFUFILT6AkthQP5ne8AqOxX8ITs xRcOEf+rbTyAiHpXs+bQyFD2Or0MpVWNr9ZNQjZNas05nkX+DvcSjvAtj7ogDF47dvLZ 0LcA== X-Gm-Message-State: AOAM533FXdgaNOkYtHd2L7x3W2HpSbUq/DVhN+P51hONytCFPnoqIuNp gKS1MogJ+8WfG7LRiiql+CSpkyuTgfrLcg== X-Google-Smtp-Source: ABdhPJwPLu4NeqazdpPlab9PlNdtyaiYAHzD7TbsfAd49Po4/ckeQ3ijWDyBIhPidxc3aLvdWFCwbw== X-Received: by 2002:adf:8bd2:: with SMTP id w18mr1049150wra.432.1634754448108; Wed, 20 Oct 2021 11:27:28 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i13sm3091093wmq.41.2021.10.20.11.27.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 11:27:27 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 1/3] tag: use a "goto cleanup" pattern, leak less memory Date: Wed, 20 Oct 2021 20:27:19 +0200 Message-Id: X-Mailer: git-send-email 2.33.1.1338.g20da966911a In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Change cmd_tag() to free its "struct strbuf"'s instead of using an UNLEAK() pattern. This changes code added in 886e1084d78 (builtin/: add UNLEAKs, 2017-10-01). As shown in the context of the declaration of the "struct msg_arg" (which I'm changing to use a designated initializer while at it, and to show the context in this change), that struct is just a thin wrapper around an int and "struct strbuf". Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/tag.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/builtin/tag.c b/builtin/tag.c index 6535ed27ee9..ad6c9855914 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -432,7 +432,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix) int annotate = 0, force = 0; int cmdmode = 0, create_tag_object = 0; const char *msgfile = NULL, *keyid = NULL; - struct msg_arg msg = { 0, STRBUF_INIT }; + struct msg_arg msg = { .buf = STRBUF_INIT }; struct ref_transaction *transaction; struct strbuf err = STRBUF_INIT; struct ref_filter filter; @@ -482,6 +482,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix) OPT_BOOL('i', "ignore-case", &icase, N_("sorting and filtering are case insensitive")), OPT_END() }; + int ret = 0; setup_ref_filter_porcelain_msg(); @@ -529,7 +530,6 @@ int cmd_tag(int argc, const char **argv, const char *prefix) ref_sorting_set_sort_flags_all(sorting, REF_SORTING_ICASE, icase); filter.ignore_case = icase; if (cmdmode == 'l') { - int ret; if (column_active(colopts)) { struct column_options copts; memset(&copts, 0, sizeof(copts)); @@ -540,7 +540,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix) ret = list_tags(&filter, sorting, &format); if (column_active(colopts)) stop_column_filter(); - return ret; + goto cleanup; } if (filter.lines != -1) die(_("-n option is only allowed in list mode")); @@ -552,12 +552,15 @@ int cmd_tag(int argc, const char **argv, const char *prefix) die(_("--points-at option is only allowed in list mode")); if (filter.reachable_from || filter.unreachable_from) die(_("--merged and --no-merged options are only allowed in list mode")); - if (cmdmode == 'd') - return delete_tags(argv); + if (cmdmode == 'd') { + ret = delete_tags(argv); + goto cleanup; + } if (cmdmode == 'v') { if (format.format && verify_ref_format(&format)) usage_with_options(git_tag_usage, options); - return for_each_tag_name(argv, verify_tag, &format); + ret = for_each_tag_name(argv, verify_tag, &format); + goto cleanup; } if (msg.given || msgfile) { @@ -626,10 +629,11 @@ int cmd_tag(int argc, const char **argv, const char *prefix) printf(_("Updated tag '%s' (was %s)\n"), tag, find_unique_abbrev(&prev, DEFAULT_ABBREV)); - UNLEAK(buf); - UNLEAK(ref); - UNLEAK(reflog_msg); - UNLEAK(msg); - UNLEAK(err); - return 0; +cleanup: + strbuf_release(&buf); + strbuf_release(&ref); + strbuf_release(&reflog_msg); + strbuf_release(&msg.buf); + strbuf_release(&err); + return ret; } From patchwork Wed Oct 20 18:27:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12572999 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F78EC433F5 for ; Wed, 20 Oct 2021 18:27:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5279D6109F for ; Wed, 20 Oct 2021 18:27:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231222AbhJTS3s (ORCPT ); Wed, 20 Oct 2021 14:29:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231238AbhJTS3p (ORCPT ); Wed, 20 Oct 2021 14:29:45 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EE57C061749 for ; Wed, 20 Oct 2021 11:27:30 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 186-20020a1c01c3000000b0030d8315b593so3503479wmb.5 for ; Wed, 20 Oct 2021 11:27:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=585MeI5T4HKkL1g4/bEtwEKVAkTW22WvWZtHm617jsk=; b=E8vbnXzOQ4kCvrSnyaq0e6E3nBpKBnUt1hl45ynjZM7REAE4DbbWt6Gn8V5EYqMy9w brVqZSGJfJGnbYAbheOPx6ASefr7FYx5QjxjLm4RKQGn1MBdQ/4iO7Ki8WoIDLvnqo9l TS7RqDeVD48Ztsz7etJir3UAJESAQDAJEbguxypbMPOnxpnQD3PitMDLt2QddDHpJS2d NqoRiCUiBkyPz1u0RxwFAwyjr0s1yT2+/GVVYQ3GTBCmVmB5F+WAxXBtUtHdS2FRa3zZ 6qUTweGqPVgkMX8yLjUWfZmAedkS3PIDki5T+tABm01nLJnQDmZKLBpCzM3hjO4ZkBB/ UQ/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=585MeI5T4HKkL1g4/bEtwEKVAkTW22WvWZtHm617jsk=; b=0sc/RnibZkgcQYhD+y781iTuQYUBf0QlMIKNwS9Xj3tTh/aLRPYMgokBGHrShgZLr0 j7HW3Nb2gvou0Ei7XC24x+21xIUMzGqITUy8LtAgH0K0rUu5elVude263IXUf/LGZNJU c522Sa3OKTheq4VZpF7E2PAx7e/SMA+vY2NhZ9vhAXA9zUc1mfqWHvEjHWFxoUzjJK0H z6x/PXqJd9zyyrJpkVMHU4nXG6t2+Nbr+SEWulkbUsYLRAEpTKHJ2fGQ/SftZytmzaTt dtwg6gXcEF48aBPRVIF2ULTYXGxhCQBJ98XfVwMReWtu0b8/n4BSf9HVA/jamXWjY+cJ x8/Q== X-Gm-Message-State: AOAM5302ZXHUkjveGxAEBprmtKrfCndWURyyNS2ixrAeoa+4cJyBuBAk FoaHZMCCitBRvveIMwHl1MY1dzuUjsZaug== X-Google-Smtp-Source: ABdhPJwJKCW/3CQBcUrVXDRh5WXVQ8XuewnWmswKpuPffILYWLtTwh9qtJCTJW9OSkJ32dvwzcPBlQ== X-Received: by 2002:a1c:4484:: with SMTP id r126mr15613660wma.150.1634754448893; Wed, 20 Oct 2021 11:27:28 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i13sm3091093wmq.41.2021.10.20.11.27.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 11:27:28 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 2/3] ref-filter API user: add and use a ref_sorting_release() Date: Wed, 20 Oct 2021 20:27:20 +0200 Message-Id: X-Mailer: git-send-email 2.33.1.1338.g20da966911a In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add a ref_sorting_release() and use it for some of the current API users, the ref_sorting_default() function and its siblings will do a malloc() which wasn't being free'd previously. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/for-each-ref.c | 2 +- builtin/tag.c | 1 + ref-filter.c | 9 +++++++++ ref-filter.h | 2 ++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c index 642b4b888fb..16a2c7d57ca 100644 --- a/builtin/for-each-ref.c +++ b/builtin/for-each-ref.c @@ -96,6 +96,6 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix) ref_array_clear(&array); free_commit_list(filter.with_commit); free_commit_list(filter.no_commit); - UNLEAK(sorting); + ref_sorting_release(sorting); return 0; } diff --git a/builtin/tag.c b/builtin/tag.c index ad6c9855914..6fe646710d6 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -630,6 +630,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix) find_unique_abbrev(&prev, DEFAULT_ABBREV)); cleanup: + ref_sorting_release(sorting); strbuf_release(&buf); strbuf_release(&ref); strbuf_release(&reflog_msg); diff --git a/ref-filter.c b/ref-filter.c index add429be797..282cdad1036 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -2705,6 +2705,15 @@ int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset) return 0; } +void ref_sorting_release(struct ref_sorting *sorting) +{ + while (sorting) { + struct ref_sorting *next = sorting->next; + free(sorting); + sorting = next; + } +} + int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset) { struct ref_filter *rf = opt->value; diff --git a/ref-filter.h b/ref-filter.h index b636f4389d0..6228458d306 100644 --- a/ref-filter.h +++ b/ref-filter.h @@ -127,6 +127,8 @@ void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *atom); int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset); /* Default sort option based on refname */ struct ref_sorting *ref_default_sorting(void); +/* Release a "struct ref_sorting" */ +void ref_sorting_release(struct ref_sorting *); /* Function to parse --merged and --no-merged options */ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset); /* Get the current HEAD's description */ From patchwork Wed Oct 20 18:27:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12573001 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38E59C433FE for ; Wed, 20 Oct 2021 18:27:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 24C236109F for ; Wed, 20 Oct 2021 18:27:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231284AbhJTS3v (ORCPT ); Wed, 20 Oct 2021 14:29:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231256AbhJTS3q (ORCPT ); Wed, 20 Oct 2021 14:29:46 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72317C06161C for ; Wed, 20 Oct 2021 11:27:31 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 67-20020a1c1946000000b0030d4c90fa87so11880417wmz.2 for ; Wed, 20 Oct 2021 11:27:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FHaytZHel5gVVKAT+Kci6ZP76N2n7tI4Fn75FtSz2Mk=; b=V/3CZumRgPv7j5ZjKWQTS1GTxRSuhvRGJRScP2HhRSfVSuVUpVyMB83UmpNz/mPPTp CX1Squ6134yFpkJfQGqvd6EZ96cyo+V4aVSUwibvJcAtITwI28VCXQuvgxnYSsSnNfon zibwAWlufXVqeSPvKUBiWucuOsoYJSRnvSNXaRj5B1i8SzmP8y0P6lSRFs4voAfOccyD 3/5UzDDIixRgHvtY5M8bQj8UVSr4Jex1zCZbhJpYMwB6PTYLfNHPpdnUHZl4q8SDF+HV 1El8ETKikyGOz5dnahwl26FMfsxOOH8m//FFujjNB3AozKk9HozCb0ROjcWpCvdF1qSL +X5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FHaytZHel5gVVKAT+Kci6ZP76N2n7tI4Fn75FtSz2Mk=; b=cf6qeialwTPDMorSVdVgboFxmo+3Rf9QdrlpLDQeRxokg34frDLbw9TQuBpaJOu4fK MEeJAGWr+ucTOa1nNsgt7f+f7+pCR+dNMhA7O998rM4gy8LVKsmDOY+IZ8pQRC8L6LU/ /BuhF3i1aFliVIq25JXWZutdI92ZEX4tRJXpZDuSFPJUavE+raC1yQt5GBIqhmRQJWiZ f9oqc1n9rkTOCx42cCmwSYWEFtn9QBWTZxJc5VKGPUxALJ61UY7R+hVfzrAUqCfXKL5d 3vTQ9EG2jcUfMNZ3LCHYIG6Rarcf+XNtfj7gZg+DuncW8K6fseAOHV5BCIEyabK99p9m LXmA== X-Gm-Message-State: AOAM533JmvR4/wupACJqd4YuZQ/rZN3mgF3xb0xhK8a1ZhCmLFWYsKI9 0SqUYKJ69yOIwnojfl+SjB1KFRdVv+0dnw== X-Google-Smtp-Source: ABdhPJxK2bi+vJVD2jN9hdnvK1VMzjR0A+/ZHksQaMGffpTgOfnZTJL1QVzdjf7sUQ+MGe1Lkcs1pw== X-Received: by 2002:a05:600c:4fcd:: with SMTP id o13mr16127741wmq.158.1634754449782; Wed, 20 Oct 2021 11:27:29 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id i13sm3091093wmq.41.2021.10.20.11.27.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 11:27:29 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 3/3] branch: use ref_sorting_release() Date: Wed, 20 Oct 2021 20:27:21 +0200 Message-Id: X-Mailer: git-send-email 2.33.1.1338.g20da966911a In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Use a ref_sorting_release() in branch.c to free the memory from the ref_sorting_options(). This plugs the final in-tree memory leak of that API. In the preceding commit the "sorting" variable was left in the cmd_branch() scope, even though that wasn't needed anymore. Move it to the "else if (list)" scope instead. We can also move the "struct string_list" only used for that branch to be declared in that block That "struct ref_sorting" does not need to be "static" (and isn't re-used). The "ref_sorting_options()" will return a valid one, we don't need to make it "static" to have it zero'd out. That it was static was another artifact of the pre-image of the preceding commit. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/branch.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/builtin/branch.c b/builtin/branch.c index 0b7ed82654a..7a1d1eeb070 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -407,7 +407,8 @@ static char *build_format(struct ref_filter *filter, int maxwidth, const char *r return strbuf_detach(&fmt, NULL); } -static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sorting, struct ref_format *format) +static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sorting, + struct ref_format *format, struct string_list *output) { int i; struct ref_array array; @@ -449,7 +450,7 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin if (column_active(colopts)) { assert(!filter->verbose && "--column and --verbose are incompatible"); /* format to a string_list to let print_columns() do its job */ - string_list_append(&output, out.buf); + string_list_append(output, out.buf); } else { fwrite(out.buf, 1, out.len, stdout); putchar('\n'); @@ -753,9 +754,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix) ref_sorting_set_sort_flags_all(sorting, REF_SORTING_ICASE, icase); ref_sorting_set_sort_flags_all( sorting, REF_SORTING_DETACHED_HEAD_FIRST, 1); - print_ref_list(&filter, sorting, &format); + print_ref_list(&filter, sorting, &format, &output); print_columns(&output, colopts, NULL); string_list_clear(&output, 0); + ref_sorting_release(sorting); return 0; } else if (edit_description) { const char *branch_name;