Merge pull request #27618 from neikeq/fix-leak

Fix memory leak introduced in bb6814a
This commit is contained in:
Ignacio Roldán Etcheverry 2019-04-03 00:25:07 +02:00 committed by GitHub
commit f285d554e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -39,6 +39,7 @@ struct ArgumentsVector {
private: private:
T pool[POOL_SIZE]; T pool[POOL_SIZE];
T *_ptr; T *_ptr;
int size;
ArgumentsVector(); ArgumentsVector();
ArgumentsVector(const ArgumentsVector &); ArgumentsVector(const ArgumentsVector &);
@ -48,11 +49,18 @@ public:
T &get(int p_idx) { return _ptr[p_idx]; } T &get(int p_idx) { return _ptr[p_idx]; }
void set(int p_idx, const T &p_value) { _ptr[p_idx] = p_value; } void set(int p_idx, const T &p_value) { _ptr[p_idx] = p_value; }
explicit ArgumentsVector(int size) { explicit ArgumentsVector(int p_size) :
if (size <= POOL_SIZE) { size(p_size) {
if (p_size <= POOL_SIZE) {
_ptr = pool; _ptr = pool;
} else { } else {
_ptr = memnew_arr(T, size); _ptr = memnew_arr(T, p_size);
}
}
~ArgumentsVector() {
if (size > POOL_SIZE) {
memdelete_arr(_ptr);
} }
} }
}; };