Hello,

here is a bug fix that fixes a memory leak in XGFontInfo:
The fix renames fontDictionary to myFontDictionary, because fontDictionary was  
declared twice (static in XGFont.m and as instance variable in GSFontInfo).  
The compiler took the instance variable, so no fontInfo was ever released nor  
reused.


2000-05-22 Georg Fleischmann

        * xgps/Source/XGFont.m
        ([XGFont(XGFontInfo) initWithFontName:matrix:]):
        renamed fontDictionary to myFontDictionary
        ([XGFont(XGFontInfo) dealloc]):
        check font_info before unloading fonts


*** xgps/Source/XGFont.m.old    Mon May 22 16:05:45 2000
--- xgps/Source/XGFont.m        Mon May 22 21:31:07 2000
***************
*** 41,47 ****
  /*
   * class global dictionary of existing fonts
   */
! static NSMutableDictionary    *fontDictionary = nil;

  @implementation XGFontInfo

--- 41,47 ----
  /*
   * class global dictionary of existing fonts
   */
! static NSMutableDictionary    *myFontDictionary = nil;

  @implementation XGFontInfo

***************
*** 66,82 ****
     * Do we have an already contructed XGFontInfo for this request? If yes we
     * return it.
     */
!   if (fontDictionary == nil)
!     fontDictionary = [NSMutableDictionary new];
!   if ((fontinfo = [fontDictionary objectForKey: xfontname]))
      {
        RELEASE(self);
!       return fontinfo;
      }

    // Now we create an XGFontInfo to add to the original fontDict.
    [super init];
!   [fontDictionary setObject: self forKey: xfontname];

    // Load X font and get font info structure.
    if (xdpy)
--- 66,82 ----
     * Do we have an already contructed XGFontInfo for this request? If yes we
     * return it.
     */
!   if (myFontDictionary == nil)
!     myFontDictionary = [NSMutableDictionary new];
!   if ((fontinfo = [myFontDictionary objectForKey: xfontname]))
      {
        RELEASE(self);
!       return [fontinfo retain];
      }

    // Now we create an XGFontInfo to add to the original fontDict.
    [super init];
!   [myFontDictionary setObject: self forKey: xfontname];

    // Load X font and get font info structure.
    if (xdpy)
***************
*** 116,122 ****

  - (void) dealloc
  {
!   XUnloadFont([XGContext currentXDisplay], font_info->fid);
    [super dealloc];
  }

--- 116,123 ----

  - (void) dealloc
  {
!   if (font_info != NULL)
!     XUnloadFont([XGContext currentXDisplay], font_info->fid);
    [super dealloc];
  }



---
Georg Fleischmann

vhf interservice
http://www.vhf.de

Reply via email to