From 5e09e1b57eb658ba800fe8513df0210daebb6b3f Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Sun, 30 Sep 2012 17:39:22 +0200 Subject: [PATCH] linux: please valgrind, free memory at exit Free the memory that is used to store the new argv and envp. It's not strictly necessary (the OS is going to reclaim the memory anyway) but it makes the output from valgrind a lot less noisy. --- src/unix/linux/linux-core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/unix/linux/linux-core.c b/src/unix/linux/linux-core.c index 167423f1..a773b079 100644 --- a/src/unix/linux/linux-core.c +++ b/src/unix/linux/linux-core.c @@ -57,6 +57,7 @@ #endif static char buf[MAXPATHLEN + 1]; +static void* args_mem; static struct { char *str; @@ -69,6 +70,12 @@ static void read_times(unsigned int numcpus, uv_cpu_info_t* ci); static unsigned long read_cpufreq(unsigned int cpunum); +__attribute__((destructor)) +static void free_args_mem(void) { + free(args_mem); /* keep valgrind happy */ +} + + int uv__platform_loop_init(uv_loop_t* loop, int default_loop) { loop->inotify_watchers = NULL; loop->inotify_fd = -1; @@ -147,11 +154,12 @@ char** uv_setup_args(int argc, char** argv) { size += (argc + 1) * sizeof(char **); size += (envc + 1) * sizeof(char **); - if ((s = (char *) malloc(size)) == NULL) { + if (NULL == (s = malloc(size))) { process_title.str = NULL; process_title.len = 0; return argv; } + args_mem = s; new_argv = (char **) s; new_env = new_argv + argc + 1;