[Pixman] [PATCH] pixman-filter.c: Cope with NULL returns from malloc()

Søren Sandmann sandmann at cs.au.dk
Thu Dec 20 08:37:43 PST 2012


From: Søren Sandmann Pedersen <ssp at redhat.com>

v2: Don't return a pointer to uninitialized memory when the allocation
of horz and vert fails, but allocation of params doesn't.
---
 pixman/pixman-filter.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/pixman/pixman-filter.c b/pixman/pixman-filter.c
index c9d2dc7..26b39d5 100644
--- a/pixman/pixman-filter.c
+++ b/pixman/pixman-filter.c
@@ -231,6 +231,8 @@ create_1d_filter (int             *width,
     *width = ceil (size);
 
     p = params = malloc (*width * n_phases * sizeof (pixman_fixed_t));
+    if (!params)
+        return NULL;
 
     step = 1.0 / n_phases;
 
@@ -309,7 +311,7 @@ pixman_filter_create_separable_convolution (int             *n_values,
 {
     double sx = fabs (pixman_fixed_to_double (scale_x));
     double sy = fabs (pixman_fixed_to_double (scale_y));
-    pixman_fixed_t *horz, *vert, *params;
+    pixman_fixed_t *horz = NULL, *vert = NULL, *params = NULL;
     int subsample_x, subsample_y;
     int width, height;
 
@@ -319,9 +321,14 @@ pixman_filter_create_separable_convolution (int             *n_values,
     horz = create_1d_filter (&width, reconstruct_x, sample_x, sx, subsample_x);
     vert = create_1d_filter (&height, reconstruct_y, sample_y, sy, subsample_y);
 
+    if (!horz || !vert)
+        goto out;
+    
     *n_values = 4 + width * subsample_x + height * subsample_y;
     
     params = malloc (*n_values * sizeof (pixman_fixed_t));
+    if (!params)
+        goto out;
 
     params[0] = pixman_int_to_fixed (width);
     params[1] = pixman_int_to_fixed (height);
@@ -333,6 +340,7 @@ pixman_filter_create_separable_convolution (int             *n_values,
     memcpy (params + 4 + width * subsample_x, vert,
 	    height * subsample_y * sizeof (pixman_fixed_t));
 
+out:
     free (horz);
     free (vert);
 
-- 
1.7.4



More information about the Pixman mailing list