[gdal-dev] GDALDataset::CopyLayer options handling causing crash

Dirk Vanden Boer dirk.vdb at gmail.com
Tue Feb 11 12:14:20 PST 2020


I get a crash when calling the CopyLayer function.
Pseudo code:
char** options = CSLAddString(nullptr, "DST_SRSWKT=some_wkt");
ds->CopyLayer(srcLayer, "newname", options);
CSLDestroy(options);

Inside GDALDataset::CopyLayer the DST_SRSWKT option is removed from the
list:
// Remove DST_WKT from option list to prevent warning from driver.
const int nSRSPos = CSLFindName(papszOptions, "DST_SRSWKT");
papszOptions = CSLRemoveStrings(papszOptions, nSRSPos, 1, nullptr);

But since this is the only option CSLDestroy is called on the options
pointer.
So the CSLDestroy(options) after the copy causes a crash since the memory
is deleted twice.

How is this supported to be handled? How can the caller know the options
array has been destroyed by the CopyLayer function?

Kind regards,
Dirk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20200211/29f65cac/attachment.html>


More information about the gdal-dev mailing list