Skip to content

Fix some Coverity false positives#4103

Open
nrwahl2 wants to merge 50 commits into
ClusterLabs:mainfrom
nrwahl2:nrwahl2-coverity
Open

Fix some Coverity false positives#4103
nrwahl2 wants to merge 50 commits into
ClusterLabs:mainfrom
nrwahl2:nrwahl2-coverity

Conversation

@nrwahl2
Copy link
Copy Markdown
Contributor

@nrwahl2 nrwahl2 commented May 5, 2026

This fixes INCOMPLETE_DEALLOCATOR false positives for mainloop_gio_destroy() and another one that I don't recall. It also fixes a longstanding const fields issue with lrmd_event_data_t.

Edit: The INCOMPLETE_DEALLOCATOR false positives are still present. I'm probably going to have to figure out how to open a support case to make those go away. However, this PR fixes other Coverity issues and does some cleanup.

@nrwahl2 nrwahl2 requested a review from clumens May 5, 2026 18:53
clumens
clumens previously approved these changes May 5, 2026
Comment thread lib/lrmd/lrmd_client.c
@clumens
Copy link
Copy Markdown
Contributor

clumens commented May 5, 2026

Man, coverity's being picky right now.

@nrwahl2
Copy link
Copy Markdown
Contributor Author

nrwahl2 commented May 5, 2026

Man, coverity's being picky right now.

Yeah, and the new errors are actually ones that I dropped in the "Drop unused Coverity annotations" commit. The analysis output said those were unused. And at the time, when I re-ran Coverity, the errors did not reappear. Now they do.

@clumens clumens self-requested a review May 5, 2026 21:23
@clumens clumens dismissed their stale review May 5, 2026 21:23

New coverity things to look at

nrwahl2 added 12 commits May 14, 2026 00:59
annotations-warnings.txt in the coverity-TAG/output directory says the
return overflow annotation is unused.

Also flag the replica->child error as a false positive, rather than
simply suppressing it. bundle_data->child->priv->children is a list of
non-NULL items, and we've already dereferenced replica->child before we
hit the line that Coverity complains about.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
qb_ipcc_is_connected() returns QB_FALSE for a NULL argument.
pcmk__ipc_free_client_buffer() does nothing when its argument's buffer
field is NULL.

Also remove a layer of nesting.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Commit 4facb96 introduced much of this complexity. The commit message
says "Make mainloop_gio_destroy() tollerant of being called
re-entrantly". However, there seems to be no way this could happen.
Pacemaker is single-threaded, and the destroy_fn can't return control
back to the main loop. Control returns to the main loop when
mainloop_gio_destroy() returns.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
...where appropriate.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
lrmd_new_event() allocates memory for rsc_id and op_type.

lrmd_copy_event() allocates memory for rsc_id, op_type, user_data,
output, remote_nodename, and exit_reason.

lrmd_dispatch_internal() allocates memory for output and exit_reason,
but prior to this commit it used strings belonging to other objects for
rsc_id, op_type, user_data, and remote_nodename.

lrmd_free_event() frees all six fields.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
This should have been done in commit e09bc86.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
@nrwahl2 nrwahl2 force-pushed the nrwahl2-coverity branch from cd3813a to 273ec06 Compare May 14, 2026 09:23
@nrwahl2 nrwahl2 changed the title Fix a couple of Coverity false positives for INCOMPLETE_DEALLOCATOR Fix some Coverity false positives May 14, 2026
nrwahl2 added 10 commits May 14, 2026 02:27
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
I don't like stealing memory just to avoid allocating a string. It makes
the code harder to reason about. And if we ever want to use the
stdout_data and stderr_data of the affected svc_action_t in the future,
we could run into bugs if we forget that the stdout/stderr was stolen.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
The sole call passes TRUE.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Now that it's been simplified, it's clear that this is equivalent to
building up a GString with a newline after each target.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
I don't like stealing memory just to avoid allocating a string. It makes
the code harder to reason about. Also, we could run into bugs if we
forget that the stdout/stderr was stolen.

Further, this confuses Coverity. It thinks pcmk__copy_result() is the
allocator for pcmk__action_result_t and that pcmk__set_result_output()
is the deallocator.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
We were already doing this for file and remote cib_t objects (via
pcmk__generate_uuid() and pcmk__str_copy(), respectively). We might as
well also assert in other places in those variants, as well as asserting
in native cib_t creation and in cib_new_variant().

This resolves some Coverity memory leak issues.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
nrwahl2 added 24 commits May 14, 2026 02:27
This is a slight decrease in redundancy. Usually I don't like more
layers of nesting, but it's a small block here, and the whole block may
be functionized later.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
For consistency. Also drop some unnecessary casts along the way.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
We already use pcmk__assert_alloc() in several places, as well as GLib
functions that allocate memory and assert on failure.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
This is the bundle_data belonging to the parent argument (stored in
parent->priv->variant_opaque).

Also rename to bundle_data for consistency.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
If replica->child is not NULL, then clone_xml was not NULL in
pe__unpack_bundle(). This implies that unpack_bundle_primitive() already
called valid_network() and that it returned true.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Also rename it and have it take a pcmk_resource_t * argument.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
We're already doing this in unpack_bundle_container(), so it seems
reasonable to do it in valid_network() if we have to reset
nreplicas_per_host to 1 there.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
The two conditions are equivalent now, and this is clearer.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
For what I perceive to be clarity.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
It gets set to a copy of rsc->id at the beginning of pe__unpack_bundle,
and then it's never changed. So we can use the bundle resource's ID
instead.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
bundle_data->agent_type must be set to a valid value if
get_container_xml() returned non-NULL.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
This gets rid of the last use of bundle_data->prefix.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
This goes back at least as far as 5892a2b. If pe__unpack_bundle() fails
in create_replica_resources(), it calls pcmk__free_resource(rsc). Then
the caller (pe__unpack_resource()) also frees rsc when it jumps to the
"done" label.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
We're setting utilization for replica resources, so this makes sense to
me.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
@nrwahl2 nrwahl2 marked this pull request as draft May 14, 2026 09:28
nrwahl2 added 3 commits May 14, 2026 02:28
Found by Coverity with --enable-fnptr option.
pcmk_controld_api_replies_expected() dereferences its argument.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Instead of doing a string comparison. This is to address what appears to
be a false positive from Coverity, but it also feels cleaner than the
code line prior to this commit.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
Found by Coverity with --enable-fnptr.

Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
@nrwahl2 nrwahl2 marked this pull request as ready for review May 14, 2026 09:30
@nrwahl2 nrwahl2 force-pushed the nrwahl2-coverity branch from 273ec06 to 670054b Compare May 14, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants