Fix memory leak in stonith__api_new() error path#4145
Conversation
|
Can one of the project admins check and authorise this run please: https://haci.fast.eng.rdu2.dc.redhat.com/job/pacemaker/job/pacemaker-pipeline/job/PR-4145/1/input |
|
|
||
| new_stonith->cmds = calloc(1, sizeof(stonith_api_operations_t)); | ||
| if (new_stonith->cmds == NULL) { | ||
| if (private->stonith_op_callback_table) { |
There was a problem hiding this comment.
This can't be NULL. We created it via pcmk__intkey_table(), which calls g_hash_table_new_full(). The GLib allocator functions behave similarly to pcmk__assert_alloc(): they exit with an error if allocation fails:
With that in mind, let's go ahead and replace all the calloc() calls with pcmk__assert_alloc() (unless @clumens objects) and drop all of these NULL checks.
There was a problem hiding this comment.
That sounds fine to me. And if we're starting a list of other things to fix in this function, let me add the following:
- The
privatevariable appears to only exist to save typing later. notify_deletesis abool, not agboolean.- We don't typically line things up vertically on the equals sign like we do at the bottom of this function.
There was a problem hiding this comment.
And if we're starting a list of other things to fix in this function, let me add the following:
Agreed, but I'm not trying to give @Jazyy a list of stylistic issues to fix. Just asking them to use pcmk__assert_alloc() instead of calloc(), which would avoid this issue, since this function already terminates on memory error.
lib/fencing/st_client: Free callback table in stonith__api_new error path
When the third calloc() fails in stonith__api_new(), the previously allocated stonith_op_callback_table hash table was not being freed, causing a memory leak. Add proper cleanup to destroy the hash table before returning NULL. This ensures all allocated resources are properly released even in error conditions.