[ccan] [PATCH 2/7] failtest: Remove memory leak

David Gibson david at gibson.dropbear.id.au
Mon Apr 3 21:11:07 AEST 2017


Somewhat ironically, a path in failtest related to detecting leaks in the
tested program itself leaks memory.  This corrects it.

Detected by Coverity.

Signed-off-by: David Gibson <david at gibson.dropbear.id.au>
---
 ccan/failtest/failtest.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/ccan/failtest/failtest.c b/ccan/failtest/failtest.c
index aab28dd..c61ce44 100644
--- a/ccan/failtest/failtest.c
+++ b/ccan/failtest/failtest.c
@@ -613,8 +613,10 @@ static NORETURN void failtest_cleanup(bool forced_cleanup, int status)
 
 		/* But their program shouldn't leak, even on failure. */
 		if (!forced_cleanup && i->can_leak) {
+			char *p = failpath_string();
 			printf("Leak at %s:%u: --failpath=%s\n",
-			       i->file, i->line, failpath_string());
+			       i->file, i->line, p);
+			free(p);
 			status = 1;
 		}
 	}
-- 
2.9.3



More information about the ccan mailing list