app_server: The client memory allocator is now reference counted.
* Not sure if cursors could also have triggered this, but the memory allocator can now outlive its ServerApp. * However, this may also reveal cases of memory that is not freed correctly.
This commit is contained in:
@@ -316,6 +316,7 @@ ClientMemoryAllocator::_AllocateChunk(size_t size, bool& newArea)
|
||||
|
||||
ClientMemory::ClientMemory()
|
||||
:
|
||||
fAllocator(NULL),
|
||||
fBlock(NULL)
|
||||
{
|
||||
}
|
||||
@@ -325,6 +326,8 @@ ClientMemory::~ClientMemory()
|
||||
{
|
||||
if (fBlock != NULL)
|
||||
fAllocator->Free(fBlock);
|
||||
if (fAllocator != NULL)
|
||||
fAllocator->ReleaseReference();
|
||||
}
|
||||
|
||||
|
||||
@@ -333,6 +336,8 @@ ClientMemory::Allocate(ClientMemoryAllocator* allocator, size_t size,
|
||||
bool& newArea)
|
||||
{
|
||||
fAllocator = allocator;
|
||||
fAllocator->AcquireReference();
|
||||
|
||||
return fAllocator->Allocate(size, &fBlock, newArea);
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -105,7 +105,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";
|
||||
@@ -194,7 +194,7 @@ ServerApp::~ServerApp()
|
||||
fWindowListLock.Lock();
|
||||
}
|
||||
|
||||
fMemoryAllocator.Detach();
|
||||
fMemoryAllocator->Detach();
|
||||
fMapLocker.Lock();
|
||||
|
||||
while (!fBitmapMap.empty())
|
||||
@@ -204,6 +204,7 @@ ServerApp::~ServerApp()
|
||||
fPictureMap.begin()->second->SetOwner(NULL);
|
||||
|
||||
fDesktop->GetCursorManager().DeleteCursors(fClientTeam);
|
||||
fMemoryAllocator->ReleaseReference();
|
||||
|
||||
STRACE(("ServerApp %s::~ServerApp(): Exiting\n", Signature()));
|
||||
}
|
||||
@@ -565,7 +566,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
|
||||
break;
|
||||
|
||||
case AS_DUMP_ALLOCATOR:
|
||||
fMemoryAllocator.Dump();
|
||||
fMemoryAllocator->Dump();
|
||||
break;
|
||||
case AS_DUMP_BITMAPS:
|
||||
{
|
||||
@@ -727,7 +728,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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user