Date: Mon, 19 Jun 2006 17:04:35 +0300 From: Ville-Pertti Keinonen <will@exomi.com> To: Jason Evans <jasone@FreeBSD.org> Cc: freebsd-current@freebsd.org, Krassimir Slavchev <krassi@bulinfo.net> Subject: Re: memory leak in free() Message-ID: <0D175ABD-B494-48BD-9DBD-349DE3712913@exomi.com> In-Reply-To: <449048C7.6090109@FreeBSD.org> References: <448FC3AF.9060606@bulinfo.net> <200606141023.51185.jhb@freebsd.org> <449048C7.6090109@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Jun 14, 2006, at 8:35 PM, Jason Evans wrote: > Incidentally, this isn't an issue on 64-bit systems, since only mmap > () is used to request memory from the kernel. The test does seem to leak memory on 64-bit systems, though; not the actual allocated bits, but support structures, namely nodes that chunk_dealloc tries to insert into old_chunks but fails because a node holding that address is already there. It should be possible to fix this either by removing any nodes within range from old_chunks when allocating "new" memory, or by checking the return value of RB_INSERT in chunk_dealloc, and deallocating the new node if it returns non-NULL. A patch implementing the latter that seems to work: --- malloc.c 10 May 2006 00:07:45 -0000 1.126 +++ malloc.c 19 Jun 2006 13:58:57 -0000 @@ -1370,7 +1370,8 @@ node->chunk = (void *)((uintptr_t)chunk + (uintptr_t) offset); node->size = chunk_size; - RB_INSERT(chunk_tree_s, &old_chunks, node); + if (RB_INSERT(chunk_tree_s, &old_chunks, node) != NULL) + base_chunk_node_dealloc(node); } #ifdef USE_BRK
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?0D175ABD-B494-48BD-9DBD-349DE3712913>