<div dir="ltr">Hi Even,<div><br></div><div>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?<br><div class="gmail_extra"><br><br>
<div class="gmail_quote">On Tue, Aug 12, 2014 at 9:48 AM, Even Rouault <span dir="ltr"><<a href="mailto:even.rouault@mines-paris.org" target="_blank">even.rouault@mines-paris.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Jorge,<br>
<br>
I don't see anything obviously wrong. Looking at the places where the variables<br>
might be nullified and running Valgrind would be my best advice.<br>
Just wanted to mention that in the likely simplified below snippet, you would<br>
leak memory.<br>
<span class="HOEnZb"><font color="#888888"><br>
Even<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
> Hello,<br>
><br>
> I have a stupid mistake in my code. This is the problem (very simplified):<br>
><br>
> postgisrasterdataset.cpp<br>
><br>
> PostGISRasterDataset::IRasterIO(....)<br>
> {<br>
> // Two attributes of my class, that inherits from GDALDataset<br>
> pszAttribute = CPLStrdup("foo");<br>
> pszAttribute2 = CPLStrdup("bar");<br>
><br>
> // Just delegates in default implementation<br>
> return GDALDataset::IRasterIO(...);<br>
> }<br>
><br>
><br>
> postgisrasterrasterband.cpp<br>
><br>
> PostGISRasterRasterBand::IRasterIO(....)<br>
> {<br>
> // Get pointer to dataset this rasterband belongs to<br>
> PostGISRasterDataset * poRDS = (PostGISRasterDataset *)poDS;<br>
><br>
> // Do some stuff with poRDS->pszAttribute and poRDS->pszAttribute2<br>
> // They're private vars, but PostGISRasterRasterBand and<br>
> // PostGISRasterDataset are friends. No problem here.<br>
><br>
> // Delegates in default implementation. So, this will result, at the<br>
> end, in calls<br>
> // to my implementation of IReadBlock / IWriteBlock<br>
> return GDALRasterBand::IRasterIO(...);<br>
> }<br>
><br>
><br>
> PostGISRasterRasterBand::IWriteBlock(...)<br>
> {<br>
> // Get pointer to dataset this rasterband belongs to<br>
> PostGISRasterDataset * poRDS = (PostGISRasterDataset *)poDS;<br>
><br>
> // Try to work with poRDS->pszAttribute and poRDS->pszAttribute2, but<br>
> // fails because they are NULL. Why??<br>
> }<br>
><br>
> Weirdest thing is the rest of cuestom attributes of my PostGISRasterDataset<br>
> class are accessible. And, of course, the poRDS pointer is always the same<br>
> (same mem address). Only problem is with those char * attributes. Looks<br>
> like they're freed at some point (or I'm doing something really wrong from<br>
> the point of view of C++, and I deserve a severe punishment for that).<br>
><br>
> Any clues?<br>
><br>
> Best regards,<br>
><br>
> --<br>
> Jorge Arevalo<br>
><br>
> <a href="http://about.me/jorgeas80" target="_blank">http://about.me/jorgeas80</a><br>
><br>
<br>
<br>
</div></div></blockquote></div><br><br></div></div></div>