[geany/geany] af3421: Plug a memory leak

Colomban Wendling git-noreply at xxxxx
Mon Sep 23 19:54:30 UTC 2013


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Mon, 23 Sep 2013 19:54:30 UTC
Commit:      af3421e688af3a8a81ffdaca1701dbeb49b5ebaa
             https://github.com/geany/geany/commit/af3421e688af3a8a81ffdaca1701dbeb49b5ebaa

Log Message:
-----------
Plug a memory leak

Do not evaluate a macro argument multiple times if it gets passed an
expression, especially if that expression allocates memory.

Thanks to Pavel Roschin for spotting the leak.


Modified Paths:
--------------
    src/build.c

Modified: src/build.c
21 files changed, 12 insertions(+), 9 deletions(-)
===================================================================
@@ -2523,15 +2523,18 @@ void build_load_menu(GKeyFile *config, GeanyBuildSource src, gpointer p)
 
 	/* set GeanyBuildCommand if it doesn't already exist and there is a command */
 /* TODO: rewrite as function */
-#define ASSIGNIF(type, id, string, value) \
-	if (!EMPTY(value) && ! type[GBO_TO_CMD(id)].exists) { \
-		type[GBO_TO_CMD(id)].exists = TRUE; \
-		SETPTR(type[GBO_TO_CMD(id)].label, g_strdup(string)); \
-		SETPTR(type[GBO_TO_CMD(id)].command, (value)); \
-		SETPTR(type[GBO_TO_CMD(id)].working_dir, NULL); \
-		type[GBO_TO_CMD(id)].old = TRUE; \
-	} else \
-		g_free(value);
+#define ASSIGNIF(type, id, string, value)								\
+	do {																\
+		gchar *ASSIGNF__value = (value);								\
+		if (!EMPTY(ASSIGNF__value) && ! type[GBO_TO_CMD(id)].exists) {	\
+			type[GBO_TO_CMD(id)].exists = TRUE;							\
+			SETPTR(type[GBO_TO_CMD(id)].label, g_strdup(string));		\
+			SETPTR(type[GBO_TO_CMD(id)].command, ASSIGNF__value);		\
+			SETPTR(type[GBO_TO_CMD(id)].working_dir, NULL);				\
+			type[GBO_TO_CMD(id)].old = TRUE;							\
+		} else															\
+			g_free(ASSIGNF__value);										\
+	} while (0)
 
 	switch (src)
 	{



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list