changeset 1089:5e31d36910b3

Fix a memory leak with DilloImage structures
author Hofmann Johannes <Johannes.Hofmann@gmx.de>
date Sun, 10 May 2009 13:44:38 -0400
parents 8c7cf8e29325
children ea72d116c3e2
files src/dicache.c src/html.cc src/image.cc
diffstat 3 files changed, 7 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/dicache.c	Sat May 09 09:53:26 2009 -0400
+++ b/src/dicache.c	Sun May 10 13:44:38 2009 -0400
@@ -403,11 +403,10 @@
 
    dReturn_val_if_fail(MimeType && Ptr, NULL);
 
-   if (!web->Image)
+   if (!web->Image) {
       web->Image = a_Image_new(NULL, web->bgColor);
-
-   /* Add an extra reference to the Image (for dicache usage) */
-   a_Image_ref(web->Image);
+      a_Image_ref(web->Image);
+   }
 
    DicEntry = a_Dicache_get_entry(web->url, DIC_Last);
    if (!DicEntry) {
--- a/src/html.cc	Sat May 09 09:53:26 2009 -0400
+++ b/src/html.cc	Sun May 10 13:44:38 2009 -0400
@@ -294,6 +294,7 @@
    DilloLinkImage *li = dNew(DilloLinkImage, 1);
    li->url = *url;
    li->image = image;
+   a_Image_ref(image);
 
    int ni = html->images->size();
    html->images->increase();
@@ -677,6 +678,7 @@
       if (images->get(i)->image) {
          if ((!pattern) || (!a_Url_cmp(images->get(i)->url, pattern))) {
             Html_load_image(bw, images->get(i)->url, images->get(i)->image);
+            a_Image_unref (images->get(i)->image);
             images->get(i)->image = NULL;  // web owns it now
          }
       }
@@ -2092,6 +2094,7 @@
    Web = a_Web_new(url);
    Web->bw = bw;
    Web->Image = Image;
+   a_Image_ref(Image);
    Web->flags |= WEB_Image;
    /* Request image data from the cache */
    if ((ClientKey = a_Capi_open_url(Web, NULL, NULL)) != 0) {
--- a/src/image.cc	Sat May 09 09:53:26 2009 -0400
+++ b/src/image.cc	Sun May 10 13:44:38 2009 -0400
@@ -46,7 +46,7 @@
    Image->BitVec = NULL;
    Image->State = IMG_Empty;
 
-   Image->RefCount = 1;
+   Image->RefCount = 0;
 
    return Image;
 }
@@ -120,6 +120,5 @@
 void a_Image_close(DilloImage *Image)
 {
    _MSG("a_Image_close\n");
-   a_Image_unref(Image);
 }