* src/sfnt/sfdriver.c (get_sfnt_postscript_name): fixed memory leak
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
diff --git a/src/sfnt/sfdriver.c b/src/sfnt/sfdriver.c
index b8b07c3..07fbd84 100644
--- a/src/sfnt/sfdriver.c
+++ b/src/sfnt/sfdriver.c
@@ -115,6 +115,7 @@
get_sfnt_postscript_name( TT_Face face )
{
FT_Int n, found_win, found_apple;
+ const char* result = NULL;
/* shouldn't happen, but just in case to avoid memory leaks */
@@ -151,11 +152,10 @@
TT_NameEntryRec* name = face->name_table.names + found_win;
FT_UInt len = name->stringLength/2;
FT_Error error;
- FT_String* result;
if ( !ALLOC( result, len+1 ) )
{
- FT_String* r = result;
+ FT_String* r = (FT_String*)result;
FT_Byte* p = (FT_Byte*) name->string;
for ( ; len > 0; len--, p += 2 )
@@ -165,26 +165,28 @@
}
*r = '\0';
}
- return result;
+ goto Exit;
}
if ( found_apple )
{
- FT_Memory memory = face->root.memory;
+ FT_Memory memory = face->root.memory;
TT_NameEntryRec* name = face->name_table.names + found_win;
- FT_UInt len = name->stringLength;
- FT_Error error;
- FT_String* result;
+ FT_UInt len = name->stringLength;
+ FT_Error error;
+ FT_String* result;
if ( !ALLOC( result, len+1 ) )
{
MEM_Copy( result, name->string, len );
result[len] = '\0';
}
- return result;
+ goto Exit;
}
- return NULL;
+ Exit:
+ face->root.internal->postscript_name = result;
+ return result;
}