[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Memory leak in getsysstats.c

From: ext-Justin.Phillips
Subject: Memory leak in getsysstats.c
Date: Mon, 22 Sep 2003 12:52:02 +0100


I'm currently using 7.2, so at a guess this may have been fixed. Using Insure++
to check for leaks, I came across the following stack trace :-

         6 bytes 1 chunk allocated at strdup.c, 43
                          malloc()  (interface)
                        __strdup()  strdup.c, 43
                   get_proc_path()  ../sysdeps/unix/sysv/linux/getsysstats.c, 78
                 phys_pages_info()  ../sysdeps/unix/sysv/linux/getsysstats.c, 
                         sysconf()  ../sysdeps/posix/sysconf.c, 615
                           qsort()  msort.c, 109
                           qsort()  (interface)

Not knowing much of what goes on under the bonnet (hood) I down loaded glibc to 
have a peak but I don't have the knowledge to provide me with the context, but 
is what I found.

 /* Make a copy we can keep around.  */
 copy_result = __strdup (result);
 if (copy_result == NULL)
   return result;

 /* Now store the copied value.  But do it atomically.  */
 assert (sizeof (long int) == sizeof (void *__unbounded));
 if (compare_and_swap ((long int *) &mount_proc, (long int) 0,
                       (long int) copy_result) == 0)
   /* Replacing the value failed.  This means another thread was
      faster and we don't need the copy anymore.  */
   free (copy_result);
     /* compare_and_swap only copied the pointer value, so we must
        now copy the bounds as well.  */
     __ptrlow (mount_proc) = __ptrlow (copy_result);
     __ptrhigh (mount_proc) = __ptrhigh (copy_result);

 return mount_proc;

Basically if the expression "compare_and_swap ((long int *) &mount_proc, (long 
int) 0,
 (long int) copy_result)" equates to anything other zero ( can it ever ? ) 
you'll get a leak.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]