Fixed memory leaks.

This commit is contained in:
Armin Novak 2014-11-16 23:37:02 +01:00
parent 24f3f0c4a6
commit ad1a029876

View File

@ -583,30 +583,30 @@ rdtkFont* rdtk_font_new(rdtkEngine* engine, const char* path, const char* file)
{ {
int status; int status;
int length; int length;
rdtkFont* font; rdtkFont* font = NULL;
char* fontBaseFile; char* fontBaseFile = NULL;
char* fontImageFile; char* fontImageFile = NULL;
char* fontDescriptorFile; char* fontDescriptorFile = NULL;
fontBaseFile = GetCombinedPath(path, file); fontBaseFile = GetCombinedPath(path, file);
if (!fontBaseFile) if (!fontBaseFile)
return NULL; goto cleanup;
length = strlen(fontBaseFile); length = strlen(fontBaseFile);
fontImageFile = (char*) malloc(length + 8); fontImageFile = (char*) malloc(length + 8);
if (!fontImageFile) if (!fontImageFile)
return NULL; goto cleanup;
strcpy(fontImageFile, fontBaseFile); strcpy(fontImageFile, fontBaseFile);
strcpy(&fontImageFile[length], ".png"); strcpy(&fontImageFile[length], ".png");
fontDescriptorFile = (char*) malloc(length + 8); fontDescriptorFile = (char*) malloc(length + 8);
if (!fontImageFile) if (!fontDescriptorFile)
return NULL; goto cleanup;
strcpy(fontDescriptorFile, fontBaseFile); strcpy(fontDescriptorFile, fontBaseFile);
strcpy(&fontDescriptorFile[length], ".xml"); strcpy(&fontDescriptorFile[length], ".xml");
@ -614,27 +614,27 @@ rdtkFont* rdtk_font_new(rdtkEngine* engine, const char* path, const char* file)
free(fontBaseFile); free(fontBaseFile);
if (!PathFileExistsA(fontImageFile)) if (!PathFileExistsA(fontImageFile))
return NULL; goto cleanup;
if (!PathFileExistsA(fontDescriptorFile)) if (!PathFileExistsA(fontDescriptorFile))
return NULL; goto cleanup;
font = (rdtkFont*) calloc(1, sizeof(rdtkFont)); font = (rdtkFont*) calloc(1, sizeof(rdtkFont));
if (!font) if (!font)
return NULL; goto cleanup;
font->engine = engine; font->engine = engine;
font->image = winpr_image_new(); font->image = winpr_image_new();
if (!font->image) if (!font->image)
return NULL; goto cleanup;
status = winpr_image_read(font->image, fontImageFile); status = winpr_image_read(font->image, fontImageFile);
if (status < 0) if (status < 0)
return NULL; goto cleanup;
status = rdtk_font_load_descriptor(font, fontDescriptorFile); status = rdtk_font_load_descriptor(font, fontDescriptorFile);
@ -642,6 +642,20 @@ rdtkFont* rdtk_font_new(rdtkEngine* engine, const char* path, const char* file)
free(fontDescriptorFile); free(fontDescriptorFile);
return font; return font;
cleanup:
if (fontImageFile)
free (fontImageFile);
if (fontDescriptorFile)
free (fontDescriptorFile);
if (font)
{
if (font->image)
winpr_image_free(font->image);
free (font);
}
return NULL;
} }
rdtkFont* rdtk_embedded_font_new(rdtkEngine* engine, BYTE* imageData, int imageSize, BYTE* descriptorData, int descriptorSize) rdtkFont* rdtk_embedded_font_new(rdtkEngine* engine, BYTE* imageData, int imageSize, BYTE* descriptorData, int descriptorSize)