diff options
author | Jorge Arellano Cid <jcid@dillo.org> | 2009-05-08 16:39:19 -0400 |
---|---|---|
committer | Jorge Arellano Cid <jcid@dillo.org> | 2009-05-08 16:39:19 -0400 |
commit | c206e5e68a1e009df93cf9175d521a4c587158d1 (patch) | |
tree | 104c2e6611501b43e93acf1b65a7c3c8f18b6bd3 /src/png.c | |
parent | 7034881b87b53b087bae78aef8380e5258f68a24 (diff) |
Fix a memory leak when stopping an image-decoding process
Diffstat (limited to 'src/png.c')
-rw-r--r-- | src/png.c | 33 |
1 files changed, 23 insertions, 10 deletions
@@ -291,15 +291,12 @@ static void Png_dataend_callback(png_structp png_ptr, png_infop info_ptr) } /* - * Finish the decoding process (and free the memory) + * Free up the resources for this image. */ -static void Png_close(DilloPng *png, CacheClient_t *Client) +static void Png_free(DilloPng *png) { - _MSG("Png_close\n"); - /* Let dicache know decoding is over */ - a_Dicache_close(png->url, png->version, Client); + MSG("Png_free %p\n", png); - /* Free up the resources for this image */ dFree(png->image_data); dFree(png->row_pointers); dFree(png->linebuf); @@ -311,6 +308,17 @@ static void Png_close(DilloPng *png, CacheClient_t *Client) } /* + * Finish the decoding process (and free the memory) + */ +static void Png_close(DilloPng *png, CacheClient_t *Client) +{ + _MSG("Png_close\n"); + /* Let dicache know decoding is over */ + a_Dicache_close(png->url, png->version, Client); + Png_free(png); +} + +/* * Receive and process new chunks of PNG image data */ static void Png_write(DilloPng *png, void *Buf, uint_t BufSize) @@ -402,12 +410,16 @@ static void Png_write(DilloPng *png, void *Buf, uint_t BufSize) * failure. This means that you can't just wait for all the data to be * presented before starting conversion and display. */ -void a_Png_callback(int Op, CacheClient_t *Client) +void a_Png_callback(int Op, void *data) { - if (Op) { /* EOF */ - Png_close(Client->CbData, Client); - } else { + if (Op == CA_Send) { + CacheClient_t *Client = data; Png_write(Client->CbData, Client->Buf, Client->BufSize); + } else if (Op == CA_Close) { + CacheClient_t *Client = data; + Png_close(Client->CbData, Client); + } else if (Op == CA_Abort) { + Png_free(data); } } @@ -417,6 +429,7 @@ void a_Png_callback(int Op, CacheClient_t *Client) void *a_Png_new(DilloImage *Image, DilloUrl *url, int version) { DilloPng *png = dNew0(DilloPng, 1); + MSG("Png_new: png=%p\n", png); png->Image = Image; png->url = url; |