From 652939dd216495679be0a4464b4052684d099720 Mon Sep 17 00:00:00 2001 From: "Pedro A. Aranda" Date: Thu, 5 Jan 2017 13:41:14 +0100 Subject: [PATCH] Fix reported memory leak (strdup without free) Clean up compiler warnings --- contrib/untgz/untgz.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/contrib/untgz/untgz.c b/contrib/untgz/untgz.c index 2c391e5..d936390 100644 --- a/contrib/untgz/untgz.c +++ b/contrib/untgz/untgz.c @@ -14,26 +14,33 @@ #include "zlib.h" +#ifdef __unix__ +# ifndef unix +# define unix 1 +# endif +#endif + #ifdef unix -# include +# include +# include #else -# include -# include +# include +# include #endif #ifdef WIN32 #include -# ifndef F_OK -# define F_OK 0 -# endif -# define mkdir(dirname,mode) _mkdir(dirname) -# ifdef _MSC_VER -# define access(path,mode) _access(path,mode) -# define chmod(path,mode) _chmod(path,mode) -# define strdup(str) _strdup(str) -# endif +# ifndef F_OK +# define F_OK 0 +# endif +# define mkdir(dirname,mode) _mkdir(dirname) +# ifdef _MSC_VER +# define access(path,mode) _access(path,mode) +# define chmod(path,mode) _chmod(path,mode) +# define strdup(str) _strdup(str) +# endif #else -# include +# include #endif @@ -277,6 +284,7 @@ void restore_attr(struct attr_item **list) chmod(item->fname,item->mode); prev = item; item = item->next; + free(prev->fname); free(prev); } *list = NULL; @@ -608,7 +616,7 @@ int main(int argc,char **argv) int action = TGZ_EXTRACT; int arg = 1; char *TGZfile; - gzFile *f; + gzFile f; prog = strrchr(argv[0],'\\'); if (prog == NULL)