diff mbox series

fixed testcase fail gcc.dg/analyzer/pr103526.c leak

Message ID 20211230022117.944-1-shihua@iscas.ac.cn
State New
Headers show
Series fixed testcase fail gcc.dg/analyzer/pr103526.c leak | expand

Commit Message

廖仕华 Dec. 30, 2021, 2:21 a.m. UTC
From: LiaoShihua <shihua@iscas.ac.cn>

    following 'false' branch in line 20, 'tmp.word_state' leaks in line 26. So free 'tmp.word_state' before return 'rval'.
  
gcc/testsuite\ChangeLog:

        * gcc.dg/analyzer/pr103526.c:

---
 gcc/testsuite/gcc.dg/analyzer/pr103526.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Jeff Law Dec. 30, 2021, 1:51 p.m. UTC | #1
On 12/29/2021 7:21 PM, shihua@iscas.ac.cn wrote:
> From: LiaoShihua <shihua@iscas.ac.cn>
>
>      following 'false' branch in line 20, 'tmp.word_state' leaks in line 26. So free 'tmp.word_state' before return 'rval'.
>    
> gcc/testsuite\ChangeLog:
>
>          * gcc.dg/analyzer/pr103526.c:
Umm, isn't the whole point of the test to verify that the analyzer 
properly detects the non-free'd pointer as escaping via the return value?

Jeff
diff mbox series

Patch

diff --git a/gcc/testsuite/gcc.dg/analyzer/pr103526.c b/gcc/testsuite/gcc.dg/analyzer/pr103526.c
index 39d60fd853e..7df2e4e7576 100644
--- a/gcc/testsuite/gcc.dg/analyzer/pr103526.c
+++ b/gcc/testsuite/gcc.dg/analyzer/pr103526.c
@@ -22,7 +22,8 @@  game_new(void)
 	if ((rval = malloc(sizeof(*rval))) == NULL)
 		goto err;
 	memcpy(rval, &tmp, sizeof(*rval));
-
+	
+	free(tmp.word_state);
 	return (rval);
 err:
 	free(tmp.word_state);