From 6a05ab018659e89d713b5a1cef41f4798bdd90de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sun, 22 Jul 2007 23:50:34 +0000 Subject: [PATCH] My ClientMemoryAllocator implementation wasn't complete and badly leaked memory. It now at least frees all memory when the object is deleted. Reported by Jonas - thanks! git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21687 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/servers/app/ClientMemoryAllocator.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/servers/app/ClientMemoryAllocator.cpp b/src/servers/app/ClientMemoryAllocator.cpp index f9371320e8..acbab6fb92 100644 --- a/src/servers/app/ClientMemoryAllocator.cpp +++ b/src/servers/app/ClientMemoryAllocator.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku, Inc. All Rights Reserved. + * Copyright 2006-2007, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -42,6 +42,24 @@ ClientMemoryAllocator::ClientMemoryAllocator(ServerApp* application) ClientMemoryAllocator::~ClientMemoryAllocator() { + // delete all areas and chunks/blocks that are still allocated + + while (true) { + struct block* block = fFreeBlocks.RemoveHead(); + if (block == NULL) + break; + + free(block); + } + + while (true) { + struct chunk* chunk = fChunks.RemoveHead(); + if (chunk == NULL) + break; + + delete_area(chunk->area); + free(chunk); + } }