From 6be9ffa3b811311043194d04ae06e05d216c57bb Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Mon, 19 Jan 2015 08:57:07 +0100 Subject: sgsn/test: Make assert_substr safer (Coverity) Currently, if assert_subscr were called with subscr == NULL, the later call to subscr_put might fail, as Coverity has complained. In addition, the call to subscr_put would free the subscr object if it were in the cache with a refcount of 0 at the time assert_substr was called. This patch adds a check for the subscr being non-NULL and reorders the checks, so that the subscr_put comes last. Fixes: Coverity CID 1264590 Sponsored-by: On-Waves ehf --- openbsc/tests/sgsn/sgsn_test.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'openbsc') diff --git a/openbsc/tests/sgsn/sgsn_test.c b/openbsc/tests/sgsn/sgsn_test.c index 662227d65..1ae94b0dd 100644 --- a/openbsc/tests/sgsn/sgsn_test.c +++ b/openbsc/tests/sgsn/sgsn_test.c @@ -203,12 +203,13 @@ void my_dummy_sgsn_update_subscriber_data(struct sgsn_mm_ctx *mmctx, static void assert_subscr(const struct gsm_subscriber *subscr, const char *imsi) { struct gsm_subscriber *sfound; + OSMO_ASSERT(subscr); + OSMO_ASSERT(strcmp(subscr->imsi, imsi) == 0); sfound = gprs_subscr_get_by_imsi(imsi); OSMO_ASSERT(sfound == subscr); - subscr_put(sfound); - OSMO_ASSERT(strcmp(subscr->imsi, imsi) == 0); + subscr_put(sfound); } static void show_subscrs(FILE *out) -- cgit v1.2.3