Fixes buggy operators and memory leak in Grid class, refs #1842

This was SVN commit r13866.
This commit is contained in:
historic_bruno 2013-09-17 00:28:22 +00:00
parent 5d9b2b95b0
commit 9f2a850a95

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2011 Wildfire Games.
/* Copyright (C) 2013 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -48,7 +48,16 @@ public:
Grid(const Grid& g)
{
*this = g;
m_W = g.m_W;
m_H = g.m_H;
m_DirtyID = g.m_DirtyID;
if (g.m_Data)
{
m_Data = new T[m_W * m_H];
memcpy(m_Data, g.m_Data, m_W*m_H*sizeof(T));
}
else
m_Data = NULL;
}
Grid& operator=(const Grid& g)
@ -60,8 +69,10 @@ public:
m_DirtyID = g.m_DirtyID;
if (g.m_Data)
{
m_Data = new T[m_W * m_H];
memcpy(m_Data, g.m_Data, m_W*m_H*sizeof(T));
T* ptr = new T[m_W * m_H];
memcpy(ptr, g.m_Data, m_W*m_H*sizeof(T));
delete[] m_Data;
m_Data = ptr;
}
else
m_Data = NULL;