rspro_dec_msg: Simplify msgb ownership handling
Initially it seemed like a good idea that rspro_dec_msg() takes care
of freeing the input msgb when generating a new decoded output
structure. However, in reality this made the implementation of
every caller more complicated, as it had to treat messages going into
rspro_dec_msg() differently than messages going elsewhere.
Adding to that, not every caller got it right, and the comments were
disagreeing about what happens to msgb ownership in erroneous cases.
Change-Id: I55d5d61922053fd94e2b5a8cdf0d799b29feec98
diff --git a/src/rspro_util.c b/src/rspro_util.c
index 1e5ce99..5c78b60 100644
--- a/src/rspro_util.c
+++ b/src/rspro_util.c
@@ -80,7 +80,7 @@
return msg;
}
-/* consumes 'msg' _if_ it is successful */
+/* caller must make sure to free msg */
RsproPDU_t *rspro_dec_msg(struct msgb *msg)
{
RsproPDU_t *pdu = NULL;
@@ -91,12 +91,9 @@
if (rval.code != RC_OK) {
fprintf(stderr, "Failed to decode: %d. Consumed %lu of %u bytes\n",
rval.code, rval.consumed, msgb_length(msg));
- msgb_free(msg);
return NULL;
}
- msgb_free(msg);
-
return pdu;
}