diff options
author | Matthias Clasen <matthiasc@src.gnome.org> | 2002-09-03 23:43:21 +0000 |
---|---|---|
committer | Matthias Clasen <matthiasc@src.gnome.org> | 2002-09-03 23:43:21 +0000 |
commit | 8abdfd3dcc391ccfc354278db57bd57a143b0bfe (patch) | |
tree | c65b8808a923cb6148adb38720aa864cf6ec0e3f /gdk-pixbuf/io-ico.c | |
parent | 6cfd71b8d03323772e6e25dafc98c0fe58e4cd0d (diff) | |
download | gtk+-8abdfd3dcc391ccfc354278db57bd57a143b0bfe.tar.gz |
Don't leak memory if g_try_realloc fails.
* io-tga.c (io_buffer_append):
* io-ico.c (DecodeHeader):
* io-bmp.c (grow_buffer): Don't leak memory if g_try_realloc fails.
* gdk-pixbuf-io.c (pixbuf_check_ico): Fix loading of .CUR files.
(#91826)
Diffstat (limited to 'gdk-pixbuf/io-ico.c')
-rw-r--r-- | gdk-pixbuf/io-ico.c | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/gdk-pixbuf/io-ico.c b/gdk-pixbuf/io-ico.c index 3f593740cf..69fea54d1b 100644 --- a/gdk-pixbuf/io-ico.c +++ b/gdk-pixbuf/io-ico.c @@ -147,7 +147,6 @@ struct ico_progressive_state { 1 = 1 bit bitonal */ - struct headerpair Header; /* Decoded (BE->CPU) header */ gint DIBoffset; @@ -199,20 +198,21 @@ static void DecodeHeader(guchar *Data, gint Bytes, gint I; /* Step 1: The ICO header */ - + IconCount = (Data[5] << 8) + (Data[4]); State->HeaderSize = 6 + IconCount*16; if (State->HeaderSize>State->BytesInHeaderBuf) { - State->HeaderBuf=g_try_realloc(State->HeaderBuf,State->HeaderSize); - if (!State->HeaderBuf) { + guchar *tmp=g_try_realloc(State->HeaderBuf,State->HeaderSize); + if (!tmp) { g_set_error (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY, _("Not enough memory to load icon")); return; } + State->HeaderBuf = tmp; State->BytesInHeaderBuf = State->HeaderSize; } if (Bytes < State->HeaderSize) @@ -261,14 +261,15 @@ static void DecodeHeader(guchar *Data, gint Bytes, State->HeaderSize = State->DIBoffset + 40; /* 40 = sizeof(InfoHeader) */ if (State->HeaderSize>State->BytesInHeaderBuf) { - State->HeaderBuf=g_try_realloc(State->HeaderBuf,State->HeaderSize); - if (!State->HeaderBuf) { + guchar *tmp=g_try_realloc(State->HeaderBuf,State->HeaderSize); + if (!tmp) { g_set_error (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY, _("Not enough memory to load icon")); return; } + State->HeaderBuf = tmp; State->BytesInHeaderBuf = State->HeaderSize; } if (Bytes<State->HeaderSize) @@ -279,7 +280,6 @@ static void DecodeHeader(guchar *Data, gint Bytes, #ifdef DUMPBIH DumpBIH(BIH); #endif - /* Add the palette to the headersize */ State->Header.width = @@ -301,14 +301,12 @@ static void DecodeHeader(guchar *Data, gint Bytes, _("Icon has zero height")); return; } - State->Header.depth = (BIH[15] << 8) + (BIH[14]);; + State->Header.depth = (BIH[15] << 8) + (BIH[14]); State->Type = State->Header.depth; if (State->Lines>=State->Header.height) State->Type = 1; /* The transparency mask is 1 bpp */ - - /* Determine the palette size. If the header indicates 0, it is actually the maximum for the bpp. You have to love the guys who made the spec. */ @@ -324,14 +322,15 @@ static void DecodeHeader(guchar *Data, gint Bytes, State->HeaderSize+=I; if (State->HeaderSize>State->BytesInHeaderBuf) { - State->HeaderBuf=g_try_realloc(State->HeaderBuf,State->HeaderSize); - if (!State->HeaderBuf) { + guchar *tmp=g_try_realloc(State->HeaderBuf,State->HeaderSize); + if (!tmp) { g_set_error (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY, _("Not enough memory to load icon")); return; } + State->HeaderBuf = tmp; State->BytesInHeaderBuf = State->HeaderSize; } if (Bytes < State->HeaderSize) @@ -487,7 +486,7 @@ gboolean gdk_pixbuf__ico_image_stop_load(gpointer data, */ g_return_val_if_fail(context != NULL, TRUE); - + context_free (context); return TRUE; } @@ -691,7 +690,7 @@ static void OneLineTransp(struct ico_progressive_state *context) Bit = Bit & 1; /* The joys of having a BGR byteorder */ Pixels[X * 4 + 3] = 255-Bit*255; -#if 0 +#if 0 if (Bit){ Pixels[X*4+0] = 255; Pixels[X*4+1] = 255; |