From 80d218bca71a4f5edead2f4fedb311cb56abefd5 Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Sat, 26 Mar 2005 11:46:49 +0000 Subject: [PATCH] fixed a fd leak and a bad memory access bug SVN revision: 13914 --- src/modules/loaders/loader_zlib.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/modules/loaders/loader_zlib.c b/src/modules/loaders/loader_zlib.c index 924b925..6ed5c9a 100644 --- a/src/modules/loaders/loader_zlib.c +++ b/src/modules/loaders/loader_zlib.c @@ -67,22 +67,28 @@ char load (ImlibImage *im, ImlibProgressFunction progress, { ImlibLoader *loader; int src, dest; - char *file, tmp[] = "/tmp/imlib2_loader_zlib-XXXXXX"; + char *file, *p, tmp[] = "/tmp/imlib2_loader_zlib-XXXXXX"; struct stat st; assert (im); - /* we'll need a copy of it later */ - file = im->real_file; + /* check that this file ends in *.gz */ + p = strrchr(im->real_file, '.'); + if (p) { + if (strcasecmp(p + 1, "gz")) + return 0; + } else + return 0; if (stat (im->real_file, &st) < 0) return 0; - if ((dest = mkstemp (tmp)) < 0) - return 0; - if ((src = open (im->real_file, O_RDONLY)) < 0) { - unlink (tmp); + return 0; + } + + if ((dest = mkstemp (tmp)) < 0) { + close (src); return 0; } @@ -96,12 +102,15 @@ char load (ImlibImage *im, ImlibProgressFunction progress, return 0; } + /* remember the original filename */ + file = strdup (im->real_file); + free (im->real_file); im->real_file = strdup (tmp); loader->load (im, progress, progress_granularity, immediate_load); free (im->real_file); - im->real_file = strdup (file); + im->real_file = file; unlink (tmp); return 1;