plugged two memmory leaks happening when a requested font is not found.
[rrdtool.git] / src / rrd_gfx.c
index 44f668b..1d46a85 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * RRDtool 1.2.9  Copyright by Tobi Oetiker, 1997-2005
+ * RRDtool 1.2.11  Copyright by Tobi Oetiker, 1997-2005
  ****************************************************************************
  * rrd_gfx.c  graphics wrapper for rrdtool
   **************************************************************************/
@@ -303,10 +303,15 @@ double gfx_get_text_width_libart (
 
   FT_Init_FreeType( &library );
   error = FT_New_Face( library, font, 0, &face );
-  if ( error ) return -1;
+  if ( error ) {
+    FT_Done_FreeType(library);
+    return -1;
+  }
   error = FT_Set_Char_Size(face,  size*64,size*64,  100,100);
-  if ( error ) return -1;
-
+  if ( error ) {
+    FT_Done_FreeType(library);
+    return -1;
+  }
   string = gfx_string_create( canvas, face, text, rotation, tabwidth, size );
   text_width = string->width;
   gfx_string_destroy(string);
@@ -386,7 +391,11 @@ gfx_string gfx_string_create(gfx_canvas_t *canvas, FT_Face face,const char *text
   cstr = malloc(sizeof(wchar_t) * clen); /* yes we are allocating probably too much here, I know */
   string->count=mbstowcs(cstr,text,clen);
   if ( string->count == -1){
-       string->count=mbstowcs(cstr,"Enc-Err",6);
+  /* conversion did not work, so lets fall back to just use what we got */
+       string->count=clen-1;
+        for(n=0;text[n] != '\0';n++){
+            cstr[n]=(unsigned char)text[n];
+        }
   }
 #else
   char         *cstr = strdup(text);
@@ -598,6 +607,7 @@ int           gfx_render_png (gfx_canvas_t *canvas,
                                  &face );
            if ( error ) {
                rrd_set_error("failed to load %s",node->filename);
+               
                break;
            }
             error = FT_Set_Char_Size(face,   /* handle to face object            */