From a7bcd316fbd21ccfd5d7c2613b9c87c0286d4646 Mon Sep 17 00:00:00 2001 From: Steve Slaven Date: Thu, 27 Oct 2005 06:11:15 +0000 Subject: This fixes a tiny memory leak caused by not freeing the copy of a variable if used in a comparison on the left side, valgrind output: ==10477== 10 bytes in 1 blocks are definitely lost in loss record 3 of 45 ==10477== at 0x1B90459D: malloc (vg_replace_malloc.c:130) ==10477== by 0x806B08A: ptrdup2 (ptr.c:65) ==10477== by 0x806B121: ptrdup (ptr.c:80) ==10477== by 0x805C503: exe_op (eval.c:675) ==10477== by 0x805DDCF: compare_and_unload (eval.c:1279) ==10477== by 0x805DFBA: _eval (eval.c:1322) ==10477== by 0x805E0D4: eval_any (eval.c:1362) ==10477== by 0x805E43C: evall (eval.c:1446) ==10477== by 0x8052514: cmd_if (cmd.c:1884) ==10477== by 0x806536E: parse_commands (main.c:1769) ==10477== by 0x8065119: parse_instruction (main.c:1709) ==10477== by 0x806525F: parse_user_input (main.c:1735) test file: #( "Don't save the config file every time" ) #file = #if ($foo > "ho" ) #print Dwarves #if ($foo > "ho" ) #print Dwarves #if ($foo > "ho" ) #print Dwarves diff --git a/eval.c b/eval.c index f790896..7910442 100644 --- a/eval.c +++ b/eval.c @@ -672,6 +672,7 @@ static int exe_op __P1 (operator *,op) if (o1.type==TYPE_TXT_VAR) { o1.txt = ptrdup(*VAR[o1.num].str); + o1.type = TYPE_TXT; /* not a var anymore */ if (REAL_ERROR) break; } dst = o1.txt; @@ -684,7 +685,6 @@ static int exe_op __P1 (operator *,op) dst = ptrcat(dst, src); o1.type = TYPE_TXT; } else { - o1.type = TYPE_NUM; o1.num = ptrcmp(dst, src); switch ((int)*op) { case (int)minus: break; @@ -699,6 +699,9 @@ static int exe_op __P1 (operator *,op) p=NULL; ret=0; break; } check_delete(&o1); + /* moved here because it interfered with allowing the dst ptr from + * being freed, casing a very tiny memory leak */ + o1.type = TYPE_NUM; } check_delete(&o2); if (!REAL_ERROR) { -- cgit v0.10.2