XvQueryAdaptors: small memory leak

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

 



Sorry to bug both of you, but I wasn't entirely clear which bits were
maintained by x.org, and which by XFree86.org, so I'm copying you both.


     VERSION:

R6.6

     CLIENT MACHINE and OPERATING SYSTEM:

intel / RedHat9.0 w/ kernel version 2.4.20-20.9

     DISPLAY TYPE:

XF86_Config

     WINDOW MANAGER:

metacity

     COMPILER:

gcc 3.2.2

     AREA:

Xv

     SYNOPSIS:

There's a small memory leak in XvQueryAdaptors().

     DESCRIPTION:

Not all of the memory allocated by XvQueryAdaptors is freed by
XvFreeAdaptorInfo.

It looks as though the culprit is the first Xalloc() in
XvQueryAdaptors().  The space is used as a local buffer (pointer
assigned to variable named "buffer") -- that is, the returned
XvAdaptorInfo structure does not have a reference to this memory, so
it is not XvFreeAdaptorInfo's responsibility to free it.  It must be
freed before returning from XvQueryAdaptors().

There are several failure paths where buffer is freed.  But on
success, it is not freed.

     REPEAT BY:

Compile this, run it, and watch its size grow.

----- 8< ----- Cut Here ----- 8< -----
/* gcc -o xvleak xvleak.c -L/usr/X11R6/lib -lXext -lXv -lX11 */
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xvlib.h>

int
main()
{
  int numAdapt;
  XvAdaptorInfo *info;
  Display *dis = XOpenDisplay(0);
  Window win = DefaultRootWindow(dis);

  while (Success == XvQueryAdaptors(dis,win,&numAdapt,&info))
    XvFreeAdaptorInfo(info);
}
----- 8< ----- Cut Here ----- 8< -----

     SAMPLE FIX:

Insert "Xfree(buffer);" immediately before the last return statement
of the XvQueryAdaptor().

I've tried this fix, and it seems ok.  The above sample program does
not work, and at least one Real Program (one that acutally uses the
returned data) seems to continue to work correctly.

phil dumont
phil@xxxxxxxxxxxxxxxxxxxxxxxx


p.s., from a cursory glance at XvQueryExtensions(), I'd say it has the
same problem, though I haven't tested it or tried to fix it.



_______________________________________________
XFree86 mailing list
XFree86@xxxxxxxxxxx
http://XFree86.Org/mailman/listinfo/xfree86

[Index of Archives]     [X Forum]     [Xorg]     [XFree86 Newbie]     [IETF Announce]     [Security]     [Font Config]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux Kernel]

  Powered by Linux