Opened 19 years ago
Last modified 19 years ago
#810 closed defect (invalid)
Memory Leaks when delete GDALDriver Object
Reported by: | Owned by: | warmerdam | |
---|---|---|---|
Priority: | high | Milestone: | |
Component: | GDAL_Raster | Version: | unspecified |
Severity: | major | Keywords: | |
Cc: |
Description
[VC++ 6.0][Windows 2000] I created my own dataset with its driver (ex: MyDataset) MyDataset is ok. I made the register function as shown in the tutorial jdemdataset.cpp void GDALRegister_MyDriver() { GDALDriver *poDriver; if(GDALGetDriverByName("MyFormat") == NULL) { ... } } I don't add my driver to GDAL Tree In my main function I wrote void main () { GDALRegister_MyDriver(); ... GDALDestroyDriverManager(); /* Bug ? */ } In debug mode I trace the execution If I don't use the GDALDestroyDriverManager, there is no error but a MemoryLeaks because the GDALDriver Object is not released. If I use this function, I have an error when the function deletes the driver object. (extract: gdaldrivermanager.cpp) GDALDriverManager::~GDALDriverManager() { /* -------------------------------------------------------------------- */ /* Destroy the existing drivers. */ /* -------------------------------------------------------------------- */ while( GetDriverCount() > 0 ) { GDALDriver *poDriver = GetDriver(0); DeregisterDriver(poDriver); delete poDriver; } ... delete poDriver occurs an error: HEAP[TestGDAL.exe]: Invalid Address specified to RtlFreeHeap( 370000, 972968 ) I made another test #include "gdal_priv.h" void main() { GDALDriver *poDriver = new GDALDriver(); if(poDriver) delete poDriver; } I have the same error on delete poDriver Could you help me to resolve this problem ? Thanks. --------------------------- Christophe Sandri.
Change History (2)
comment:2 by , 19 years ago
Thanks Frank, I tried the /MD parameter and it seems to run correctly now. For more informations, I used another way to solve that problem I wrote an herited class from GDALDriver class MyDriver : public GDALDriver { // An empty class }; In the register function, ... void GDALRegister_MyDriver(void) { GDALDriver *poDriver; if(GDALGetDriverByName("MyFormat") == NULL) { poDriver = new MyDriver(); ... } } When the GDALDestroyDriverManager function is called, there is no more Invalid Address specified. My way seems to work but I prefer your solution that looks like cleaner. Thanks
Note:
See TracTickets
for help on using tickets.