freetype-devel
[Top][All Lists]
Advanced

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

[Devel] memory leak in open_face()


From: dima
Subject: [Devel] memory leak in open_face()
Date: Tue, 04 Mar 2003 16:31:12 +0300
User-agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.1) Gecko/20030104

I experienced a strange problem trying to build fontconfig on my laptop. It has 160M RAM & fc-cache ran out of memory during 'make install'. I turned a swap on & figured out that it allocates about 180M (I used standard & cyrillic fonts shipped with XFree86 4.2.1 only). I debugged the stuff & found the bug in src/base/ftobjs.c (freetype-2.1.3). The code contains gotos for error handling ( I consider it to be not that good ;) ), but FT_FREE is called in the case clazz->init_face() is failed only. 'error' variable contains an unpredictable value if the 1st or the 2nd 'goto Fail' is used (initializing it with a null value on declaration is a good idea i guess). I provided the code with my suggestions marked with '++' signs below.

Regards, Dima.

....
    /* allocate the face object and perform basic initialization */
    if ( FT_ALLOC( face, clazz->face_object_size ) )
      goto Fail;

    if ( FT_NEW( internal ) )
      goto Fail;

    face->internal = internal;
....
    error = clazz->init_face( stream,
                              face,
                              (FT_Int)face_index,
                              num_params,
                              params );
    if ( error )
      goto Fail;
....
  Fail:
    if ( error )
    {
      clazz->done_face( face );
      FT_FREE( face->internal );
      FT_FREE( face );
      *aface = 0;
    }
++  else {
++    if( face ) {
++      if( face->internal )
++        FT_FREE( face->internal );
++      FT_FREE( face );
++    }
++  /* some error value should be generated here */
++  }

    return error;
  }
....




reply via email to

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