Fix memory leak when realloc fails due to out-of-memory.

This commit is contained in:
Carl Worth 2005-02-24 14:06:03 +00:00
parent a64b7e51ee
commit aca0708fc8
3 changed files with 17 additions and 12 deletions

View file

@ -1,3 +1,8 @@
2005-02-24 Carl Worth <cworth@cworth.org>
* src/cairo_pattern.c (cairo_pattern_add_color_stop): Fix memory
leak when realloc fails due to out-of-memory.
2005-02-24 Owen Taylor <otaylor@redhat.com>
* src/cairo_win32_surface.[ch]: Instead of counting

View file

@ -215,7 +215,7 @@ cairo_pattern_add_color_stop (cairo_pattern_t *pattern,
double red, double green, double blue,
double alpha)
{
cairo_color_stop_t *stop;
cairo_color_stop_t *stop, *new_stops;
int i;
_cairo_restrict_value (&offset, 0.0, 1.0);
@ -224,13 +224,13 @@ cairo_pattern_add_color_stop (cairo_pattern_t *pattern,
_cairo_restrict_value (&blue, 0.0, 1.0);
pattern->n_stops++;
pattern->stops = realloc (pattern->stops,
sizeof (cairo_color_stop_t) * pattern->n_stops);
if (pattern->stops == NULL) {
pattern->n_stops = 0;
new_stops = realloc (pattern->stops,
sizeof (cairo_color_stop_t) * pattern->n_stops);
if (new_stops == NULL) {
pattern->n_stops--;
return CAIRO_STATUS_NO_MEMORY;
}
pattern->stops = new_stops;
stop = &pattern->stops[pattern->n_stops - 1];

View file

@ -215,7 +215,7 @@ cairo_pattern_add_color_stop (cairo_pattern_t *pattern,
double red, double green, double blue,
double alpha)
{
cairo_color_stop_t *stop;
cairo_color_stop_t *stop, *new_stops;
int i;
_cairo_restrict_value (&offset, 0.0, 1.0);
@ -224,13 +224,13 @@ cairo_pattern_add_color_stop (cairo_pattern_t *pattern,
_cairo_restrict_value (&blue, 0.0, 1.0);
pattern->n_stops++;
pattern->stops = realloc (pattern->stops,
sizeof (cairo_color_stop_t) * pattern->n_stops);
if (pattern->stops == NULL) {
pattern->n_stops = 0;
new_stops = realloc (pattern->stops,
sizeof (cairo_color_stop_t) * pattern->n_stops);
if (new_stops == NULL) {
pattern->n_stops--;
return CAIRO_STATUS_NO_MEMORY;
}
pattern->stops = new_stops;
stop = &pattern->stops[pattern->n_stops - 1];