HomeClusterLabs Projects

Feature: libcib: allow free function for user data supplied to CIB callbacks

Description

Feature: libcib: allow free function for user data supplied to CIB callbacks

This feature provides the infrastructure to fix memory leaks in CIB callbacks
detected in routine valgrind testing.

CIB clients can do cib->cmds->register_callback() to be notified of CIB
updates for a particular call ID. They can supply a user_data parameter to
be passed to their callback function.

When libcib removes a callback registered this way, it will leak user_data if
it was dynamically allocated. The client can't always do the free, because the
removal may be implicit (e.g. when updating the callback of an existing call ID).

This revision solves the problem by adding a register_callback_full() method
that takes a function as argument that will be used to free user_data.

A side effect is that the callback is removed from the callback table
after the callback is called, rather than before. The only effect on callers
would be that the return value of num_cib_op_callbacks() will be 1 higher than
it would before this revision, so the lone use of that in the pacemaker codebase
has been adjusted accordingly.

This revision includes additions to the libcib public API (no removals).
There are no API changes, but there is a slight change in behavior as
described above.

Details

Provenance
kgaillotAuthored on Jul 24 2015, 1:19 PM
Parents
rP3d781d3fe615: Merge branch 'master' of github.com:ClusterLabs/pacemaker
Branches
Unknown
Tags
Unknown

Event Timeline