Repository navigation
Conversation
The generated RPC server functions allocate their list arguments (attribute lists, stat counter arrays) and free them only after a successful SAI call. When the call fails, or the API function pointer is NULL, they throw sai_thrift_exception first, so every failed call leaks those buffers. Tests that expect a call to be rejected leak on every expected failure, which LeakSanitizer reports when the RPC server exits. Free the allocated arguments before each throw, and run the new checkrpcleaks.pl from 'make rpc' so that a generated function which throws while still holding an allocation fails the build. Signed-off-by: Mori Levinzon <mlevinzon@nvidia.com>
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
| if ($line =~ /^ \S.*?\b(sai_thrift_\w+)\(.*\) \{$/) | ||
| { | ||
| $function = $1; | ||
| @allocated = (); |
There was a problem hiding this comment.
you are making empty allocated table here, would it be possible that this if() will happen twice? so first you will allocate (line 55), but not free, then this line happens ad 47, and you have allocated, and then empty ?
woulid it be better to do something like this:
$allocations{X} +=1; // if allocated, -=1 if deallocated, later on at the end, loop throug all keys and check if all are zeros, since currently you can have allocated empty, and freed containing something, which is not desired, and it will be not catched, since error code is set only when allocated is not empty
There was a problem hiding this comment.
Good point, thanks. The check now does that, adapted to functions having several exits:
-
Function boundaries are tracked by brace depth; a function start seen before the current one ends is an error instead of a silent reset.
-
Per-variable counters: +1 per malloc, +1 per free on the success path, and at the function's return every variable must be freed as many times as it was allocated. Freeing something never allocated is an error too.
-
A plain per-function counter would see 1 malloc against 3 frees in e.g. create_tunnel (two error branches plus the success path), so each error branch is checked as its own path: every throw, and every early return inside a branch, must free each allocation made so far exactly once.
-
Branch layouts it can't follow (} else, else if) are reported rather than checked wrongly.
No errors on the regenerated server, 1472 errors in 670 functions on current master, and each of those cases is reported when injected.
Track function boundaries by brace depth, and report a function start seen before the current function ends instead of resetting the state. Count allocations and frees per variable. The success path must free each variable as many times as it was allocated, and every throw or early return inside a branch must free each allocation made so far exactly once. Freeing a variable that was never allocated is an error, and so is a branch layout the check does not follow. Signed-off-by: Mori Levinzon <mlevinzon@nvidia.com>
|
@kcudnik The checker now tracks allocations per path as you suggested, details in the thread above. Could you take another look when you get a chance, and kick off /azp run? Thanks! |
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
|
@kcudnik @tjchadaga this is approved and all checks passed. Could one of you merge it when you get a chance? Thanks! |
Fixes #2377
The generated RPC server functions free their list arguments (attribute lists, stat counter arrays) only after a successful SAI call. On a failed call, or a NULL API function pointer, they throw
sai_thrift_exceptionbefore freeing, so every failed call leaks.meta/templates/sai_rpc_server_functions.tt: newfree_malloced_argsblock, called before each throw (NULL API pointer, failed status, failed stats call). It uses its own variable names becausePROCESSshares the caller's stash, whereindentationandargare in use.meta/checkrpcleaks.pl: checks the generatedsai_rpc_server.cppand fails if a function throws while still holding an allocation.meta/Makefile:make rpcruns the check.Testing:
checkrpcleaks.plfails: 670 generated functions throw without freeing.sai_rpc_server.cppdiffers from master only by the addedfree()calls (1472 lines, nothing removed).make,make rpc,make sai_rpc_server.skeletonandmake sai_rpc_frontendpass.