[Toybox] [PATCH] Fix the operator precedence in expr.

Andy Chu andychup at gmail.com
Wed Mar 16 11:34:27 PDT 2016


>   if (p<*toys.optargs || p>toys.optargs[toys.optc-1]) not_argv();
>
> It would be nice to free this data ourselves because expr is close to
> $((1+2)) in the shell, and it would be nice if the shell could just
> internall call expr nofork in that case.

I attached to a patch to track the strings allocated and then free
them at the end.

(Note that there is NOT a "node" per argument ('struct value' which
which contains an int or string).  The nodes are on the stack and used
destructively in the style of a *= b, a += b, etc.  What we are
talking about is the strings that the nodes (may) point to.  These are
almost always argv strings which don't need to be freed, but in the 2
cases I mentioned, we allocate them.

So now this is fixed, and I tested it with ASAN (with LLVM 3.8 which
can be downloaded easily).  It easily finds the memory leak before
(only the regex test cases where we allocate memory fail, not every
test case) and confirms they pass after the patch.

ASAN also found another existing memory leak in the code!  (not
calling regfree())  When I'm triaging the tests I'll definitely see
which ones pass under ASAN too.

Andy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-Track-and-free-all-strings-allocated-during-expr-eva.patch
Type: text/x-patch
Size: 2687 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20160316/3daa12c7/attachment.bin>


More information about the Toybox mailing list