Commit 3a664fca14a5bea8fadfffedc00e4e66109cf085

David Turner 2001-12-21T15:26:19

* src/cid/cidobjs.c (CID_Face_Done): fixed a memory leak, the subrs routines were never released when CID faces were destroyed

diff --git a/ChangeLog b/ChangeLog
index 191ab7b..699a553 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2001-12-21  David Turner  <david@freetype.org>
 
+        * include/freetype/cache/ftcmanag.h, include/freetype/cache/ftcimage.h,
+        include/freetype/cache/ftcsbits.h: updating documentation to better
+        explain the use of the "anode" output parameter in lookup functions
+
 	* src/pshinter/pshglob.c (psh_globals_new): Replaced a floating
 	point constant with a fixed-float equivalent.  For some reasons not
 	all compilers are capable of directly computing a floating pointer
diff --git a/include/freetype/cache/ftcimage.h b/include/freetype/cache/ftcimage.h
index bc75466..f12ee29 100644
--- a/include/freetype/cache/ftcimage.h
+++ b/include/freetype/cache/ftcimage.h
@@ -170,6 +170,7 @@ FT_BEGIN_HEADER
   /*                                                                       */
   /*    anode  :: used to return the address of of the corresponding       */
   /*              cache node after incrementing its reference count        */
+  /*              (see note below)                                         */
   /*                                                                       */
   /* <Return>                                                              */
   /*    FreeType error code.  0 means success.                             */
diff --git a/include/freetype/cache/ftcmanag.h b/include/freetype/cache/ftcmanag.h
index 44e2dab..7db644c 100644
--- a/include/freetype/cache/ftcmanag.h
+++ b/include/freetype/cache/ftcmanag.h
@@ -152,7 +152,7 @@ FT_BEGIN_HEADER
   /*                    between abstract @FTC_FaceID values and real       */
   /*                    @FT_Face objects.                                  */
   /*                                                                       */
-  /*    families     :: XXX                                                */
+  /*    families     :: global table of families.                          */
   /*                                                                       */
   typedef struct  FTC_ManagerRec_
   {
diff --git a/include/freetype/cache/ftcsbits.h b/include/freetype/cache/ftcsbits.h
index 8e04c89..181cfd2 100644
--- a/include/freetype/cache/ftcsbits.h
+++ b/include/freetype/cache/ftcsbits.h
@@ -164,10 +164,9 @@ FT_BEGIN_HEADER
   /* <Output>                                                              */
   /*    sbit   :: A handle to a small bitmap descriptor.                   */
   /*                                                                       */
-  /*    anode  :: An opaque cache node pointer that will be used           */
-  /*              to release the sbit once it becomes unuseful.            */
-  /*              Can be NULL, in which case this function will            */
-  /*              have the same effect as @FTC_SBitCache_Lookup. XXX       */
+  /*    anode  :: used to return the address of of the corresponding       */
+  /*              cache node after incrementing its reference count        */
+  /*              (see note below)                                         */
   /*                                                                       */
   /* <Return>                                                              */
   /*    FreeType error code.  0 means success.                             */
@@ -181,6 +180,17 @@ FT_BEGIN_HEADER
   /*    The descriptor's `buffer' field is set to 0 to indicate a missing  */
   /*    glyph bitmap.                                                      */
   /*                                                                       */
+  /*    If "anode" is _not_ NULL, it receives the address of the cache     */
+  /*    node containing the bitmap, after increasing its reference         */
+  /*    count. This ensures that the node (as well as the image) will      */
+  /*    always be kept in the cache until you call @FTC_Node_Unref to      */
+  /*    "release" it.                                                      */
+  /*                                                                       */
+  /*    If "anode" is NULL, the cache node is left unchanged, which means  */
+  /*    that the bitmap could be flushed out of the cache on the next      */
+  /*    call to one of the caching sub-system APIs. Just don't assume      */
+  /*    that it's persistent..                                             */
+  /*                                                                       */
   FT_EXPORT( FT_Error )
   FTC_SBitCache_Lookup( FTC_SBitCache    cache,
                         FTC_ImageDesc*   desc,
diff --git a/src/cid/cidload.c b/src/cid/cidload.c
index ad39013..5611291 100644
--- a/src/cid/cidload.c
+++ b/src/cid/cidload.c
@@ -446,7 +446,7 @@
 
       if ( FILE_Seek( cid->data_offset + offsets[0] ) ||
            FILE_Read( subr->code[0], data_len )  )
-        goto Exit;
+        goto Fail;
 
       /* set up pointers */
       for ( count = 1; count <= num_subrs; count++ )
diff --git a/src/cid/cidobjs.c b/src/cid/cidobjs.c
index e2eb679..2d1e6b3 100644
--- a/src/cid/cidobjs.c
+++ b/src/cid/cidobjs.c
@@ -196,6 +196,25 @@
 
       memory = face->root.memory;
 
+      /* release subrs */
+      if ( face->subrs )
+      {
+        FT_Int      n;
+        
+        for ( n = 0; n < cid->num_dicts; n++ )
+        {
+          CID_Subrs*  subr = face->subrs + n;
+          
+          if ( subr->code )
+          {
+            FREE( subr->code[0] );
+            FREE( subr->code );
+          }
+        }
+
+        FREE( face->subrs );
+      }
+
       /* release FontInfo strings */
       FREE( info->version );
       FREE( info->notice );
diff --git a/src/type1/t1objs.c b/src/type1/t1objs.c
index 34f29fe..4d4faf0 100644
--- a/src/type1/t1objs.c
+++ b/src/type1/t1objs.c
@@ -123,7 +123,7 @@
                                  size->root.metrics.x_scale,
                                  size->root.metrics.y_scale,
                                  0, 0 );
-    return error;                                
+    return error;
   }