<div dir="auto">Seems like it would depend on what you're doing with the pointer after you return it.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Aug 1, 2020, 5:50 AM Andrew C Aitchison <<a href="mailto:andrew@aitchison.me.uk">andrew@aitchison.me.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
I would like to define GetSpatialRef() for my raster driver as something like:<br>
<br>
const OGRSpatialReference* GetSpatialRef() const override {<br>
OGRSpatialReference* poSRS = new OGRSpatialReference();<br>
if (poSRS->importFromEPSGA(27700)!=OGRERR_NONE)<br>
{<br>
delete poSRS;<br>
poSRS = nullptr;<br>
}<br>
return poSRS;<br>
}<br>
<br>
Unfortunately, valgrid reports that this leaks in the "new"<br>
on the line<br>
OGRSpatialReference* poSRS = new OGRSpatialReference();<br>
<br>
On the other hand,<br>
<br>
const OGRSpatialReference* GetSpatialRef() const override {<br>
return new OGRSpatialReference("EPSG:27700");<br>
}<br>
<br>
is no better:<br>
==117785==<br>
==117785== HEAP SUMMARY:<br>
==117785== in use at exit: 5,764 bytes in 24 blocks<br>
==117785== total heap usage: 7,363 allocs, 7,339 frees, 1,213,218 bytes allocated<br>
==117785==<br>
==117785== Searching for pointers to 24 not-freed blocks<br>
==117785== Checked 3,635,216 bytes<br>
==117785==<br>
==117785== 596 (16 direct, 580 indirect) bytes in 1 blocks are definitely lost in loss record 14 of 16<br>
==117785== at 0x483BE63: operator new(unsigned long) (vg_replace_malloc.c:344)<br>
==117785== by 0x5E1D765: VRCDataset::GetSpatialRef() const (VRC.h:154)<br>
==117785== by 0x4ED723A: GDALInfo (gdalinfo_lib.cpp:333)<br>
==117785== by 0x10954D: main (gdalinfo_bin.cpp:213)<br>
==117785==<br>
==117785== 596 (16 direct, 580 indirect) bytes in 1 blocks are definitely lost in loss record 15 of 16<br>
==117785== at 0x483BE63: operator new(unsigned long) (vg_replace_malloc.c:344)<br>
==117785== by 0x5E1D765: VRCDataset::GetSpatialRef() const (VRC.h:154)<br>
==117785== by 0x4ED9203: GDALInfo (gdalinfo_lib.cpp:578)<br>
==117785== by 0x10954D: main (gdalinfo_bin.cpp:213)<br>
==117785==<br>
==117785== LEAK SUMMARY:<br>
==117785== definitely lost: 32 bytes in 2 blocks<br>
==117785== indirectly lost: 1,160 bytes in 10 blocks<br>
==117785== possibly lost: 0 bytes in 0 blocks<br>
==117785== still reachable: 4,572 bytes in 12 blocks<br>
==117785== suppressed: 0 bytes in 0 blocks<br>
<br>
This is with both gdal 3.0.4 and 3.1.2 on Ubunto 20.04.<br>
<br>
-- <br>
Andrew C. Aitchison Kendal, UK<br>
<a href="mailto:andrew@aitchison.me.uk" target="_blank" rel="noreferrer">andrew@aitchison.me.uk</a><br>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank" rel="noreferrer">gdal-dev@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" rel="noreferrer noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a></blockquote></div>