diff --git a/FileLoader.h b/FileLoader.h index 8ab8464..8a6cffb 100644 --- a/FileLoader.h +++ b/FileLoader.h @@ -39,13 +39,24 @@ class FileLoader data = new char[size]; _refcnt = new int; *_refcnt = 1; + m_alloced = true; + } + Buffer(char * data, int sz) + { + size = sz; + this->data = data; + m_alloced = false; } void copy(const Buffer & other) { data = other.data; size = other.size; - _refcnt = other._refcnt; - (*_refcnt)++; + m_alloced = other.m_alloced; + if (m_alloced) + { + _refcnt = other._refcnt; + (*_refcnt)++; + } } Buffer(const Buffer & other) { copy(other); } Buffer & operator=(const Buffer & other) @@ -55,15 +66,19 @@ class FileLoader } ~Buffer() { - (*_refcnt)--; - if (*_refcnt < 1) + if (m_alloced) { - delete _refcnt; - delete data; + (*_refcnt)--; + if (*_refcnt < 1) + { + delete _refcnt; + delete data; + } } } protected: int * _refcnt; + bool m_alloced; }; virtual int getSize(const Path & path) = 0;