Fix small memory leak in c-api example

While working on creating bindings for dlang, I noticed that there was a
missing call to `sk_imageinfo_delete`, corresponding to the call to
`sk_imageinfo_new` in the c-api example. At first I thought that
`sk_surface_new_raster` (or something else) would free the image info
object internally, but after checking the implementation I saw this was
not the case.

This can be trivially verified with valgrind:

Before this change:
    $ valgrind ./skia-c-example 2>&1 | grep 'definitely lost'
    ==186215==    definitely lost: 24 bytes in 1 blocks

After:
    $ valgrind ./skia-c-example 2>&1 | grep 'definitely lost'
    ==185878==    definitely lost: 0 bytes in 0 blocks

Test: built and ran skia-c-example.c under valgrind
Change-Id: Ie3fba2e7602341d2f5e7dac198b3ec5923777cbd
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/260021
Reviewed-by: Hal Canary <halcanary@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
This commit is contained in:
Petar Kirov 2019-12-16 00:00:28 +02:00 committed by Skia Commit-Bot
parent 7b1678a527
commit 1ff585637a
2 changed files with 4 additions and 1 deletions

View File

@ -39,6 +39,7 @@ MIPS <*@imgtec.com>
NVIDIA <*@nvidia.com>
Opera Software ASA <*@opera.com>
Pavel Krajcevski <pavel@cs.unc.edu>
Petar Kirov <petar.p.kirov@gmail.com>
Raul Tambre <raul@tambre.ee>
Samsung <*@samsung.com>
Samsung Open Source Group <*@osg.samsung.com>

View File

@ -17,7 +17,9 @@
static sk_surface_t* make_surface(int32_t w, int32_t h) {
sk_imageinfo_t* info = sk_imageinfo_new(w, h, RGBA_8888_SK_COLORTYPE,
PREMUL_SK_ALPHATYPE, NULL);
return sk_surface_new_raster(info, NULL);
sk_surface_t* result = sk_surface_new_raster(info, NULL);
sk_imageinfo_delete(info);
return result;
}
static void emit_png(const char* path, sk_surface_t* surface) {