[PATCH v3 2/4] last-modified: fix memory leak when more than one revision is given
- From
Toon Claes <toon@iotcl.com>
- Date
- Jan 16, 2026, 13:08 UTC
- Message-ID
- <20260116-toon-last-modified-tree-v3-2-e6ade4dc35ab@iotcl.com>
- In-Reply-To
- <20260116-toon-last-modified-tree-v3-0-e6ade4dc35ab@iotcl.com>
When more than one revision is given, the function populate_paths_from_revs() leaks a `struct pathspec`. Plug it.
Signed-off-by: Toon Claes <toon@iotcl.com> --- builtin/last-modified.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/builtin/last-modified.c b/builtin/last-modified.c index 7d95244e3f..06e3f79aec 100644 --- a/builtin/last-modified.c +++ b/builtin/last-modified.c @@ -123,7 +123,7 @@ static void add_path_from_diff(struct diff_queue_struct *q, static int populate_paths_from_revs(struct last_modified *lm) { - int num_interesting = 0; + int num_interesting = 0, ret = 0; struct diff_options diffopt; /* @@ -145,16 +145,20 @@ static int populate_paths_from_revs(struct last_modified *lm) if (obj->item->flags & UNINTERESTING) continue; - if (num_interesting++) - return error(_("last-modified can only operate on one revision at a time")); + if (num_interesting++) { + ret = error(_("last-modified can only operate on one revision at a time")); + goto out; + } diff_tree_oid(lm->rev.repo->hash_algo->empty_tree, &obj->item->oid, "", &diffopt); diff_flush(&diffopt); } + +out: clear_pathspec(&diffopt.pathspec); - return 0; + return ret; } static void last_modified_emit(struct last_modified *lm,
-- 2.52.0