[PATCH] src and test: Fix issues reported by cppcheck static analysis tool
Ravi Nanjundappa <[email protected]>
| Newsgroups | gmane.comp.lib.cairo |
|---|---|
| Message-ID | <[email protected]> |
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 [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. Signed-off-by: Ravi Nanjundappa <[email protected]> --- src/skia/cairo-skia-surface.cpp | 4 +++- test/pdf-mime-data.c | 10 +++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) 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, diff --git a/test/pdf-mime-data.c b/test/pdf-mime-data.c index e2c529e..dba72fd 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 */ @@ -71,11 +71,15 @@ 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); return CAIRO_TEST_NO_MEMORY; + } - if (fread(*data, *len, 1, fp) != 1) + if (fread(*data, *len, 1, fp) != 1) { + fclose(fp); return CAIRO_TEST_FAILURE; + } fclose(fp); return CAIRO_TEST_SUCCESS; -- 1.7.9.5 -- cairo mailing list [email protected] http://lists.cairographics.org/mailman/listinfo/cairo