Fix memory leak in LinearAllocator used by Sample_TempObstacles

This commit is contained in:
Sander van Noort 2016-04-03 22:39:33 +02:00 committed by Jakob Botsch Nielsen
parent d7187028b2
commit b05e45492e

View File

@ -132,11 +132,11 @@ struct FastLZCompressor : public dtTileCacheCompressor
struct LinearAllocator : public dtTileCacheAlloc struct LinearAllocator : public dtTileCacheAlloc
{ {
unsigned char* buffer; unsigned char* buffer;
int capacity; size_t capacity;
int top; size_t top;
int high; size_t high;
LinearAllocator(const int cap) : buffer(0), capacity(0), top(0), high(0) LinearAllocator(const size_t cap) : buffer(0), capacity(0), top(0), high(0)
{ {
resize(cap); resize(cap);
} }
@ -146,7 +146,7 @@ struct LinearAllocator : public dtTileCacheAlloc
dtFree(buffer); dtFree(buffer);
} }
void resize(const int cap) void resize(const size_t cap)
{ {
if (buffer) dtFree(buffer); if (buffer) dtFree(buffer);
buffer = (unsigned char*)dtAlloc(cap, DT_ALLOC_PERM); buffer = (unsigned char*)dtAlloc(cap, DT_ALLOC_PERM);
@ -159,7 +159,7 @@ struct LinearAllocator : public dtTileCacheAlloc
top = 0; top = 0;
} }
virtual void* alloc(const int size) virtual void* alloc(const size_t size)
{ {
if (!buffer) if (!buffer)
return 0; return 0;