Coverity reports a "dereference after NULL check" in
BkdoorChannelStart. However, at the point of dereference
it's known that chan->inStarted is TRUE, which means chan->in
is guaranteed to be non-NULL, so it's not a bug.
Still, given that an input channel, if present, must have been
started before calling BkdoorChannelStart, it's possible to do
some code cleanup that will also get Coverity to stop reporting
the issue. Change what's currently a test into an ASSERT, test
chan->in rather than chan->inStarted, and add comments to make
it clearer what's going on.
static gboolean
BkdoorChannelStart(RpcChannel *chan)
{
- gboolean ret = TRUE;
+ gboolean ret;
BackdoorChannel *bdoor = chan->_private;
#if defined(NEED_RPCIN)
- ret = chan->in == NULL || chan->inStarted;
- if (ret) {
- ret = RpcOut_start(bdoor->out);
- if (!ret) {
- if (chan->inStarted) {
- RpcIn_stop(chan->in);
- chan->inStarted = FALSE;
- }
- }
+ /*
+ * If the RpcIn channel exists, it should have been started before
+ * calling this routine.
+ */
+ ASSERT(chan->in == NULL || chan->inStarted);
+
+ ret = RpcOut_start(bdoor->out);
+ if (!ret && chan->in != NULL) {
+ /*
+ * If the output channel failed to start, stop the input channel
+ * if there is one.
+ */
+
+ RpcIn_stop(chan->in);
+ chan->inStarted = FALSE;
}
#else
ret = RpcOut_start(bdoor->out);