fixed testcase fail gcc.dg/analyzer/pr103526.c leak
Commit Message
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
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
@@ -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);