From patchwork Thu Apr 14 14:38:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neels Hofmeyr X-Patchwork-Id: 610482 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.osmocom.org (lists.osmocom.org [IPv6:2a01:4f8:191:444b::2:7]) by ozlabs.org (Postfix) with ESMTP id 3qm3JY4CNVz9s9k for ; Fri, 15 Apr 2016 00:41:17 +1000 (AEST) Received: from lists.osmocom.org (lists.osmocom.org [144.76.43.76]) by lists.osmocom.org (Postfix) with ESMTP id 1CD1F1C9FB; Thu, 14 Apr 2016 14:41:16 +0000 (UTC) X-Original-To: openbsc@lists.osmocom.org Delivered-To: openbsc@lists.osmocom.org Received: from einhorn.in-berlin.de (einhorn.in-berlin.de [IPv6:2001:bf0:c000::1:8]) by lists.osmocom.org (Postfix) with ESMTP id 16A951C9F3 for ; Thu, 14 Apr 2016 14:41:14 +0000 (UTC) X-Envelope-From: nhofmeyr@sysmocom.de X-Envelope-To: Received: from localhost (cable-37-120-29-94.cust.telecolumbus.net [37.120.29.94] (may be forged)) (authenticated bits=0) by einhorn.in-berlin.de (8.14.4/8.14.4/Debian-4+deb7u1) with ESMTP id u3EEfEl6022881 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 14 Apr 2016 16:41:14 +0200 From: Neels Hofmeyr To: openbsc@lists.osmocom.org Subject: [PATCH] queue_new(): if calloc fails, abort (CID #57918) Date: Thu, 14 Apr 2016 16:38:42 +0200 Message-Id: <1460644722-22972-1-git-send-email-nhofmeyr@sysmocom.de> X-Mailer: git-send-email 2.1.4 X-BeenThere: openbsc@lists.osmocom.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Development of OpenBSC, OsmoBSC, OsmoNITB, OsmoCSCN" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openbsc-bounces@lists.osmocom.org Sender: "OpenBSC" Coverity complains about a 'Dereference before null check' on *queue. So, push the NULL check further up, but also, instead of handling a calloc failure as error, rather abort the program. --- gtp/queue.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/gtp/queue.c b/gtp/queue.c index 7c971b0..707b522 100644 --- a/gtp/queue.c +++ b/gtp/queue.c @@ -127,16 +127,15 @@ int queue_new(struct queue_t **queue) if (QUEUE_DEBUG) printf("queue_new\n"); *queue = calloc(1, sizeof(struct queue_t)); + if (!(*queue)) + abort(); (*queue)->next = 0; (*queue)->first = -1; (*queue)->last = -1; if (QUEUE_DEBUG) queue_print(*queue); - if (*queue) - return 0; - else - return EOF; + return 0; } /*! \brief Deallocates queue structure */