svm: cleanup mq private data on fifo segment cleanup

Type: fix

Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: I65373f2cd5a33381da1e51ed7ab7a8b1358cef29
diff --git a/src/svm/fifo_segment.c b/src/svm/fifo_segment.c
index 986778d..00fb023 100644
--- a/src/svm/fifo_segment.c
+++ b/src/svm/fifo_segment.c
@@ -814,7 +814,7 @@
   vec_free (fs->slices);
 
   vec_foreach (fs->mqs, mq)
-    vec_free (mq->rings);
+    svm_msg_q_cleanup (mq);
 
   vec_free (fs->mqs);
 }
diff --git a/src/svm/message_queue.c b/src/svm/message_queue.c
index e08ba06..a6af796 100644
--- a/src/svm/message_queue.c
+++ b/src/svm/message_queue.c
@@ -167,10 +167,19 @@
 }
 
 void
+svm_msg_q_cleanup (svm_msg_q_t *mq)
+{
+  vec_free (mq->rings);
+  clib_spinlock_free (&mq->q.lock);
+  if (mq->q.evtfd != -1)
+    close (mq->q.evtfd);
+}
+
+void
 svm_msg_q_free (svm_msg_q_t * mq)
 {
+  svm_msg_q_cleanup (mq);
   clib_mem_free (mq->q.shr);
-  clib_spinlock_free (&mq->q.lock);
   clib_mem_free (mq);
 }
 
diff --git a/src/svm/message_queue.h b/src/svm/message_queue.h
index 0e402c5..bd76eda 100644
--- a/src/svm/message_queue.h
+++ b/src/svm/message_queue.h
@@ -126,6 +126,11 @@
 void svm_msg_q_attach (svm_msg_q_t *mq, void *smq_base);
 
 /**
+ * Cleanup mq's private data
+ */
+void svm_msg_q_cleanup (svm_msg_q_t *mq);
+
+/**
  * Free message queue
  *
  * @param mq		message queue to be freed