wtsi-npg / baton

iRODS client programs and API
http://wtsi-npg.github.io/baton
GNU General Public License v2.0
19 stars 19 forks source link

Memory management bugfix and refactor #217

Closed kjsanger closed 4 years ago

kjsanger commented 4 years ago

These changes address two related problems with baton, firstly inconsistent memory management on errors, leading to segfaults and secondly, memory management code duplication between error and non-error code paths.

init_rods_path (called from resolve_rods_path) is no longer responsible for memset'ing the rods_path struct. Now the caller does this immediately after declaring. This in repetitive, but is simple and eliminates the most common class of bug found recently in baton (segfaults due to uninitialised memory on the error handling code path).

Where non-error and error code paths share operations and return values, these have been combined with a new label 'finally'.

As the changes are extensive, the API has been tested with Valgrind. Included is a new wrapper script for baton-do that can be used where higher level APIs run a baton-do child process. This allows the specific baton-do functions used by the higher level API to be run under Valgrind.

The Valgrind tests revealed an existing memory leak in list_checksum, which has been fixed.