aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHofmann Johannes <Johannes.Hofmann@gmx.de>2009-05-10 13:44:38 -0400
committerHofmann Johannes <Johannes.Hofmann@gmx.de>2009-05-10 13:44:38 -0400
commit2023266c7206c3fb456fda012ae0a4c81b69a634 (patch)
treee67d622e5a4623a5ab30fefabdc127bec0058c6b
parentfbc75f17d99ea52fd38352b165cfb2a1b8d710d0 (diff)
Fix a memory leak with DilloImage structures
-rw-r--r--src/dicache.c7
-rw-r--r--src/html.cc3
-rw-r--r--src/image.cc3
3 files changed, 7 insertions, 6 deletions
diff --git a/src/dicache.c b/src/dicache.c
index 2e5a442b..8503cf66 100644
--- a/src/dicache.c
+++ b/src/dicache.c
@@ -403,11 +403,10 @@ static void *Dicache_image(int ImgType, const char *MimeType, void *Ptr,
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) {
diff --git a/src/html.cc b/src/html.cc
index f20d8fa8..974b914c 100644
--- a/src/html.cc
+++ b/src/html.cc
@@ -294,6 +294,7 @@ static void Html_add_new_linkimage(DilloHtml *html,
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 @@ void DilloHtml::loadImages (const DilloUrl *pattern)
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 @@ static void Html_load_image(BrowserWindow *bw, DilloUrl *url,
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) {
diff --git a/src/image.cc b/src/image.cc
index 3417ed9d..653d2ea1 100644
--- a/src/image.cc
+++ b/src/image.cc
@@ -46,7 +46,7 @@ DilloImage *a_Image_new(const char *alt_text, int32_t bg_color)
Image->BitVec = NULL;
Image->State = IMG_Empty;
- Image->RefCount = 1;
+ Image->RefCount = 0;
return Image;
}
@@ -120,6 +120,5 @@ void a_Image_write(DilloImage *Image, uint_t y)
void a_Image_close(DilloImage *Image)
{
_MSG("a_Image_close\n");
- a_Image_unref(Image);
}