[gdal-dev] Losing access to dataset variables. Am I doing something really dumb?
Jorge Arevalo
jorgearevalo at libregis.org
Tue Aug 12 01:03:38 PDT 2014
Hi Even,
Thanks for your hints. About the memory leaking, apart from the obvious
fact that CPLStrdup vars need to be freed, are you seeing something more?
On Tue, Aug 12, 2014 at 9:48 AM, Even Rouault <even.rouault at mines-paris.org>
wrote:
> Hi Jorge,
>
> I don't see anything obviously wrong. Looking at the places where the
> variables
> might be nullified and running Valgrind would be my best advice.
> Just wanted to mention that in the likely simplified below snippet, you
> would
> leak memory.
>
> Even
>
> > Hello,
> >
> > I have a stupid mistake in my code. This is the problem (very
> simplified):
> >
> > postgisrasterdataset.cpp
> >
> > PostGISRasterDataset::IRasterIO(....)
> > {
> > // Two attributes of my class, that inherits from GDALDataset
> > pszAttribute = CPLStrdup("foo");
> > pszAttribute2 = CPLStrdup("bar");
> >
> > // Just delegates in default implementation
> > return GDALDataset::IRasterIO(...);
> > }
> >
> >
> > postgisrasterrasterband.cpp
> >
> > PostGISRasterRasterBand::IRasterIO(....)
> > {
> > // Get pointer to dataset this rasterband belongs to
> > PostGISRasterDataset * poRDS = (PostGISRasterDataset *)poDS;
> >
> > // Do some stuff with poRDS->pszAttribute and poRDS->pszAttribute2
> > // They're private vars, but PostGISRasterRasterBand and
> > // PostGISRasterDataset are friends. No problem here.
> >
> > // Delegates in default implementation. So, this will result, at the
> > end, in calls
> > // to my implementation of IReadBlock / IWriteBlock
> > return GDALRasterBand::IRasterIO(...);
> > }
> >
> >
> > PostGISRasterRasterBand::IWriteBlock(...)
> > {
> > // Get pointer to dataset this rasterband belongs to
> > PostGISRasterDataset * poRDS = (PostGISRasterDataset *)poDS;
> >
> > // Try to work with poRDS->pszAttribute and poRDS->pszAttribute2, but
> > // fails because they are NULL. Why??
> > }
> >
> > Weirdest thing is the rest of cuestom attributes of my
> PostGISRasterDataset
> > class are accessible. And, of course, the poRDS pointer is always the
> same
> > (same mem address). Only problem is with those char * attributes. Looks
> > like they're freed at some point (or I'm doing something really wrong
> from
> > the point of view of C++, and I deserve a severe punishment for that).
> >
> > Any clues?
> >
> > Best regards,
> >
> > --
> > Jorge Arevalo
> >
> > http://about.me/jorgeas80
> >
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20140812/d8830119/attachment.html>
More information about the gdal-dev
mailing list