# [PATCH] update-cache --refresh cache entry leak

3 messages from 2005-04-16 to 2005-04-17. Participants: Junio C Hamano, Linus Torvalds.
Thread: https://gitlist.dev/t/55

## Junio C Hamano, 2005-04-16 22:51

Subject: [PATCH] update-cache --refresh cache entry leak
Message-ID: <7v8y3i5o8t.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v8y3i5o8t.fsf%40assigned-by-dhcp.cox.net

```
When update-cache --refresh replaces an existing cache entry
with a new one, it forgets to free the original.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
update-cache.c:  61d2b93a751f35ba24f479cd4fc151188916f02a
--- update-cache.c
+++ update-cache.c	2005-04-16 15:49:03.000000000 -0700
@@ -203,6 +203,8 @@
 			printf("%s: needs update\n", ce->name);
 			continue;
 		}
+		if (new != ce)
+			free(ce);
 		active_cache[i] = new;
 	}
 }


```

## Linus Torvalds, 2005-04-17 03:35

Subject: Re: [PATCH] update-cache --refresh cache entry leak
Message-ID: <Pine.LNX.4.58.0504162033250.7211@ppc970.osdl.org>
URL: https://gitlist.dev/e/Pine.LNX.4.58.0504162033250.7211%40ppc970.osdl.org
In-Reply-To: <7v8y3i5o8t.fsf@assigned-by-dhcp.cox.net>

```


On Sat, 16 Apr 2005, Junio C Hamano wrote:
>
> When update-cache --refresh replaces an existing cache entry
> with a new one, it forgets to free the original.

I've seen this patch now three times, and it's been wrong every single 
time. Maybe we should add a comment?

That active-cache entry you free()'d was not necessarily allocated with 
malloc(). Most cache-entries are just mmap'ed directly from the index 
file.

Leaking is ok. We cannot leak too much.

		Linus

```

## Junio C Hamano, 2005-04-17 04:44

Subject: Re: [PATCH] update-cache --refresh cache entry leak
Message-ID: <7vbr8e2erl.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vbr8e2erl.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <Pine.LNX.4.58.0504162033250.7211@ppc970.osdl.org>

```
>>>>> "LT" == Linus Torvalds <torvalds@osdl.org> writes:

LT> I've seen this patch now three times, and it's been wrong every single 
LT> time. Maybe we should add a comment?

I found out the previous two just after I sent it out.  Sorry
about that.



```
