All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai] Pool memory leak when writing to full queue
@ 2012-07-12 19:58 Kai
  2012-07-13 19:00 ` Philippe Gerum
  0 siblings, 1 reply; 2+ messages in thread
From: Kai @ 2012-07-12 19:58 UTC (permalink / raw)
  To: xenomai

Hi,

I have a problem using rt_queue_write() (native skin):
As far as I understand, the function wraps around rt_queue_send() by 
allocating pool memory first and memcpy-ing the user-supplied buffer 
into it.
Problem: If sending fails because the queue is full (w.r.t. the number 
of queued messages), the error is returned to the caller, but the 
allocated pool memory is never freed.
The attached program shows how the pool memory gets almost completely 
filled without any messages left in the queue.

The following patch seems to fix it:

--- xenomai-2.6.1/ksrc/skins/native/syscall_old.c       2012-07-12 
19:53:48.464968791 +0200
+++ xenomai-2.6.1/ksrc/skins/native/syscall.c   2012-07-12 
19:48:34.174968603 +0200
@@ -2358,6 +2358,8 @@
         ret = rt_queue_send(q, mbuf, size, mode);
         if (ret == 0 && (mode & Q_BROADCAST))
                 rt_queue_free(q, mbuf); /* Nobody received, free the 
buffer. */
+       if (ret < 0) /* Send failed */
+               rt_queue_free(q, mbuf);

         return ret;
  }

Regards,
Kai
-------------- next part --------------
A non-text attachment was scrubbed...
Name: QueueWriteTest.cpp
Type: text/x-c++src
Size: 1906 bytes
Desc: not available
URL: <http://www.xenomai.org/pipermail/xenomai/attachments/20120712/45ef7ba0/attachment.cpp>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-07-13 19:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-12 19:58 [Xenomai] Pool memory leak when writing to full queue Kai
2012-07-13 19:00 ` Philippe Gerum

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.