# [PATCH] Fix memory leak in get_reachable_subset

5 messages from 2023-06-03 to 2023-06-05. Participants: Mike Hommey, Junio C Hamano, René Scharfe, Derrick Stolee.
Thread: https://gitlist.dev/t/59833

## Mike Hommey, 2023-06-03 00:28

Subject: [PATCH] Fix memory leak in get_reachable_subset
Message-ID: <20230603002819.1122129-1-mh@glandium.org>
URL: https://gitlist.dev/e/20230603002819.1122129-1-mh%40glandium.org

```
Signed-off-by: Mike Hommey <mh@glandium.org>
---
 commit-reach.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/commit-reach.c b/commit-reach.c
index 70bde8af05..f15d84566b 100644
--- a/commit-reach.c
+++ b/commit-reach.c
@@ -944,6 +944,8 @@ struct commit_list *get_reachable_subset(struct commit **from, int nr_from,
 		}
 	}
 
+	clear_prio_queue(&queue);
+
 	clear_commit_marks_many(nr_to, to, PARENT1);
 	clear_commit_marks_many(nr_from, from, PARENT2);
 
-- 
2.41.0.6.ge371d37104


```

## Junio C Hamano, 2023-06-03 02:02

Subject: Re: [PATCH] Fix memory leak in get_reachable_subset
Message-ID: <xmqqedmt7167.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqedmt7167.fsf%40gitster.g
In-Reply-To: <20230603002819.1122129-1-mh@glandium.org>

```
Mike Hommey <mh@glandium.org> writes:

> Signed-off-by: Mike Hommey <mh@glandium.org>
> ---

As most lines in the affected function seems to come from your
fcb2c076 (commit-reach: implement get_reachable_subset, 2018-11-02),
I'll redirect the review of this patch to you.

Thanks.

>  commit-reach.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/commit-reach.c b/commit-reach.c
> index 70bde8af05..f15d84566b 100644
> --- a/commit-reach.c
> +++ b/commit-reach.c
> @@ -944,6 +944,8 @@ struct commit_list *get_reachable_subset(struct commit **from, int nr_from,
>  		}
>  	}
>  
> +	clear_prio_queue(&queue);
> +
>  	clear_commit_marks_many(nr_to, to, PARENT1);
>  	clear_commit_marks_many(nr_from, from, PARENT2);

```

## René Scharfe, 2023-06-03 06:02

Subject: Re: [PATCH] Fix memory leak in get_reachable_subset
Message-ID: <21d3f105-ed32-e397-a1fe-53344894bd44@web.de>
URL: https://gitlist.dev/e/21d3f105-ed32-e397-a1fe-53344894bd44%40web.de
In-Reply-To: <xmqqedmt7167.fsf@gitster.g>

```
Am 03.06.23 um 04:02 schrieb Junio C Hamano:
> Mike Hommey <mh@glandium.org> writes:
>
>> Signed-off-by: Mike Hommey <mh@glandium.org>
>> ---
>
> As most lines in the affected function seems to come from your
> fcb2c076 (commit-reach: implement get_reachable_subset, 2018-11-02),
> I'll redirect the review of this patch to you.

Stolee reviewed it already when the patch was sent the first time, here:
https://lore.kernel.org/git/20230421234409.1925489-1-mh@glandium.org/T/#u

>
> Thanks.
>
>>  commit-reach.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/commit-reach.c b/commit-reach.c
>> index 70bde8af05..f15d84566b 100644
>> --- a/commit-reach.c
>> +++ b/commit-reach.c
>> @@ -944,6 +944,8 @@ struct commit_list *get_reachable_subset(struct commit **from, int nr_from,
>>  		}
>>  	}
>>
>> +	clear_prio_queue(&queue);

Makes sense: The loop that dequeues would end before consuming all items
when all "to" commits are found to be reachable.

>> +
>>  	clear_commit_marks_many(nr_to, to, PARENT1);
>>  	clear_commit_marks_many(nr_from, from, PARENT2);


```

## Junio C Hamano, 2023-06-04 04:42

Subject: Re: [PATCH] Fix memory leak in get_reachable_subset
Message-ID: <xmqq7csj6dok.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqq7csj6dok.fsf%40gitster.g
In-Reply-To: <21d3f105-ed32-e397-a1fe-53344894bd44@web.de>

```
René Scharfe <l.s.r@web.de> writes:

> Stolee reviewed it already when the patch was sent the first time, here:
> https://lore.kernel.org/git/20230421234409.1925489-1-mh@glandium.org/T/#u

OK.  Thanks.

```

## Derrick Stolee, 2023-06-05 15:50

Subject: Re: [PATCH] Fix memory leak in get_reachable_subset
Message-ID: <221ddd01-c058-dd87-9f3f-25146770f606@github.com>
URL: https://gitlist.dev/e/221ddd01-c058-dd87-9f3f-25146770f606%40github.com
In-Reply-To: <xmqq7csj6dok.fsf@gitster.g>

```
On 6/4/2023 12:42 AM, Junio C Hamano wrote:
> René Scharfe <l.s.r@web.de> writes:
> 
>> Stolee reviewed it already when the patch was sent the first time, here:
>> https://lore.kernel.org/git/20230421234409.1925489-1-mh@glandium.org/T/#u
> 
> OK.  Thanks.

Thanks for finding this link. I saw this patch and immediately thought,
"I made this mistake a _second_ time?"

The patch continues to look good to me.

Thanks,
-Stolee

```
