[cairo-commit] 2 commits - src/skia test/pdf-mime-data.c

Bryce Harrington bryce at kemper.freedesktop.org
Wed Aug 27 20:40:46 PDT 2014


 src/skia/cairo-skia-surface.cpp |    4 +++-
 test/pdf-mime-data.c            |   25 ++++++++++++++-----------
 2 files changed, 17 insertions(+), 12 deletions(-)

New commits:
commit c6ae5b197623867e2baca0bf4fe2907ea55536f5
Author: Ravi Nanjundappa <nravi.n at samsung.com>
Date:   Mon Aug 25 09:28:40 2014 +0530

    test: Fix null pointer issue reported by cppcheck static analysis tool
    
    cppcheck analysis tool reports the following issues when run on the
    latest Cairo source.
    
    $ grep "(error)"  cppcheck_error_log.txt
    [test/pdf-mime-data.c:58]: (error) Possible null pointer dereference: file - otherwise it is redundant to check if file is null at line 53
    [test/pdf-mime-data.c:75]: (error) Resource leak: fp
    $
    
    The proposed changes fixes the above issues.
    
    And also it does some refactoring to print the appropriate error messages
    for each error condition in read_file() function and also to free the allocated
    data buffer.
    
    Signed-off-by: Ravi Nanjundappa <nravi.n at samsung.com>
    Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/test/pdf-mime-data.c b/test/pdf-mime-data.c
index e2c529e..fd5af1f 100644
--- a/test/pdf-mime-data.c
+++ b/test/pdf-mime-data.c
@@ -50,7 +50,7 @@ read_file (const cairo_test_context_t *ctx,
     FILE *fp;
 
     fp = fopen (file, "rb");
-    if (file == NULL) {
+    if (fp == NULL) {
 	char filename[4096];
 
 	/* try again with srcdir */
@@ -61,8 +61,11 @@ read_file (const cairo_test_context_t *ctx,
     if (fp == NULL) {
 	switch (errno) {
 	case ENOMEM:
+	    cairo_test_log (ctx, "Could not create file handle for %s due to \
+				lack of memory\n", file);
 	    return CAIRO_TEST_NO_MEMORY;
 	default:
+	    cairo_test_log (ctx, "Could not get the file handle for %s\n", file);
 	    return CAIRO_TEST_FAILURE;
 	}
     }
@@ -71,11 +74,19 @@ read_file (const cairo_test_context_t *ctx,
     *len = ftell(fp);
     fseek (fp, 0, SEEK_SET);
     *data = malloc (*len);
-    if (*data == NULL)
+    if (*data == NULL) {
+	fclose(fp);
+	cairo_test_log (ctx, "Could not allocate memory for buffer to read \
+				from file %s\n", file);
 	return CAIRO_TEST_NO_MEMORY;
+    }
 
-    if (fread(*data, *len, 1, fp) != 1)
+    if (fread(*data, *len, 1, fp) != 1) {
+	free (data);
+	fclose(fp);
+	cairo_test_log (ctx, "Could not read data from file %s\n", file);
 	return CAIRO_TEST_FAILURE;
+    }
 
     fclose(fp);
     return CAIRO_TEST_SUCCESS;
@@ -104,8 +115,6 @@ preamble (cairo_test_context_t *ctx)
     image = cairo_image_surface_create_from_png (IMAGE_FILE ".png");
     test_status = read_file (ctx, IMAGE_FILE ".jpg", &data, &len);
     if (test_status) {
-	cairo_test_log (ctx, "Could not read input jpeg file %s\n", IMAGE_FILE ".jpg");
-	free(data);
 	return test_status;
     }
 
@@ -149,17 +158,11 @@ preamble (cairo_test_context_t *ctx)
 
     test_status = read_file (ctx, IMAGE_FILE ".jpg", &data, &len);
     if (test_status) {
-	cairo_test_log (ctx, "Could not read input jpeg file %s\n", IMAGE_FILE ".jpg");
-	free(data);
 	return test_status;
     }
 
     test_status = read_file (ctx, CAIRO_TEST_OUTPUT_DIR "/" BASENAME "-000.jpg", &out_data, &out_len);
     if (test_status) {
-	free (data);
-	cairo_test_log (ctx,
-			"Could not read input jpeg file %s\n",
-			CAIRO_TEST_OUTPUT_DIR "/" BASENAME "-000.jpg");
 	return test_status;
     }
 
commit 52c4f0f2dafcc6e087a9c3c6d00c582fc272c2c2
Author: Ravi Nanjundappa <nravi.n at samsung.com>
Date:   Thu Aug 21 18:18:34 2014 +0530

    src: Fix memory issue reported by cppcheck static analysis tool
    
    cppcheck analysis tool reports the following issues when run on the
    latest Cairo source.
    
    $ grep "(error)"  cppcheck_error_log.txt
    [src/skia/cairo-skia-surface.cpp:245]: (error) Memory leak: surface
    $
    
    The proposed changes fixes the above issues.
    
    Signed-off-by: Ravi Nanjundappa <nravi.n at samsung.com>
    Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/skia/cairo-skia-surface.cpp b/src/skia/cairo-skia-surface.cpp
index 9b16bd2..834a2f1 100644
--- a/src/skia/cairo-skia-surface.cpp
+++ b/src/skia/cairo-skia-surface.cpp
@@ -241,8 +241,10 @@ _cairo_skia_surface_create_internal (SkBitmap::Config config,
     pixman_image = pixman_image_create_bits (pixman_format,
 					     width, height,
 					     (uint32_t *) data, stride);
-    if (unlikely (pixman_image == NULL))
+    if (unlikely (pixman_image == NULL)) {
+	free (surface);
 	return (cairo_skia_surface_t *) _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
+    }
 
     _cairo_surface_init (&surface->image.base,
 			 &cairo_skia_surface_backend,


More information about the cairo-commit mailing list