Module: xenomai-rpm
Branch: for-upstream
Commit: 5cfb204fc10bd91d9a55c92ba7b129423145cad3
URL:    
http://git.xenomai.org/?p=xenomai-rpm.git;a=commit;h=5cfb204fc10bd91d9a55c92ba7b129423145cad3

Author: Ronny meeus <ronny.me...@gmail.com>
Date:   Tue Jan 18 17:57:18 2011 +0100

psos: fix memory leak with message buffers

---

 ksrc/skins/psos+/queue.c |   56 ++++++++++++++++++++-------------------------
 1 files changed, 25 insertions(+), 31 deletions(-)

diff --git a/ksrc/skins/psos+/queue.c b/ksrc/skins/psos+/queue.c
index 703ca3b..d531046 100644
--- a/ksrc/skins/psos+/queue.c
+++ b/ksrc/skins/psos+/queue.c
@@ -40,6 +40,7 @@ static int msgq_read_proc(char *page,
        int len;
        spl_t s;
 
+       p += sprintf(p, "psosmbufq #bufs=%d\n",countq(&psosmbufq));
        p += sprintf(p, "maxnum=%lu:maxlen=%lu:mcount=%d\n",
                     queue->maxnum, queue->maxlen, countq(&queue->inq));
 
@@ -164,15 +165,20 @@ static psosmbuf_t *get_mbuf(psosqueue_t *queue, u_long 
msglen)
                if (mbuf)
                        inith(&mbuf->link);
        } else {
-               xnholder_t *holder = getq(&queue->freeq);
-
-               if (!holder &&
-                   testbits(queue->synchbase.status, Q_INFINITE) &&
-                   feed_pool(&queue->chunkq,
-                             &queue->freeq, PSOS_QUEUE_MIN_ALLOC,
-                             queue->maxlen) != 0)
+               xnholder_t *holder = NULL;
+               if (testbits(queue->synchbase.status, Q_SHAREDINIT)) {
+                       holder = getq(&psosmbufq);
+                       if (!holder) {
+                               feed_pool(&psoschunkq, 
&psosmbufq,PSOS_QUEUE_MIN_ALLOC,queue->maxlen);
+                               holder = getq(&psosmbufq);
+                       }
+               } else {
                        holder = getq(&queue->freeq);
-
+                       if (!holder && testbits(queue->synchbase.status, 
Q_INFINITE)) { 
+                               feed_pool(&queue->chunkq,&queue->freeq, 
PSOS_QUEUE_MIN_ALLOC,queue->maxlen);
+                               holder = getq(&queue->freeq);
+                       }
+               }
                if (holder)
                        mbuf = link2psosmbuf(holder);
        }
@@ -187,7 +193,6 @@ static u_long q_create_internal(const char *name,
        static unsigned long msgq_ids;
        psosqueue_t *queue;
        int bflags, ret;
-       u_long rc;
        spl_t s;
 
        bflags = (flags & Q_VARIABLE);
@@ -236,27 +241,13 @@ static u_long q_create_internal(const char *name,
        initq(&queue->chunkq);
 
        if (bflags & Q_PRIVCACHE) {
-               if (bflags & Q_SHAREDINIT) {
-                       xnlock_get_irqsave(&nklock, s);
-                       rc = feed_pool(&psoschunkq, &psosmbufq, maxnum, maxlen);
-                       xnlock_put_irqrestore(&nklock, s);
-               } else
-                       rc = feed_pool(&queue->chunkq, &queue->freeq, maxnum,
-                                      maxlen);
-
-               if (!rc) {
-                       /* Can't preallocate msg buffers. */
-                       xnfree(queue);
-                       return ERR_NOMGB;
-               }
-
-               if (bflags & Q_SHAREDINIT) {
-                       xnlock_get_irqsave(&nklock, s);
-
-                       while (countq(&queue->freeq) < maxnum)
-                               appendq(&queue->freeq, getq(&psosmbufq));
-
-                       xnlock_put_irqrestore(&nklock, s);
+               if ((bflags & Q_SHAREDINIT) == 0) {
+                       u_long rc = feed_pool(&queue->chunkq, &queue->freeq, 
maxnum, maxlen);
+                       if (!rc) {
+                               /* Can't preallocate msg buffers. */
+                               xnfree(queue);
+                               return ERR_NOMGB;
+                       }
                }
        }
 
@@ -477,7 +468,10 @@ static u_long q_receive_internal(u_long qid,
 
        if (testbits(queue->synchbase.status, Q_NOCACHE))
                xnfree(mbuf);
-       else
+       else if (testbits(queue->synchbase.status, Q_SHAREDINIT)) {
+               /* Message buffer should go to the psosmbufq */
+               appendq(&psosmbufq, &mbuf->link);
+       } else    
                appendq(&queue->freeq, &mbuf->link);
 
       unlock_and_exit:


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to