mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-02-21 18:00:39 +01:00
A few cleanups to eliminate a memory leak.
This commit is contained in:
parent
5edcd47a91
commit
fb46d7390e
8 changed files with 25 additions and 89 deletions
|
|
@ -1,5 +1,7 @@
|
|||
2003-10-30 Carl Worth <cworth@isi.edu>
|
||||
|
||||
* cairo_font: A few cleanups to eliminate a memory leak.
|
||||
|
||||
* src/cairo_gstate.c (_cairo_gstate_init_copy):
|
||||
(_cairo_gstate_fini):
|
||||
(_cairo_gstate_select_font):
|
||||
|
|
|
|||
|
|
@ -41,14 +41,8 @@ cairo_status_t
|
|||
_cairo_font_init (cairo_font_t *font,
|
||||
const struct cairo_font_backend *backend)
|
||||
{
|
||||
font->family = (unsigned char *) strdup (CAIRO_FONT_FAMILY_DEFAULT);
|
||||
if (font->family == NULL)
|
||||
return CAIRO_STATUS_NO_MEMORY;
|
||||
|
||||
cairo_matrix_set_identity (&font->matrix);
|
||||
font->refcount = 1;
|
||||
font->weight = CAIRO_FONT_WEIGHT_NORMAL;
|
||||
font->slant = CAIRO_FONT_SLANT_NORMAL;
|
||||
font->backend = backend;
|
||||
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
|
|
@ -63,12 +57,6 @@ _cairo_font_copy (cairo_font_t *font)
|
|||
if (font == NULL || font->backend->copy == NULL)
|
||||
return NULL;
|
||||
|
||||
if (font->family) {
|
||||
tmp = (unsigned char *) strdup ((char *) font->family);
|
||||
if (tmp == NULL)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
newfont = font->backend->copy (font);
|
||||
if (newfont == NULL) {
|
||||
free (tmp);
|
||||
|
|
@ -76,33 +64,11 @@ _cairo_font_copy (cairo_font_t *font)
|
|||
}
|
||||
|
||||
newfont->refcount = 1;
|
||||
newfont->family = tmp;
|
||||
cairo_matrix_copy(&newfont->matrix, &font->matrix);
|
||||
newfont->slant = font->slant;
|
||||
newfont->weight = font->weight;
|
||||
newfont->backend = font->backend;
|
||||
return newfont;
|
||||
}
|
||||
|
||||
void
|
||||
_cairo_font_fini (cairo_font_t *font)
|
||||
{
|
||||
if (font == NULL)
|
||||
return;
|
||||
|
||||
if (--(font->refcount) > 0)
|
||||
return;
|
||||
|
||||
if (font->family)
|
||||
free (font->family);
|
||||
font->family = NULL;
|
||||
|
||||
_cairo_matrix_fini (&font->matrix);
|
||||
|
||||
if (font->backend->close)
|
||||
font->backend->close (font);
|
||||
}
|
||||
|
||||
cairo_status_t
|
||||
_cairo_font_scale (cairo_font_t *font, double scale)
|
||||
{
|
||||
|
|
@ -197,7 +163,11 @@ cairo_font_reference (cairo_font_t *font)
|
|||
void
|
||||
cairo_font_destroy (cairo_font_t *font)
|
||||
{
|
||||
_cairo_font_fini (font);
|
||||
if (--(font->refcount) > 0)
|
||||
return;
|
||||
|
||||
if (font->backend->destroy)
|
||||
font->backend->destroy (font);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -207,7 +207,7 @@ _cairo_ft_font_copy (cairo_font_t *font)
|
|||
}
|
||||
|
||||
static void
|
||||
_cairo_ft_font_close (cairo_font_t *font)
|
||||
_cairo_ft_font_destroy (cairo_font_t *font)
|
||||
{
|
||||
cairo_ft_font_t * ft_font = NULL;
|
||||
|
||||
|
|
@ -600,5 +600,5 @@ const struct cairo_font_backend cairo_ft_font_backend = {
|
|||
glyph_path: (void *) _cairo_ft_font_glyph_path,
|
||||
create: (void *) _cairo_ft_font_create,
|
||||
copy: (void *) _cairo_ft_font_copy,
|
||||
close: (void *) _cairo_ft_font_close
|
||||
destroy: (void *) _cairo_ft_font_destroy
|
||||
};
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ _cairo_gstate_init_copy (cairo_gstate_t *gstate, cairo_gstate_t *other)
|
|||
CLEANUP_PATH:
|
||||
_cairo_path_fini (&gstate->path);
|
||||
CLEANUP_FONT:
|
||||
_cairo_font_fini (gstate->font);
|
||||
cairo_font_destroy (gstate->font);
|
||||
CLEANUP_DASHES:
|
||||
free (gstate->dash);
|
||||
gstate->dash = NULL;
|
||||
|
|
@ -158,7 +158,7 @@ _cairo_gstate_init_copy (cairo_gstate_t *gstate, cairo_gstate_t *other)
|
|||
void
|
||||
_cairo_gstate_fini (cairo_gstate_t *gstate)
|
||||
{
|
||||
_cairo_font_fini (gstate->font);
|
||||
cairo_font_destroy (gstate->font);
|
||||
|
||||
cairo_surface_destroy (gstate->surface);
|
||||
gstate->surface = NULL;
|
||||
|
|
@ -1426,7 +1426,7 @@ _cairo_gstate_select_font (cairo_gstate_t *gstate,
|
|||
cairo_font_weight_t weight)
|
||||
{
|
||||
if (gstate->font != NULL)
|
||||
_cairo_font_fini (gstate->font);
|
||||
cairo_font_destroy (gstate->font);
|
||||
|
||||
gstate->font = _cairo_font_create (family, slant, weight);
|
||||
|
||||
|
|
@ -1478,7 +1478,7 @@ _cairo_gstate_set_font (cairo_gstate_t *gstate,
|
|||
cairo_font_t *font)
|
||||
{
|
||||
if (gstate->font != NULL)
|
||||
_cairo_font_fini (gstate->font);
|
||||
cairo_font_destroy (gstate->font);
|
||||
gstate->font = font;
|
||||
cairo_font_reference (gstate->font);
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
|
|
|
|||
|
|
@ -41,14 +41,8 @@ cairo_status_t
|
|||
_cairo_font_init (cairo_font_t *font,
|
||||
const struct cairo_font_backend *backend)
|
||||
{
|
||||
font->family = (unsigned char *) strdup (CAIRO_FONT_FAMILY_DEFAULT);
|
||||
if (font->family == NULL)
|
||||
return CAIRO_STATUS_NO_MEMORY;
|
||||
|
||||
cairo_matrix_set_identity (&font->matrix);
|
||||
font->refcount = 1;
|
||||
font->weight = CAIRO_FONT_WEIGHT_NORMAL;
|
||||
font->slant = CAIRO_FONT_SLANT_NORMAL;
|
||||
font->backend = backend;
|
||||
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
|
|
@ -63,12 +57,6 @@ _cairo_font_copy (cairo_font_t *font)
|
|||
if (font == NULL || font->backend->copy == NULL)
|
||||
return NULL;
|
||||
|
||||
if (font->family) {
|
||||
tmp = (unsigned char *) strdup ((char *) font->family);
|
||||
if (tmp == NULL)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
newfont = font->backend->copy (font);
|
||||
if (newfont == NULL) {
|
||||
free (tmp);
|
||||
|
|
@ -76,33 +64,11 @@ _cairo_font_copy (cairo_font_t *font)
|
|||
}
|
||||
|
||||
newfont->refcount = 1;
|
||||
newfont->family = tmp;
|
||||
cairo_matrix_copy(&newfont->matrix, &font->matrix);
|
||||
newfont->slant = font->slant;
|
||||
newfont->weight = font->weight;
|
||||
newfont->backend = font->backend;
|
||||
return newfont;
|
||||
}
|
||||
|
||||
void
|
||||
_cairo_font_fini (cairo_font_t *font)
|
||||
{
|
||||
if (font == NULL)
|
||||
return;
|
||||
|
||||
if (--(font->refcount) > 0)
|
||||
return;
|
||||
|
||||
if (font->family)
|
||||
free (font->family);
|
||||
font->family = NULL;
|
||||
|
||||
_cairo_matrix_fini (&font->matrix);
|
||||
|
||||
if (font->backend->close)
|
||||
font->backend->close (font);
|
||||
}
|
||||
|
||||
cairo_status_t
|
||||
_cairo_font_scale (cairo_font_t *font, double scale)
|
||||
{
|
||||
|
|
@ -197,7 +163,11 @@ cairo_font_reference (cairo_font_t *font)
|
|||
void
|
||||
cairo_font_destroy (cairo_font_t *font)
|
||||
{
|
||||
_cairo_font_fini (font);
|
||||
if (--(font->refcount) > 0)
|
||||
return;
|
||||
|
||||
if (font->backend->destroy)
|
||||
font->backend->destroy (font);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -207,7 +207,7 @@ _cairo_ft_font_copy (cairo_font_t *font)
|
|||
}
|
||||
|
||||
static void
|
||||
_cairo_ft_font_close (cairo_font_t *font)
|
||||
_cairo_ft_font_destroy (cairo_font_t *font)
|
||||
{
|
||||
cairo_ft_font_t * ft_font = NULL;
|
||||
|
||||
|
|
@ -600,5 +600,5 @@ const struct cairo_font_backend cairo_ft_font_backend = {
|
|||
glyph_path: (void *) _cairo_ft_font_glyph_path,
|
||||
create: (void *) _cairo_ft_font_create,
|
||||
copy: (void *) _cairo_ft_font_copy,
|
||||
close: (void *) _cairo_ft_font_close
|
||||
destroy: (void *) _cairo_ft_font_destroy
|
||||
};
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ _cairo_gstate_init_copy (cairo_gstate_t *gstate, cairo_gstate_t *other)
|
|||
CLEANUP_PATH:
|
||||
_cairo_path_fini (&gstate->path);
|
||||
CLEANUP_FONT:
|
||||
_cairo_font_fini (gstate->font);
|
||||
cairo_font_destroy (gstate->font);
|
||||
CLEANUP_DASHES:
|
||||
free (gstate->dash);
|
||||
gstate->dash = NULL;
|
||||
|
|
@ -158,7 +158,7 @@ _cairo_gstate_init_copy (cairo_gstate_t *gstate, cairo_gstate_t *other)
|
|||
void
|
||||
_cairo_gstate_fini (cairo_gstate_t *gstate)
|
||||
{
|
||||
_cairo_font_fini (gstate->font);
|
||||
cairo_font_destroy (gstate->font);
|
||||
|
||||
cairo_surface_destroy (gstate->surface);
|
||||
gstate->surface = NULL;
|
||||
|
|
@ -1426,7 +1426,7 @@ _cairo_gstate_select_font (cairo_gstate_t *gstate,
|
|||
cairo_font_weight_t weight)
|
||||
{
|
||||
if (gstate->font != NULL)
|
||||
_cairo_font_fini (gstate->font);
|
||||
cairo_font_destroy (gstate->font);
|
||||
|
||||
gstate->font = _cairo_font_create (family, slant, weight);
|
||||
|
||||
|
|
@ -1478,7 +1478,7 @@ _cairo_gstate_set_font (cairo_gstate_t *gstate,
|
|||
cairo_font_t *font)
|
||||
{
|
||||
if (gstate->font != NULL)
|
||||
_cairo_font_fini (gstate->font);
|
||||
cairo_font_destroy (gstate->font);
|
||||
gstate->font = font;
|
||||
cairo_font_reference (gstate->font);
|
||||
return CAIRO_STATUS_SUCCESS;
|
||||
|
|
|
|||
|
|
@ -274,7 +274,7 @@ struct cairo_font_backend {
|
|||
|
||||
cairo_font_t *(*copy) (cairo_font_t *other);
|
||||
|
||||
void (*close) (cairo_font_t *font);
|
||||
void (*destroy) (cairo_font_t *font);
|
||||
|
||||
};
|
||||
|
||||
|
|
@ -399,10 +399,7 @@ typedef struct cairo_traps {
|
|||
|
||||
struct cairo_font {
|
||||
int refcount;
|
||||
unsigned char *family;
|
||||
cairo_matrix_t matrix;
|
||||
cairo_font_slant_t slant;
|
||||
cairo_font_weight_t weight;
|
||||
const struct cairo_font_backend *backend;
|
||||
};
|
||||
|
||||
|
|
@ -789,9 +786,6 @@ _cairo_font_init (cairo_font_t *font,
|
|||
extern cairo_font_t * __internal_linkage
|
||||
_cairo_font_copy (cairo_font_t *font);
|
||||
|
||||
extern void __internal_linkage
|
||||
_cairo_font_fini (cairo_font_t *font);
|
||||
|
||||
extern cairo_status_t __internal_linkage
|
||||
_cairo_font_scale (cairo_font_t *font, double scale);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue