Opened 12 years ago

Closed 12 years ago

#2553 closed defect (fixed)

Mismatched free() / delete / delete [] in grib driver and a couple of memory leaks

Reported by: winkey Owned by: warmerdam
Priority: normal Milestone:
Component: default Version: unspecified
Severity: normal Keywords:
Cc:

Description

rush@winkey ~ $ valgrind --leak-check=full --show-reachable=yes gdalinfo gfs.t06z.pgrb2f00

==14936== Mismatched free() / delete / delete []
==14936==    at 0x402364C: free (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==14936==    by 0x41D9780: GRIBRasterBand::~GRIBRasterBand() (gribdataset.cpp:226)
==14936==    by 0x42E7284: GDALDataset::~GDALDataset() (gdaldataset.cpp:147)
==14936==    by 0x42F243D: GDALPamDataset::~GDALPamDataset() (gdalpamdataset.cpp:146)
==14936==    by 0x41D94E1: GRIBDataset::~GRIBDataset() (gribdataset.cpp:260)
==14936==    by 0x42E5FB1: GDALClose (gdaldataset.cpp:1920)
==14936==    by 0x804B153: main (gdalinfo.c:659)
==14936==  Address 0x570aed0 is 0 bytes inside a block of size 736 alloc'd
==14936==    at 0x4024284: operator new(unsigned) (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==14936==    by 0x41D991C: GRIBRasterBand::ReadGribData(DataSource&, int, int, double**, grib_MetaData**) (gribdataset.cpp:206)
==14936==    by 0x41D9D2B: GRIBDataset::Open(GDALOpenInfo*) (gribdataset.cpp:351)
==14936==    by 0x42E60C3: GDALOpen (gdaldataset.cpp:1774)
==14936==    by 0x8049F96: main (gdalinfo.c:147)
==14936== 
==14936== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 7 from 1)
==14936== malloc/free: in use at exit: 312 bytes in 10 blocks.
==14936== malloc/free: 13,837 allocs, 13,827 frees, 14,176,024 bytes allocated.
==14936== For counts of detected errors, rerun with: -v
==14936== searching for pointers to 10 not-freed blocks.
==14936== checked 1,020,676 bytes.
==14936== 
==14936== 
==14936== 1 bytes in 1 blocks are definitely lost in loss record 1 of 8
==14936==    at 0x4023AA8: malloc (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==14936==    by 0x52F60EF: strdup (in /lib/libc-2.7.so)
==14936==    by 0x4310B9C: VSIStrdup (cpl_vsisimple.cpp:311)
==14936==    by 0x43022CF: CPLStrdup (cpl_conv.cpp:228)
==14936==    by 0x41D9654: GRIBDataset::GRIBDataset() (gribdataset.cpp:239)
==14936==    by 0x41D9BE2: GRIBDataset::Open(GDALOpenInfo*) (gribdataset.cpp:315)
==14936==    by 0x42E60C3: GDALOpen (gdaldataset.cpp:1774)
==14936==    by 0x8049F96: main (gdalinfo.c:147)
==14936== 
==14936== 
==14936== 4 bytes in 1 blocks are definitely lost in loss record 2 of 8
==14936==    at 0x4023AA8: malloc (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==14936==    by 0x424E8DD: ParseElemName (metaname.cpp:1814)
==14936==    by 0x4251DF6: MetaParse (metaparse.cpp:1836)
==14936==    by 0x4199ADF: ReadGrib2Record (degrib2.cpp:1063)
==14936==    by 0x41D99A2: GRIBRasterBand::ReadGribData(DataSource&, int, int, double**, grib_MetaData**) (gribdataset.cpp:209)
==14936==    by 0x41D9D2B: GRIBDataset::Open(GDALOpenInfo*) (gribdataset.cpp:351)
==14936==    by 0x42E60C3: GDALOpen (gdaldataset.cpp:1774)
==14936==    by 0x8049F96: main (gdalinfo.c:147)
==14936== 
==14936== 
==14936== 10 bytes in 1 blocks are definitely lost in loss record 3 of 8
==14936==    at 0x4023B7E: realloc (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==14936==    by 0x4262206: AllocSprintf (myerror.c:229)
==14936==    by 0x42629AF: reallocSprintf (myerror.c:343)
==14936==    by 0x424DDB4: ParseLevelName (metaname.cpp:2502)
==14936==    by 0x42518E7: MetaParse (metaparse.cpp:1904)
==14936==    by 0x4199ADF: ReadGrib2Record (degrib2.cpp:1063)
==14936==    by 0x41D99A2: GRIBRasterBand::ReadGribData(DataSource&, int, int, double**, grib_MetaData**) (gribdataset.cpp:209)
==14936==    by 0x41D9D2B: GRIBDataset::Open(GDALOpenInfo*) (gribdataset.cpp:351)
==14936==    by 0x42E60C3: GDALOpen (gdaldataset.cpp:1774)
==14936==    by 0x8049F96: main (gdalinfo.c:147)
==14936== 
==14936== 
==14936== 20 bytes in 1 blocks are definitely lost in loss record 4 of 8
==14936==    at 0x4022BCE: calloc (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==14936==    by 0x41C5090: g2_unpack3 (g2_unpack3.c:93)
==14936==    by 0x41C41CE: g2_getfld (g2_getfld.c:389)
==14936==    by 0x41D783E: unpk_g2ncep (grib2api.c:868)
==14936==    by 0x41D8BE3: unpk_grib2 (grib2api.c:1798)
==14936==    by 0x4199A02: ReadGrib2Record (degrib2.cpp:1039)
==14936==    by 0x41D99A2: GRIBRasterBand::ReadGribData(DataSource&, int, int, double**, grib_MetaData**) (gribdataset.cpp:209)
==14936==    by 0x41D9D2B: GRIBDataset::Open(GDALOpenInfo*) (gribdataset.cpp:351)
==14936==    by 0x42E60C3: GDALOpen (gdaldataset.cpp:1774)
==14936==    by 0x8049F96: main (gdalinfo.c:147)
==14936== 
==14936== 
==14936== 20 bytes in 1 blocks are still reachable in loss record 5 of 8
==14936==    at 0x4022BCE: calloc (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==14936==    by 0x4E5018C: (within /lib/libdl-2.7.so)
==14936==    by 0x4E4FB7B: dlopen (in /lib/libdl-2.7.so)
==14936==    by 0x4311139: CPLGetSymbol (cplgetsymbol.cpp:87)
==14936==    by 0x445A291: LoadProjLibrary() (ogrct.cpp:160)
==14936==    by 0x445AA6E: OGRCreateCoordinateTransformation(OGRSpatialReference*, OGRSpatialReference*) (ogrct.cpp:279)
==14936==    by 0x41D926A: GRIBDataset::SetMetaData(grib_MetaData*) (gribdataset.cpp:467)
==14936==    by 0x41D9D3D: GRIBDataset::Open(GDALOpenInfo*) (gribdataset.cpp:352)
==14936==    by 0x42E60C3: GDALOpen (gdaldataset.cpp:1774)
==14936==    by 0x8049F96: main (gdalinfo.c:147)
==14936== 
==14936== 
==14936== 36 bytes in 1 blocks are still reachable in loss record 6 of 8
==14936==    at 0x4023AA8: malloc (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==14936==    by 0x400C793: (within /lib/ld-2.7.so)
==14936==    by 0x4011F45: (within /lib/ld-2.7.so)
==14936==    by 0x400DED1: (within /lib/ld-2.7.so)
==14936==    by 0x40118ED: (within /lib/ld-2.7.so)
==14936==    by 0x4E4FC5B: (within /lib/libdl-2.7.so)
==14936==    by 0x400DED1: (within /lib/ld-2.7.so)
==14936==    by 0x4E5011B: (within /lib/libdl-2.7.so)
==14936==    by 0x4E4FB7B: dlopen (in /lib/libdl-2.7.so)
==14936==    by 0x4311139: CPLGetSymbol (cplgetsymbol.cpp:87)
==14936==    by 0x445A291: LoadProjLibrary() (ogrct.cpp:160)
==14936==    by 0x445AA6E: OGRCreateCoordinateTransformation(OGRSpatialReference*, OGRSpatialReference*) (ogrct.cpp:279)
==14936== 
==14936== 
==14936== 65 bytes in 3 blocks are definitely lost in loss record 7 of 8
==14936==    at 0x4023B7E: realloc (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==14936==    by 0x4262010: AllocSprintf (myerror.c:126)
==14936==    by 0x4262A00: mallocSprintf (myerror.c:301)
==14936==    by 0x424E919: ParseElemName (metaname.cpp:1817)
==14936==    by 0x4251DF6: MetaParse (metaparse.cpp:1836)
==14936==    by 0x4199ADF: ReadGrib2Record (degrib2.cpp:1063)
==14936==    by 0x41D99A2: GRIBRasterBand::ReadGribData(DataSource&, int, int, double**, grib_MetaData**) (gribdataset.cpp:209)
==14936==    by 0x41D9D2B: GRIBDataset::Open(GDALOpenInfo*) (gribdataset.cpp:351)
==14936==    by 0x42E60C3: GDALOpen (gdaldataset.cpp:1774)
==14936==    by 0x8049F96: main (gdalinfo.c:147)
==14936== 
==14936== 
==14936== 156 bytes in 1 blocks are definitely lost in loss record 8 of 8
==14936==    at 0x4023AA8: malloc (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==14936==    by 0x4310C2C: VSIMalloc (cpl_vsisimple.cpp:280)
==14936==    by 0x430252E: CPLMalloc (cpl_conv.cpp:129)
==14936==    by 0x444D3D1: OGR_SRSNode::exportToWkt(char**) const (ogr_srsnode.cpp:438)
==14936==    by 0x41D9138: GRIBDataset::SetMetaData(grib_MetaData*) (gribdataset.cpp:445)
==14936==    by 0x41D9D3D: GRIBDataset::Open(GDALOpenInfo*) (gribdataset.cpp:352)
==14936==    by 0x42E60C3: GDALOpen (gdaldataset.cpp:1774)
==14936==    by 0x8049F96: main (gdalinfo.c:147)
==14936== 
==14936== LEAK SUMMARY:
==14936==    definitely lost: 256 bytes in 8 blocks.
==14936==      possibly lost: 0 bytes in 0 blocks.
==14936==    still reachable: 56 bytes in 2 blocks.
==14936==         suppressed: 0 bytes in 0 blocks.



Change History (3)

comment:1 Changed 12 years ago by Even Rouault

I just found one remaining memory leak among the memory leaks you mention above. Fixed in trunk in r15255.

I suppose from the line numbers of your Valgrind report that you're using GDAL <= 1.5.2. The GRIB driver seems to have undergone major changes in SVN trunk (moved from spike to trunk in r13877, so most of the issues raised seem to have been fixed in GDAL 1.6.0dev)

comment:2 Changed 12 years ago by winkey

actualy i checked it out from svn less than 8 hours before i submitted it

comment:3 Changed 12 years ago by winkey

Resolution: fixed
Status: newclosed

again, second copy thanks rouault.

brian

Note: See TracTickets for help on using tickets.