Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 2 Jun 2016 15:52:34 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r301208 - head/sys/kern
Message-ID:  <201606021552.u52FqYxc049471@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Thu Jun  2 15:52:34 2016
New Revision: 301208
URL: https://svnweb.freebsd.org/changeset/base/301208

Log:
  taskqueue: plug a leak in _taskqueue_create
  
  While here make some style fixes and postpone the sprintf so that it is
  only done when the function can no longer fail.
  
  CID:	1356041

Modified:
  head/sys/kern/subr_taskqueue.c

Modified: head/sys/kern/subr_taskqueue.c
==============================================================================
--- head/sys/kern/subr_taskqueue.c	Thu Jun  2 15:31:24 2016	(r301207)
+++ head/sys/kern/subr_taskqueue.c	Thu Jun  2 15:52:34 2016	(r301208)
@@ -130,14 +130,16 @@ _taskqueue_create(const char *name, int 
 	char *tq_name;
 
 	tq_name = malloc(TASKQUEUE_NAMELEN, M_TASKQUEUE, mflags | M_ZERO);
-	if (!tq_name)
+	if (tq_name == NULL)
 		return (NULL);
 
-	snprintf(tq_name, TASKQUEUE_NAMELEN, "%s", (name) ? name : "taskqueue");
-
 	queue = malloc(sizeof(struct taskqueue), M_TASKQUEUE, mflags | M_ZERO);
-	if (!queue)
+	if (queue == NULL) {
+		free(tq_name, M_TASKQUEUE);
 		return (NULL);
+	}
+
+	snprintf(tq_name, TASKQUEUE_NAMELEN, "%s", (name) ? name : "taskqueue");
 
 	STAILQ_INIT(&queue->tq_queue);
 	TAILQ_INIT(&queue->tq_active);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201606021552.u52FqYxc049471>