[mythtv] Re: Myth Theme Memory Usage
Joseph Caputo
jcaputo1 at comcast.net
Thu Dec 9 01:51:27 UTC 2004
Alan Gonzalez wrote:
> I looked at mythcontext.cpp
>
> At first glance I noticed a small memory issue that probably doesn't
> have much to do with this issue, just thought I'd mention it. This
> is in function: MythContext::CacheThemeImagesDirectory
>
> if (!cacheinfo.exists() ||
> (cacheinfo.lastModified() < fi->lastModified()))
> {
> VERBOSE(VB_FILE, QString("generating cache image for: %1")
> .arg(fi->absFilePath()));
>
> QImage *tmpimage = LoadScaleImage(fi->absFilePath(), false);
>
> if (tmpimage && tmpimage->width() > 0 && tmpimage->height() > 0)
> {
> if (!tmpimage->save(destdir + filename, "PNG"))
> {
> cerr << "Couldn't save cache cache image: "
> << d->themecachedir + filename << endl;
> }
>
> ----> take delete this out of if block
> delete tmpimage;
> }
> }
>
> This code block should have the 'delete tmpimage' outside of the if
> statement. It's ok to delete null values and it's ok to delete
> allocated values. The current implementation leaks memory if an image
> has either width or height == 0.
Actually, it's not *guaranteed* to be OK to delete a NULL pointer...
though it usually is, it's implementation-defined behavior. I usually
do the following just to be safe:
if (ptr)
{
delete ptr;
ptr = NULL;
}
-JAC
More information about the mythtv-dev
mailing list