From fd603ed9e2f87d05b2261a25e11aceb01814dfbe Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sat, 28 Mar 2015 18:09:31 +0100 Subject: write_queue: Check the result of osmo_wqueue_enqueue and free The write_queue is designed to have a maximum amount of pending messages and will refuse to take new messages when it has been reached. The caller can decide if it wants to flush the queue and add the message again, create a log. But in all cases the ownership of the msgb has not been transferred. Fix the potential memory leak in the failure situation. --- openbsc/src/utils/smpp_mirror.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'openbsc/src/utils') diff --git a/openbsc/src/utils/smpp_mirror.c b/openbsc/src/utils/smpp_mirror.c index cf3657e39..2f154db49 100644 --- a/openbsc/src/utils/smpp_mirror.c +++ b/openbsc/src/utils/smpp_mirror.c @@ -85,7 +85,13 @@ static int pack_and_send(struct esme *esme, uint32_t type, void *ptr) } msgb_put(msg, rlen); - return osmo_wqueue_enqueue(&esme->wqueue, msg); + if (osmo_wqueue_enqueue(&esme->wqueue, msg) != 0) { + LOGP(DSMPP, LOGL_ERROR, "[%s] Write queue full. Dropping message\n", + esme->system_id); + msgb_free(msg); + return -EAGAIN; + } + return 0; } /* FIXME: merge with smpp_smsc.c */ -- cgit v1.2.3