From patchwork Thu Oct 7 09:46:09 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: 12541401 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 C5ECCC433F5 for ; Thu, 7 Oct 2021 09:46:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A2475611AE for ; Thu, 7 Oct 2021 09:46:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240442AbhJGJsS (ORCPT ); Thu, 7 Oct 2021 05:48:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232869AbhJGJsJ (ORCPT ); Thu, 7 Oct 2021 05:48:09 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0464AC061755 for ; Thu, 7 Oct 2021 02:46:16 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id t8so17303640wri.1 for ; Thu, 07 Oct 2021 02:46:15 -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=WFCN7Aazo/ILNKg4fcrkalc+Ra/lGQ7IkaLgmAVCWs0=; b=ER/E9WX4jr9qNEWuEmPY3PeZQdHY/DX6uprFcQybassoHyiuGPgj4kuWborsDOWY6y Swfet1w5XVOo1fwyq+fw8bWoyWgen6+8cnSYqzjAYKLTyvymYgjgtSWrYJjwJapy7WPS jxUUf+Cm7GhIZBFQocv+Gfqm8JapnlMe+DsT8cy7joeA6WhCOzE4KFhDxuISe7jrhIzb cfZyeivqi7Ba6OcY1KPE+jRVorrsJTAbJgL5eWHwqMXWUkN3nEb2j1VvrTRpZhYr5cP2 xKHuokNZZQqhK47aGtuW1vN0YbF6V+ffPtwg9p/JQL/IefCiOh3DIh3TBwS3a/r043kE fAtg== 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=WFCN7Aazo/ILNKg4fcrkalc+Ra/lGQ7IkaLgmAVCWs0=; b=1IwdZVeez2intunoUv6LAI4V47LRvA4zq06qV4M1baFFTVY3r7ByYEytuH+wllV5VI z5DhZBjcQnzxoVwoseUAblIwwf0wBO9K08c7tnWpyQ2BqE5KDurcTz+dMLEpwtaIqy1z r3B1CcnSaJhqEfz5kNm5Bg8cUyZl2+hfcHNSLX/epEDwCN9QNAbYws7M2oUuGznOyoj2 geceOhA3hb9INGhMaEVAwgdcTqBmjf4EqqdYTsRgj8KSVMlb0xHZSnLpfXvgAG5qSups bUL+lRfGU+5DfzbesXOiQ90mdh0mapGI07YHDAxObKxRGjDNvxHnvTvFk39XfyZk+52H GO5w== X-Gm-Message-State: AOAM533VQacEiFHFRRwa7otxwmf9mFlbF1Vio8FQvZ7EM+nhSwxFlS6u urfasBN5o21vnsEPdfHMK4rAuYtUHU+Bgg== X-Google-Smtp-Source: ABdhPJwWYjTHgxt6eg0rjqpGfYDKCn4uABGixbZYWlb4eVCFhulHcOBU/cEsKKNZtYJWpr4dp9IxfA== X-Received: by 2002:a05:6000:44:: with SMTP id k4mr4060959wrx.68.1633599974345; Thu, 07 Oct 2021 02:46:14 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l13sm7720489wme.38.2021.10.07.02.46.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 02:46:13 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?q?Martin_=C3=85gren?= , Andrzej Hunt , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 1/3] unpack-trees: don't leak memory in verify_clean_subdirectory() Date: Thu, 7 Oct 2021 11:46:09 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1446.g6af949f83bd In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix two different but related memory leaks in verify_clean_subdirectory(). We leaked both the "pathbuf" if read_directory() returned non-zero, and we never cleaned up our own "struct dir_struct" either. * "pathbuf": When the read_directory() call followed by the free(pathbuf) was added in c81935348be (Fix switching to a branch with D/F when current branch has file D., 2007-03-15) we didn't bother to free() before we called die(). But when this code was later libified in 203a2fe1170 (Allow callers of unpack_trees() to handle failure, 2008-02-07) we started to leak as we returned data to the caller. This fixes that memory leak, which can be observed under SANITIZE=leak with e.g. the "t1001-read-tree-m-2way.sh" test. * "struct dir_struct": We've leaked the dir_struct ever since this code was added back in c81935348be. When that commit was written there wasn't an equivalent of dir_clear(). Since it was added in 270be816049 (dir.c: provide clear_directory() for reclaiming dir_struct memory, 2013-01-06) we've omitted freeing the memory allocated here. This memory leak could also be observed under SANITIZE=leak and the "t1001-read-tree-m-2way.sh" test. This makes all the test in "t1001-read-tree-m-2way.sh" pass under "GIT_TEST_PASSING_SANITIZE_LEAK=true", we'd previously die in tests 25, 26 & 28. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t1001-read-tree-m-2way.sh | 2 ++ unpack-trees.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/t/t1001-read-tree-m-2way.sh b/t/t1001-read-tree-m-2way.sh index 1057a96b249..d1115528cb9 100755 --- a/t/t1001-read-tree-m-2way.sh +++ b/t/t1001-read-tree-m-2way.sh @@ -20,6 +20,8 @@ In the test, these paths are used: rezrov - in H, deleted in M yomin - not in H or M ' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-read-tree.sh diff --git a/unpack-trees.c b/unpack-trees.c index a7e1712d236..89ca95ce90b 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -2156,9 +2156,10 @@ static int verify_clean_subdirectory(const struct cache_entry *ce, if (o->dir) d.exclude_per_dir = o->dir->exclude_per_dir; i = read_directory(&d, o->src_index, pathbuf, namelen+1, NULL); + dir_clear(&d); + free(pathbuf); if (i) return add_rejected_path(o, ERROR_NOT_UPTODATE_DIR, ce->name); - free(pathbuf); return cnt; } From patchwork Thu Oct 7 09:46:10 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: 12541399 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 1E16BC433FE for ; Thu, 7 Oct 2021 09:46:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 051186117A for ; Thu, 7 Oct 2021 09:46:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240212AbhJGJsR (ORCPT ); Thu, 7 Oct 2021 05:48:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238404AbhJGJsK (ORCPT ); Thu, 7 Oct 2021 05:48:10 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8512C061760 for ; Thu, 7 Oct 2021 02:46:16 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id t2so17151775wrb.8 for ; Thu, 07 Oct 2021 02:46:16 -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=M0T9wd0WWaQJFbmAZmQdPtXB1nHO4u/JsR6zBWETr14=; b=J/CnVDitC6yDcjXEjjP0O0UYdMmXjbVAUGIk/+jmkPDag13TWfi31vLue5Bu/28wLF hpSetB18dv4+HoESwcYKKFiF+FtHIlFPGObRPPQjoDKRHj78ScDRjy2QnTlMKoj9q3qa dnBOaevvI8DEQxcO9gN6Qer5+kqaBxfCh31MQpQV/e5+ng8aDF4V4vA3eObc8QdhnS++ djhAWRbcFuzJ1KU65+PulwpzkY1kOgCt9ygXAyxwRFa6xMaEKP/tos2O7XgdY32FC7yJ hyrVs33zzQZ/oA5rxxjYs7Qa5X9azzwcV8u+oQHCrA59x6eXNg4ckcKcGXfNTvquDylb 8dxg== 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=M0T9wd0WWaQJFbmAZmQdPtXB1nHO4u/JsR6zBWETr14=; b=Jg1CU8oeHhiYoB/feA+qidSsgjvLYcyO/7EO9WWL/TwQLAtuxdg/IeMgO77JW8Q685 MkjND+YrIt+Ju4eKpS+Wr1B7JiWA5E8wNrzMGrz2Aj7sMK6E+YQcZCgK2FMCXR05UaKx IKl/kd4lUQL+F4PAGTttNNdVQlkdAxUe3Pyo8t7ZuqF28V+4Dwf/cFA3huk7py4Ylmne qTMVTt2uS61+RONxocqVupZWLUOvj9erY9Wa1uZH0inv2SsGpkPt4gZOWkQGB9A1FRI7 fk9JgYgFWf4rLtg9macLUPJ9V9cuxS6RIyqHj3jblEDWdpkeZW5dpiLv7Bu3L1Fb3fAg RMEg== X-Gm-Message-State: AOAM530OWLsLkicrVD5cfOWlk51CRPbtZ5HcJPThvE/mc4SbLcKSQ/9b hcheYg0m52JG2hUJbR8t5Tu6J5/BoSS+Sg== X-Google-Smtp-Source: ABdhPJz5c7vl4Alr8tVNm0U3SY1B27yZFln6Y6V338IddBePwBDhzL1aEwN2tMlq1LDJrVWQgm+ykw== X-Received: by 2002:a1c:f713:: with SMTP id v19mr3481583wmh.188.1633599975077; Thu, 07 Oct 2021 02:46:15 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l13sm7720489wme.38.2021.10.07.02.46.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 02:46:14 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?q?Martin_=C3=85gren?= , Andrzej Hunt , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 2/3] sequencer: add a "goto cleanup" to do_reset() Date: Thu, 7 Oct 2021 11:46:10 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1446.g6af949f83bd In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Restructure code that's mostly added in 9055e401dd6 (sequencer: introduce new commands to reset the revision, 2018-04-25) to avoid code duplication, and to make freeing other resources easier in a subsequent commit. It's safe to initialize "tree_desc" to be zero'd out in order to unconditionally free desc.buffer, it won't be initialized on the first couple of "goto"'s. There are three earlier "return"'s in this function that I'm not bothering to covert, those don't need to rollback anything, or free any resources, so let's leave, even though they could safely "goto cleanup" as well. Signed-off-by: Ævar Arnfjörð Bjarmason --- sequencer.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/sequencer.c b/sequencer.c index 6872b7b00a4..457eba4ab10 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3650,7 +3650,7 @@ static int do_reset(struct repository *r, struct strbuf ref_name = STRBUF_INIT; struct object_id oid; struct lock_file lock = LOCK_INIT; - struct tree_desc desc; + struct tree_desc desc = { 0 }; struct tree *tree; struct unpack_trees_options unpack_tree_opts; int ret = 0; @@ -3684,10 +3684,8 @@ static int do_reset(struct repository *r, strbuf_addf(&ref_name, "refs/rewritten/%.*s", len, name); if (get_oid(ref_name.buf, &oid) && get_oid(ref_name.buf + strlen("refs/rewritten/"), &oid)) { - error(_("could not read '%s'"), ref_name.buf); - rollback_lock_file(&lock); - strbuf_release(&ref_name); - return -1; + ret = error(_("could not read '%s'"), ref_name.buf); + goto cleanup; } } @@ -3703,24 +3701,18 @@ static int do_reset(struct repository *r, init_checkout_metadata(&unpack_tree_opts.meta, name, &oid, NULL); if (repo_read_index_unmerged(r)) { - rollback_lock_file(&lock); - strbuf_release(&ref_name); - return error_resolve_conflict(_(action_name(opts))); + ret = error_resolve_conflict(_(action_name(opts))); + goto cleanup; } if (!fill_tree_descriptor(r, &desc, &oid)) { - error(_("failed to find tree of %s"), oid_to_hex(&oid)); - rollback_lock_file(&lock); - free((void *)desc.buffer); - strbuf_release(&ref_name); - return -1; + ret = error(_("failed to find tree of %s"), oid_to_hex(&oid)); + goto cleanup; } if (unpack_trees(1, &desc, &unpack_tree_opts)) { - rollback_lock_file(&lock); - free((void *)desc.buffer); - strbuf_release(&ref_name); - return -1; + ret = -1; + goto cleanup; } tree = parse_tree_indirect(&oid); @@ -3728,13 +3720,15 @@ static int do_reset(struct repository *r, if (write_locked_index(r->index, &lock, COMMIT_LOCK) < 0) ret = error(_("could not write index")); - free((void *)desc.buffer); if (!ret) ret = update_ref(reflog_message(opts, "reset", "'%.*s'", len, name), "HEAD", &oid, NULL, 0, UPDATE_REFS_MSG_ON_ERR); - +cleanup: + free((void *)desc.buffer); + if (ret < 0) + rollback_lock_file(&lock); strbuf_release(&ref_name); return ret; } From patchwork Thu Oct 7 09:46:11 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: 12541403 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 C6D1AC433F5 for ; Thu, 7 Oct 2021 09:46:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AD94561139 for ; Thu, 7 Oct 2021 09:46:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240682AbhJGJsW (ORCPT ); Thu, 7 Oct 2021 05:48:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239515AbhJGJsL (ORCPT ); Thu, 7 Oct 2021 05:48:11 -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 8C3CAC061762 for ; Thu, 7 Oct 2021 02:46:17 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id v17so17151218wrv.9 for ; Thu, 07 Oct 2021 02:46:17 -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=bbZSFlrZWdQ6B6swv0UdSnWvmbn//nd6iH5EIXUSqAI=; b=nga+TsFxK6jx0nnd3iYOXC7v5f9lT8EvLNIMjrLQm+ve4V+w7hRCKq1i09NvuFJoMn mOw0SksvzzvcRi4qankrB+F3AeQS+8iJidcojShmyoyIS0SwuQfAlXHA+sEMq3R7atO4 IhGXMY4bY49HJduT1yFO9zldCyGTosGL0D5PNwylMf4zMZ45vk66OD1mqOGLqPk38jPP xak8cCJhBMfsWkl+pUia0nDD/TxI7zJJf5RMm+NPCRGXUW2rsJTLAfQLU0wrnY+NC4dZ jcCf8ORU+2F4XTB2gnKoEpm2ivDLge4hRp6e+Tu8krkBjPVVZsZyg3qmqcAj6WyU8ZfR GYDA== 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=bbZSFlrZWdQ6B6swv0UdSnWvmbn//nd6iH5EIXUSqAI=; b=b3tB1n2/C4yKEBqFb/BsPCHijg9DtsnlTU2cR9kxNTHTZlcGKRjn5ueuw3yZ/ZhIK6 ld901+y2dpdQLYA5e2lLSfoNrQqJjT5WX6ovKxldcl4sTlKVoaotNsgqJiIdhVv/8J65 frc7bxoK/K430n3xjTFXpcJ8mnMlkNcshvfaY9IZ0xp7pe0L3W486XoJShegnXr1zCiv VDxsIAJrO5MuUFKTyrZmTf1OqVO1rHBg9ScDybRpIjOAOxgDVyoovwY/A7YaT13rtsxM sg4IBzImD32Fiukdox/T4JBeH42Sq5y+ibGqTTf0yF+mEc+0Krfm4JhOM/yPAixb0U22 czTQ== X-Gm-Message-State: AOAM532/AXG6hoqto6LLqz5YY0AH9E7QxvAmch39LQjo70Am2pSSsQbR S6at/VIQ5QrIbQ4qOEluaFuQwTvxKEO5hg== X-Google-Smtp-Source: ABdhPJx16SlzTFm7SLz+b3eheNTPxi14RXSyxWNG1YK7zsx9IJgNRk5o+idDKaBIM4I+BzZNGRL5/g== X-Received: by 2002:a1c:f01a:: with SMTP id a26mr3455983wmb.150.1633599975883; Thu, 07 Oct 2021 02:46:15 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id l13sm7720489wme.38.2021.10.07.02.46.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Oct 2021 02:46:15 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , =?utf-8?q?Martin_=C3=85gren?= , Andrzej Hunt , Jeff King , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH v2 3/3] sequencer: fix a memory leak in do_reset() Date: Thu, 7 Oct 2021 11:46:11 +0200 Message-Id: X-Mailer: git-send-email 2.33.0.1446.g6af949f83bd In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Fix a memory leak introduced in 9055e401dd6 (sequencer: introduce new commands to reset the revision, 2018-04-25), which called setup_unpack_trees_porcelain() without a corresponding call to clear_unpack_trees_porcelain(). This inches us closer to passing various tests in "t34*.sh" (e.g. "t3434-rebase-i18n.sh"), but because they have so many other memory leaks in revisions.c this doesn't make any test file or even a single test pass. Signed-off-by: Ævar Arnfjörð Bjarmason --- sequencer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sequencer.c b/sequencer.c index 457eba4ab10..fefe5a601f4 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3652,7 +3652,7 @@ static int do_reset(struct repository *r, struct lock_file lock = LOCK_INIT; struct tree_desc desc = { 0 }; struct tree *tree; - struct unpack_trees_options unpack_tree_opts; + struct unpack_trees_options unpack_tree_opts = { 0 }; int ret = 0; if (repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0) @@ -3689,7 +3689,6 @@ static int do_reset(struct repository *r, } } - memset(&unpack_tree_opts, 0, sizeof(unpack_tree_opts)); setup_unpack_trees_porcelain(&unpack_tree_opts, "reset"); unpack_tree_opts.head_idx = 1; unpack_tree_opts.src_index = r->index; @@ -3730,6 +3729,7 @@ static int do_reset(struct repository *r, if (ret < 0) rollback_lock_file(&lock); strbuf_release(&ref_name); + clear_unpack_trees_porcelain(&unpack_tree_opts); return ret; }