added 1 changeset to branch 'refs/remotes/axeld-github/background' old head: af954b5cb2f3e9585dc4f2227f2612aaa66cf542 new head: a0cdf78ec7d0f7ee6088298747abbaf6c6d525b0 overview: https://github.com/axeld/haiku/compare/af954b5...a0cdf78 ---------------------------------------------------------------------------- a0cdf78: app_server: The client memory allocator is now reference counted. * Not sure if cursors could also have triggered this, but with the Desktop bitmaps, the memory allocator needs to stay alive as long as the bitmap is alive. * This fixes an immediate crash after setbackground returns. * However, this may also reveal cases of memory that is not freed correctly. [ Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> ] ---------------------------------------------------------------------------- Commit: a0cdf78ec7d0f7ee6088298747abbaf6c6d525b0 Author: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> Date: Sat Mar 9 11:54:02 2013 UTC ---------------------------------------------------------------------------- 4 files changed, 18 insertions(+), 9 deletions(-) src/servers/app/ClientMemoryAllocator.cpp | 7 ++++++- src/servers/app/ClientMemoryAllocator.h | 5 +++-- src/servers/app/ServerApp.cpp | 9 +++++---- src/servers/app/ServerApp.h | 6 ++++-- ---------------------------------------------------------------------------- diff --git a/src/servers/app/ClientMemoryAllocator.cpp b/src/servers/app/ClientMemoryAllocator.cpp index 8f3001d..168e511 100644 --- a/src/servers/app/ClientMemoryAllocator.cpp +++ b/src/servers/app/ClientMemoryAllocator.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2006-2012, Haiku, Inc. All Rights Reserved. + * Copyright 2006-2013, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -300,6 +300,7 @@ ClientMemoryAllocator::_AllocateChunk(size_t size, bool& newArea) ClientMemory::ClientMemory() : + fAllocator(NULL), fBlock(NULL) { } @@ -309,6 +310,8 @@ ClientMemory::~ClientMemory() { if (fBlock != NULL) fAllocator->Free(fBlock); + if (fAllocator != NULL) + fAllocator->ReleaseReference(); } @@ -317,6 +320,8 @@ ClientMemory::Allocate(ClientMemoryAllocator* allocator, size_t size, bool& newArea) { fAllocator = allocator; + fAllocator->AcquireReference(); + return fAllocator->Allocate(size, &fBlock, newArea); } diff --git a/src/servers/app/ClientMemoryAllocator.h b/src/servers/app/ClientMemoryAllocator.h index 7af6f3a..e2b94f8 100644 --- a/src/servers/app/ClientMemoryAllocator.h +++ b/src/servers/app/ClientMemoryAllocator.h @@ -1,5 +1,5 @@ /* - * Copyright 2006-2010, Haiku, Inc. All Rights Reserved. + * Copyright 2006-2013, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -10,6 +10,7 @@ #include <Locker.h> +#include <Referenceable.h> #include <util/DoublyLinkedList.h> @@ -34,7 +35,7 @@ typedef DoublyLinkedList<block> block_list; typedef DoublyLinkedList<chunk> chunk_list; -class ClientMemoryAllocator { +class ClientMemoryAllocator : public BReferenceable { public: ClientMemoryAllocator(ServerApp* application); ~ClientMemoryAllocator(); diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp index c8ce97a..05c84c6 100644 --- a/src/servers/app/ServerApp.cpp +++ b/src/servers/app/ServerApp.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2012, Haiku. + * Copyright 2001-2013, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -103,7 +103,7 @@ ServerApp::ServerApp(Desktop* desktop, port_id clientReplyPort, fViewCursor(NULL), fCursorHideLevel(0), fIsActive(false), - fMemoryAllocator(this) + fMemoryAllocator(new ClientMemoryAllocator(this)) { if (fSignature == "") fSignature = "application/no-signature"; @@ -201,6 +201,7 @@ ServerApp::~ServerApp() fPictureMap.begin()->second->SetOwner(NULL); fDesktop->GetCursorManager().DeleteCursors(fClientTeam); + fMemoryAllocator->ReleaseReference(); STRACE(("ServerApp %s::~ServerApp(): Exiting\n", Signature())); } @@ -562,7 +563,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) break; case AS_DUMP_ALLOCATOR: - fMemoryAllocator.Dump(); + fMemoryAllocator->Dump(); break; case AS_DUMP_BITMAPS: { @@ -724,7 +725,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link) if (link.Read<int32>(&screenID) == B_OK) { // TODO: choose the right HWInterface with regards to the // screenID - bitmap = gBitmapManager->CreateBitmap(&fMemoryAllocator, + bitmap = gBitmapManager->CreateBitmap(fMemoryAllocator, *fDesktop->HWInterface(), frame, colorSpace, flags, bytesPerRow, screenID, &allocationFlags); } diff --git a/src/servers/app/ServerApp.h b/src/servers/app/ServerApp.h index 84c88af..433ea47 100644 --- a/src/servers/app/ServerApp.h +++ b/src/servers/app/ServerApp.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2012, Haiku. + * Copyright 2001-2013, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -38,6 +38,7 @@ namespace BPrivate { class PortLink; }; + class ServerApp : public MessageLooper { public: ServerApp(Desktop* desktop, @@ -156,7 +157,8 @@ private: bool fIsActive; - ClientMemoryAllocator fMemoryAllocator; + ClientMemoryAllocator* fMemoryAllocator; }; + #endif // SERVER_APP_H