|
Memory leak fixes in ogrfeaturesytle.cpp: msg#00163gis.gdal.devel
Frank,
I ran across
several memory leaks in ogrfeaturestyle.cpp
with a large input
file and querying the feature style string I was
getting several
thousand memory leaks.
The problem was in
two places, first in CreateStyleToolFromStyleString
it was not calling
CSLDestroy(papszToken);
Then in the
destructors of OGRStyleTool subclasses they
were
only calling CPLFree(m_pasStyleValue);
The problem with
this is m_pasStyleValue is a vector like class of
several OGRStyleValue's. Inside OGRStyleValue can be a
pointer to a
heap allocated string in
pszValue, which was the
leak.
Below are the
changes that fixed these leaks.
Thanks
Steve
Brooks
$ diff clean/gdal/ogr/ogrfeaturestyle.cpp modified/gdal/ogr/ogrfeaturestyle.cpp
432a433 > OGRStyleTool *poStyleTool = NULL; 434,447c435,447 < if (CSLCount(papszToken) <2) < return NULL; < < if (EQUAL(papszToken[0],"PEN")) < return new OGRStylePen(); < else if (EQUAL(papszToken[0],"BRUSH")) < return new OGRStyleBrush(); < else if (EQUAL(papszToken[0],"SYMBOL")) < return new OGRStyleSymbol(); < else if (EQUAL(papszToken[0],"LABEL")) < return new OGRStyleLabel(); < else < return NULL; < --- > if (CSLCount(papszToken) >= 2) > { > if (EQUAL(papszToken[0],"PEN")) > poStyleTool = new OGRStylePen(); > else if (EQUAL(papszToken[0],"BRUSH")) > poStyleTool = new OGRStyleBrush(); > else if (EQUAL(papszToken[0],"SYMBOL")) > poStyleTool = new OGRStyleSymbol(); > else if (EQUAL(papszToken[0],"LABEL")) > poStyleTool = new OGRStyleLabel(); > } > CSLDestroy(papszToken); > return poStyleTool; 1394a1395,1402 > for (int i = 0; i < OGRSTPenLast; i++) > { > if (m_pasStyleValue[i].pszValue != NULL) > { > CPLFree(m_pasStyleValue[i].pszValue); > m_pasStyleValue[i].pszValue = NULL; > } > } 1414a1423,1430 > for (int i = 0; i < OGRSTBrushLast; i++) > { > if (m_pasStyleValue[i].pszValue != NULL) > { > CPLFree(m_pasStyleValue[i].pszValue); > m_pasStyleValue[i].pszValue = NULL; > } > } 1434a1451,1458 > for (int i = 0; i < OGRSTSymbolLast; i++) > { > if (m_pasStyleValue[i].pszValue != NULL) > { > CPLFree(m_pasStyleValue[i].pszValue); > m_pasStyleValue[i].pszValue = NULL; > } > } 1455,1456c1479,1490 < CPLFree(m_pasStyleValue); < --- > if (m_pasStyleValue != NULL) > { > for (int i = 0; i < OGRSTLabelLast; i++) > { > if (m_pasStyleValue[i].pszValue != NULL) > { > CPLFree(m_pasStyleValue[i].pszValue); > m_pasStyleValue[i].pszValue = NULL; > } > } > } > CPLFree(m_pasStyleValue); |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: esri .hdr open problem; minor hdf4 channels issue: 00163, Andrey Kiselev |
|---|---|
| Next by Date: | Memory leak fix for ogrdgnlayer.cpp: 00163, Steve Brooks |
| Previous by Thread: | GDALNumeric.SaveArray : Unable to access numpy arrays of typecode "@"i: 00163, Gagan Tandon |
| Next by Thread: | Re: Memory leak fixes in ogrfeaturesytle.cpp: 00163, Frank Warmerdam |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |