Quantcast
Viewing all articles
Browse latest Browse all 2341

Commented Unassigned: Memory leak in CMapView::LoadMapState [24898]

There is a memory leak in `CMapView::LoadMapState()` method. The `CPLXMLNode* node` that gets allocated during XML parsing is never free'd.

I suggest to insert a call to `CPLDestroyXMLNode(node);` right before returning the parse result:
``` C++
// *********************************************************
// LoadMapState()
// *********************************************************
VARIANT_BOOL CMapView::LoadMapState(LPCTSTR Filename, IDispatch* Callback)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());

try
{
CPLXMLNode* node = CPLParseXMLFile(Filename);
if (node)
{
IStopExecution* cb = NULL;
if (Callback)
{
Callback->QueryInterface(IID_IStopExecution, (void**)&cb);
}

bool result = DeserializeMapStateCore(node, Filename, VARIANT_TRUE, cb);

if (cb)
{
cb->Release();
}
CPLDestroyXMLNode(node);
return result ? VARIANT_TRUE : VARIANT_FALSE;
}
else
{
return VARIANT_FALSE;
}
}
catch(...)
{
return VARIANT_FALSE;
}
}
```
Comments: ** Comment from web user: fjkaiser **

A similar memory leak exists in `CMapView::SaveMapState()` method.

The sugggested sollutin looks as follows:

``` C++
// *********************************************************
// SaveMapState()
// *********************************************************
VARIANT_BOOL CMapView::SaveMapState(LPCTSTR Filename, VARIANT_BOOL RelativePaths, VARIANT_BOOL Overwrite)
{
...
CPLXMLNode* node = SerializeMapStateCore(RelativePaths, Filename);
VARIANT_BOOL bResult = CPLSerializeXMLTreeToFile(node, Filename) ? VARIANT_TRUE : VARIANT_FALSE;
CPLDestroyXMLNode(node);
return bResult;
}
```


Viewing all articles
Browse latest Browse all 2341

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>