[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Help with clang sanitizer
From: |
Akim Demaille |
Subject: |
Re: Help with clang sanitizer |
Date: |
Sun, 23 Sep 2018 13:47:37 +0200 |
> Le 21 sept. 2018 à 07:08, Akim Demaille <address@hidden> a écrit :
>
> Hi all,
>
> The CI is running the test suite with address sanitizer turned on.
> There are two failing tests:
>
>> =================================================================
>> ==3989==ERROR: LeakSanitizer: detected memory leaks
>> Direct leak of 28 byte(s) in 1 object(s) allocated from:
>> #0 0x527308 in operator new(unsigned long)
>> (/home/travis/build/akimd/bison/tests/testsuite.dir/317/test+0x527308)
>> #1 0x2b0a17ec6248 in std::string::_Rep::_S_create(unsigned long, unsigned
>> long, std::allocator<char> const&)
>> (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0xba248)
>> #2 0x724e58 (<unknown module>)
>> SUMMARY: AddressSanitizer: 28 byte(s) leaked in 1 allocation(s).
>> ./types.at:128: exit code was 1, expected 0
>> 317. types.at:128: 317. lalr1.cc api.value.type=variant (types.at:128):
>> FAILED (types.at:128)
Finally got it. A careful reading of the test case should have
sufficed to find it :-/
commit 6537a59c98bccda8899a2fff8431071827188264
Author: Akim Demaille <address@hidden>
Date: Sun Sep 23 11:42:56 2018 +0200
tests: fix a memory leak
This has been bugging me for while. I was hard to reproduce: it
worked only on GNU/Linux, probably because libc++ implements the small
string optimization, while libstdc++ did not and actually allocated on
the heap for this small string.
See https://lists.gnu.org/archive/html/bison-patches/2018-09/msg00110.html.
* tests/types.at (api.value.type): Do not provide a semantic value to
EOF.
diff --git a/tests/types.at b/tests/types.at
index c17e852f..c95d93e4 100644
--- a/tests/types.at
+++ b/tests/types.at
@@ -132,7 +132,8 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc],
[glr.cc]],
[],
['1' '2' { printf ("%2.1f\n", $1 + $2); }],
["12"],
- [AT_VAL = (res - '0') / 10.0],
+ [if (res)
+ AT_VAL = (res - '0') / 10.0],
[0.3])
# A typedef which looks like a Bison keyword, but it's using braces.
@@ -141,7 +142,8 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc],
[glr.cc]],
[%code requires { typedef double variant; }],
['1' '2' { printf ("%2.1f\n", $1 + $2); }],
["12"],
- [AT_VAL = (res - '0') / 10.0],
+ [if (res)
+ AT_VAL = (res - '0') / 10.0],
[0.3])
# A user defined struct.
@@ -151,8 +153,11 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc],
[glr.cc]],
['1' '2'
{ printf ("%d %2.1f\n", $1.ival + $2.ival, $1.fval + $2.fval); }],
["12"],
- [AT_VAL.ival = (res - '0') * 10;
- AT_VAL.fval = (res - '0') / 10.f],
+ [if (res)
+ {
+ AT_VAL.ival = (res - '0') * 10;
+ AT_VAL.fval = (res - '0') / 10.f;
+ }],
[30 0.3])
# A user defined struct that uses pointers.
@@ -197,7 +202,7 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc],
[glr.cc]],
["12"],
[if (res == '1')
AT_VAL.ival = 10;
- else
+ else if (res == '2')
AT_VAL.fval = .2f],
[10 0.2])
@@ -215,7 +220,7 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc],
[glr.cc]],
["12"],
[if (res == '1')
AT_VAL.ival = 10;
- else
+ else if (res == '2')
AT_VAL.fval = 0.2f],
[10 0.2])])
@@ -251,7 +256,7 @@ m4_foreach([b4_skel], [[yacc.c], [glr.c], [lalr1.cc],
[glr.cc]],
["12"],
[if (res == '1')
AT_VAL.build(10);
- else
+ else if (res == '2')
AT_VAL.build<std::string>("two");],
[10, two])])
])