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()
|
ClientMemory::ClientMemory()
|
||||||
:
|
:
|
||||||
|
fAllocator(NULL),
|
||||||
fBlock(NULL)
|
fBlock(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -325,6 +326,8 @@ ClientMemory::~ClientMemory()
|
|||||||
{
|
{
|
||||||
if (fBlock != NULL)
|
if (fBlock != NULL)
|
||||||
fAllocator->Free(fBlock);
|
fAllocator->Free(fBlock);
|
||||||
|
if (fAllocator != NULL)
|
||||||
|
fAllocator->ReleaseReference();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -333,6 +336,8 @@ ClientMemory::Allocate(ClientMemoryAllocator* allocator, size_t size,
|
|||||||
bool& newArea)
|
bool& newArea)
|
||||||
{
|
{
|
||||||
fAllocator = allocator;
|
fAllocator = allocator;
|
||||||
|
fAllocator->AcquireReference();
|
||||||
|
|
||||||
return fAllocator->Allocate(size, &fBlock, newArea);
|
return fAllocator->Allocate(size, &fBlock, newArea);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <Locker.h>
|
#include <Locker.h>
|
||||||
|
#include <Referenceable.h>
|
||||||
|
|
||||||
#include <util/DoublyLinkedList.h>
|
#include <util/DoublyLinkedList.h>
|
||||||
|
|
||||||
@@ -34,7 +35,7 @@ typedef DoublyLinkedList<block> block_list;
|
|||||||
typedef DoublyLinkedList<chunk> chunk_list;
|
typedef DoublyLinkedList<chunk> chunk_list;
|
||||||
|
|
||||||
|
|
||||||
class ClientMemoryAllocator {
|
class ClientMemoryAllocator : public BReferenceable {
|
||||||
public:
|
public:
|
||||||
ClientMemoryAllocator(ServerApp* application);
|
ClientMemoryAllocator(ServerApp* application);
|
||||||
~ClientMemoryAllocator();
|
~ClientMemoryAllocator();
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ ServerApp::ServerApp(Desktop* desktop, port_id clientReplyPort,
|
|||||||
fViewCursor(NULL),
|
fViewCursor(NULL),
|
||||||
fCursorHideLevel(0),
|
fCursorHideLevel(0),
|
||||||
fIsActive(false),
|
fIsActive(false),
|
||||||
fMemoryAllocator(this)
|
fMemoryAllocator(new ClientMemoryAllocator(this))
|
||||||
{
|
{
|
||||||
if (fSignature == "")
|
if (fSignature == "")
|
||||||
fSignature = "application/no-signature";
|
fSignature = "application/no-signature";
|
||||||
@@ -194,7 +194,7 @@ ServerApp::~ServerApp()
|
|||||||
fWindowListLock.Lock();
|
fWindowListLock.Lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
fMemoryAllocator.Detach();
|
fMemoryAllocator->Detach();
|
||||||
fMapLocker.Lock();
|
fMapLocker.Lock();
|
||||||
|
|
||||||
while (!fBitmapMap.empty())
|
while (!fBitmapMap.empty())
|
||||||
@@ -204,6 +204,7 @@ ServerApp::~ServerApp()
|
|||||||
fPictureMap.begin()->second->SetOwner(NULL);
|
fPictureMap.begin()->second->SetOwner(NULL);
|
||||||
|
|
||||||
fDesktop->GetCursorManager().DeleteCursors(fClientTeam);
|
fDesktop->GetCursorManager().DeleteCursors(fClientTeam);
|
||||||
|
fMemoryAllocator->ReleaseReference();
|
||||||
|
|
||||||
STRACE(("ServerApp %s::~ServerApp(): Exiting\n", Signature()));
|
STRACE(("ServerApp %s::~ServerApp(): Exiting\n", Signature()));
|
||||||
}
|
}
|
||||||
@@ -565,7 +566,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case AS_DUMP_ALLOCATOR:
|
case AS_DUMP_ALLOCATOR:
|
||||||
fMemoryAllocator.Dump();
|
fMemoryAllocator->Dump();
|
||||||
break;
|
break;
|
||||||
case AS_DUMP_BITMAPS:
|
case AS_DUMP_BITMAPS:
|
||||||
{
|
{
|
||||||
@@ -727,7 +728,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
|
|||||||
if (link.Read<int32>(&screenID) == B_OK) {
|
if (link.Read<int32>(&screenID) == B_OK) {
|
||||||
// TODO: choose the right HWInterface with regards to the
|
// TODO: choose the right HWInterface with regards to the
|
||||||
// screenID
|
// screenID
|
||||||
bitmap = gBitmapManager->CreateBitmap(&fMemoryAllocator,
|
bitmap = gBitmapManager->CreateBitmap(fMemoryAllocator,
|
||||||
*fDesktop->HWInterface(), frame, colorSpace, flags,
|
*fDesktop->HWInterface(), frame, colorSpace, flags,
|
||||||
bytesPerRow, screenID, &allocationFlags);
|
bytesPerRow, screenID, &allocationFlags);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2012, Haiku.
|
* Copyright 2001-2013, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -38,6 +38,7 @@ namespace BPrivate {
|
|||||||
class PortLink;
|
class PortLink;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class ServerApp : public MessageLooper {
|
class ServerApp : public MessageLooper {
|
||||||
public:
|
public:
|
||||||
ServerApp(Desktop* desktop,
|
ServerApp(Desktop* desktop,
|
||||||
@@ -156,7 +157,8 @@ private:
|
|||||||
|
|
||||||
bool fIsActive;
|
bool fIsActive;
|
||||||
|
|
||||||
ClientMemoryAllocator fMemoryAllocator;
|
ClientMemoryAllocator* fMemoryAllocator;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // SERVER_APP_H
|
#endif // SERVER_APP_H
|
||||||
|
|||||||
Reference in New Issue
Block a user