From 11b971f405cf4f1a1bb51bb3ff115ca76707c3eb Mon Sep 17 00:00:00 2001 From: Amarnath Valluri Date: Thu, 16 Jun 2016 15:45:02 +0300 Subject: go.cxx: Fix use of a freed variable Signed-off-by: Amarnath Valluri --- Source/Modules/go.cxx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx index 6013fa15b..7fa9b2670 100644 --- a/Source/Modules/go.cxx +++ b/Source/Modules/go.cxx @@ -4176,7 +4176,6 @@ private: Wrapper *dummy = NewWrapper(); emit_attach_parmmaps(parms, dummy); - DelWrapper(dummy); Swig_typemap_attach_parms("gotype", parms, NULL); Swig_typemap_attach_parms("imtype", parms, NULL); @@ -4233,6 +4232,8 @@ private: Swig_typemap_attach_parms("goin", parms, dummy); Swig_typemap_attach_parms("goargout", parms, dummy); + DelWrapper(dummy); + if (!is_ignored) { // We use an interface to see if this method is defined in Go. Printv(f_go_wrappers, "type ", interface_name, " interface {\n", NULL); -- cgit v1.2.1 From 08d5e19e6edf85e22cee4759e8ecb17228eb5b71 Mon Sep 17 00:00:00 2001 From: Amarnath Valluri Date: Thu, 16 Jun 2016 15:51:50 +0300 Subject: Lua: Fix possible memory leaks Signed-off-by: Amarnath Valluri --- Source/Modules/lua.cxx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/Modules/lua.cxx b/Source/Modules/lua.cxx index 1b4c8f617..80ea47f3f 100644 --- a/Source/Modules/lua.cxx +++ b/Source/Modules/lua.cxx @@ -856,6 +856,9 @@ public: //Printf(stdout,"Swig_overload_dispatch %s %s '%s' %d\n",symname,wname,dispatch,maxargs); if (!luaAddSymbol(lua_name, n)) { + DelWrapper(f); + Delete(dispatch); + Delete(tmp); return SWIG_ERROR; } -- cgit v1.2.1 From 030a3b08bf981397ea5a16e0d3f727d7b4beba54 Mon Sep 17 00:00:00 2001 From: Amarnath Valluri Date: Thu, 16 Jun 2016 15:53:22 +0300 Subject: Fix leaked file descriptor Signed-off-by: Amarnath Valluri --- Source/Swig/include.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Swig/include.c b/Source/Swig/include.c index 08226a25c..94df338f0 100644 --- a/Source/Swig/include.c +++ b/Source/Swig/include.c @@ -291,6 +291,7 @@ int Swig_insert_file(const_String_or_char_ptr filename, File *outfile) { while ((nbytes = Read(f, buffer, 4096)) > 0) { Write(outfile, buffer, nbytes); } + fclose(f); return 0; } -- cgit v1.2.1 From 9b371b48d15cb739af65d91d92cd695e968e11b5 Mon Sep 17 00:00:00 2001 From: Amarnath Valluri Date: Thu, 16 Jun 2016 15:59:21 +0300 Subject: scilab.cxx: Fix memory leaks Signed-off-by: Amarnath Valluri --- Source/Modules/scilab.cxx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/Modules/scilab.cxx b/Source/Modules/scilab.cxx index 42df12f7c..7febf1011 100644 --- a/Source/Modules/scilab.cxx +++ b/Source/Modules/scilab.cxx @@ -326,6 +326,7 @@ public: bool isLastOverloaded = isOverloaded && !Getattr(node, "sym:nextSibling"); if (!isOverloaded && !addSymbol(functionName, node)) { + DelWrapper(wrapper); return SWIG_ERROR; } @@ -603,6 +604,7 @@ public: Append(getFunctionWrapper->code, "return SWIG_OK;\n"); Append(getFunctionWrapper->code, "}\n"); Wrapper_print(getFunctionWrapper, wrappersSection); + DelWrapper(getFunctionWrapper); /* Add function to builder table */ addFunctionToScilab(scilabGetFunctionName, getFunctionName); @@ -630,6 +632,7 @@ public: Append(setFunctionWrapper->code, "return SWIG_OK;\n"); Append(setFunctionWrapper->code, "}\n"); Wrapper_print(setFunctionWrapper, wrappersSection); + DelWrapper(setFunctionWrapper); /* Add function to builder table */ addFunctionToScilab(scilabSetFunctionName, setFunctionName); -- cgit v1.2.1 From 478d5df91178a35f97cdf90c055d95c358b55e52 Mon Sep 17 00:00:00 2001 From: Amarnath Valluri Date: Thu, 16 Jun 2016 17:38:14 +0300 Subject: CCache: Fix memory/file descriptor leaks Signed-off-by: Amarnath Valluri --- CCache/ccache.c | 13 ++++++++++++- CCache/execute.c | 1 + CCache/stats.c | 5 ++++- CCache/unify.c | 3 ++- CCache/util.c | 7 ++++++- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CCache/ccache.c b/CCache/ccache.c index e7dd1d30a..c5c510388 100644 --- a/CCache/ccache.c +++ b/CCache/ccache.c @@ -130,6 +130,7 @@ static void failed(void) exit(1); } args_add_prefix(orig_args, p); + free(p); } if (ccache_verbose) { @@ -490,7 +491,9 @@ static void find_hash(ARGS *args) /* also include the hash of the compiler name - as some compilers use hard links and behave differently depending on the real name */ if (st.st_nlink > 1) { - hash_string(str_basename(args->argv[0])); + char *path = str_basename(args->argv[0]); + hash_string(path); + free(path); } hash_int(st.st_size); @@ -523,6 +526,7 @@ static void find_hash(ARGS *args) input_base, tmp_string(), i_extension); x_asprintf(&path_stderr, "%s/tmp.cpp_stderr.%s", temp_dir, tmp_string()); + free(input_base); if (!direct_i_file) { /* run cpp on the input file to obtain the .i */ @@ -781,6 +785,7 @@ static void find_compiler(int argc, char **argv) /* support user override of the compiler */ if ((path=getenv("CCACHE_CC"))) { + free(base); base = x_strdup(path); } @@ -791,8 +796,10 @@ static void find_compiler(int argc, char **argv) stats_update(STATS_COMPILER); cc_log("could not find compiler (%s)\n", base); perror(base); + free(base); exit(1); } + free(base); } @@ -1076,6 +1083,7 @@ static void process_args(int argc, char **argv) if (strlen(p) < 2) { cc_log("badly formed dependency file %s\n", output_file); stats_update(STATS_ARGS); + free(default_depfile_name); failed(); return; } @@ -1093,6 +1101,7 @@ static void process_args(int argc, char **argv) strcat(default_depfile_name, ".d"); args_add(stripped_args, "-MF"); args_add(stripped_args, default_depfile_name); + free(default_depfile_name); } if (!dependency_target_specified) { @@ -1117,6 +1126,7 @@ static void process_args(int argc, char **argv) exit(1); } args_add_prefix(stripped_args, p); + free(p); } } @@ -1305,6 +1315,7 @@ static void setup_uncached_err(void) if (putenv(buf) == -1) { cc_log("putenv failed\n"); + close(uncached_fd); stats_update(STATS_ERROR); failed(); } diff --git a/CCache/execute.c b/CCache/execute.c index 165b91e66..6df025e95 100644 --- a/CCache/execute.c +++ b/CCache/execute.c @@ -267,6 +267,7 @@ char *find_executable(const char *name, const char *exclude_name) } free(fname); } + free(path); return NULL; #endif diff --git a/CCache/stats.c b/CCache/stats.c index d2122bcd3..db0d4d2bf 100644 --- a/CCache/stats.c +++ b/CCache/stats.c @@ -138,7 +138,10 @@ static void stats_update_size(enum stats stat, size_t size, size_t numfiles) memset(counters, 0, sizeof(counters)); - if (lock_fd(fd) != 0) return; + if (lock_fd(fd) != 0) { + close(fd); + return; + } /* read in the old stats */ stats_read_fd(fd, counters); diff --git a/CCache/unify.c b/CCache/unify.c index a93d48a02..7a36476a1 100644 --- a/CCache/unify.c +++ b/CCache/unify.c @@ -281,6 +281,7 @@ int unify_hash(const char *fname) fd = open(fname, O_RDONLY|O_BINARY); if (fd == -1 || fstat(fd, &st) != 0) { cc_log("Failed to open preprocessor output %s\n", fname); + if (fd != -1) close(fd); stats_update(STATS_PREPROCESSOR); return -1; } @@ -289,12 +290,12 @@ int unify_hash(const char *fname) lines in preprocessor output. I have seen lines of over 100k in length, so this is well worth it */ map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + close(fd); if (map == (char *)-1) { cc_log("Failed to mmap %s\n", fname); stats_update(STATS_PREPROCESSOR); return -1; } - close(fd); /* pass it through the unifier */ unify((unsigned char *)map, st.st_size); diff --git a/CCache/util.c b/CCache/util.c index 66f9823b9..af4e7868b 100644 --- a/CCache/util.c +++ b/CCache/util.c @@ -189,9 +189,11 @@ void copy_fd(int fd_in, int fd_out) { while ((n = gzread(gz_in, buf, sizeof(buf))) > 0) { if (write(fd_out, buf, n) != n) { + gzclose(gz_in); fatal("Failed to copy fd"); } } + gzclose(gz_in); } static int _copy_file(const char *src, const char *dest, int mode) { @@ -248,9 +250,11 @@ static int _copy_file(const char *src, const char *dest, int mode) { } if (mode == COPY_TO_CACHE) { - gz_out = gzdopen(dup(fd_out), "wb"); + int dup_fd_out = dup(fd_out); + gz_out = gzdopen(dup_fd_out, "wb"); if (!gz_out) { gzclose(gz_in); + close(dup_fd_out); close(fd_out); free(tmp_name); return -1; @@ -459,6 +463,7 @@ int create_cachedirtag(const char *dir) f = fopen(filename, "w"); if (!f) goto error; if (fwrite(CACHEDIR_TAG, sizeof(CACHEDIR_TAG)-1, 1, f) != 1) { + fclose(f); goto error; } if (fclose(f)) goto error; -- cgit v1.2.1 From 6234ebd48600cb418b1a858fd586656321eceda8 Mon Sep 17 00:00:00 2001 From: Amarnath Valluri Date: Fri, 17 Jun 2016 13:28:09 +0300 Subject: CCache: Fix typo in null check --- CCache/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CCache/util.c b/CCache/util.c index af4e7868b..ef90e2336 100644 --- a/CCache/util.c +++ b/CCache/util.c @@ -490,7 +490,7 @@ void x_asprintf(char **ptr, const char *format, ...) } va_end(ap); - if (!ptr) fatal("out of memory in x_asprintf"); + if (!*ptr) fatal("out of memory in x_asprintf"); } /* -- cgit v1.2.1 From 7ec7cc63daa079e581b5cae0a0e7cee4384b928e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 26 Jun 2016 00:06:01 +0100 Subject: memory leak improvements - delete at end of scope --- Source/Modules/scilab.cxx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/Modules/scilab.cxx b/Source/Modules/scilab.cxx index 7febf1011..137adc234 100644 --- a/Source/Modules/scilab.cxx +++ b/Source/Modules/scilab.cxx @@ -604,7 +604,6 @@ public: Append(getFunctionWrapper->code, "return SWIG_OK;\n"); Append(getFunctionWrapper->code, "}\n"); Wrapper_print(getFunctionWrapper, wrappersSection); - DelWrapper(getFunctionWrapper); /* Add function to builder table */ addFunctionToScilab(scilabGetFunctionName, getFunctionName); @@ -632,11 +631,13 @@ public: Append(setFunctionWrapper->code, "return SWIG_OK;\n"); Append(setFunctionWrapper->code, "}\n"); Wrapper_print(setFunctionWrapper, wrappersSection); - DelWrapper(setFunctionWrapper); /* Add function to builder table */ addFunctionToScilab(scilabSetFunctionName, setFunctionName); + + DelWrapper(setFunctionWrapper); } + DelWrapper(getFunctionWrapper); return SWIG_OK; } -- cgit v1.2.1 From adfa531a3b602d953e4127bc0968c30e5afa584d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 26 Jun 2016 00:06:15 +0100 Subject: whitespace fix --- CCache/stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CCache/stats.c b/CCache/stats.c index db0d4d2bf..4d01d2afa 100644 --- a/CCache/stats.c +++ b/CCache/stats.c @@ -141,7 +141,7 @@ static void stats_update_size(enum stats stat, size_t size, size_t numfiles) if (lock_fd(fd) != 0) { close(fd); return; - } + } /* read in the old stats */ stats_read_fd(fd, counters); -- cgit v1.2.1