From 5a28370d8a8945877e7537762770d1119c34bf9f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexander=20K=C3=B6plinger?= Date: Mon, 23 Jan 2017 03:11:40 +0100 Subject: [PATCH] Fix a few cppcheck errors (#4281) * [zlib] Fix CppCheck error "Shifting a negative value is undefined behaviour" This matches what upstream now does: https://github.com/madler/zlib/blob/2edb94a3025d288dc251bc6cbb2c02e60fbd7438/inflate.c#L1529 * [scripts] Fix CppCheck error "Memory leak: nargv" * [tests] Fix CppCheck error: "Memory leak: reference" * [aot-compiler] Fix CppCheck error: "Resource leak: infile" * [metadata] Fix CppCheck error: "Uninitialized variable: ret" --- mono/metadata/w32process-unix-bsd.c | 2 +- mono/mini/aot-compiler.c | 1 + mono/unit-tests/test-memfuncs.c | 4 ++++ scripts/launch.c | 2 ++ support/inflate.c | 2 +- 5 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mono/metadata/w32process-unix-bsd.c b/mono/metadata/w32process-unix-bsd.c index 79655b952b6..ce3b9996133 100644 --- a/mono/metadata/w32process-unix-bsd.c +++ b/mono/metadata/w32process-unix-bsd.c @@ -24,7 +24,7 @@ mono_w32process_get_name (pid_t pid) gint mib [6]; gsize size; struct kinfo_proc *pi; - gchar *ret; + gchar *ret = NULL; #if defined(__FreeBSD__) mib [0] = CTL_KERN; diff --git a/mono/mini/aot-compiler.c b/mono/mini/aot-compiler.c index 0d24eeb924d..701364be006 100644 --- a/mono/mini/aot-compiler.c +++ b/mono/mini/aot-compiler.c @@ -10325,6 +10325,7 @@ load_profile_file (MonoAotCompile *acfg, char *filename) } } + fclose (infile); acfg->profile_data = g_list_append (acfg->profile_data, data); } diff --git a/mono/unit-tests/test-memfuncs.c b/mono/unit-tests/test-memfuncs.c index 07c33a90eff..af116e1906b 100644 --- a/mono/unit-tests/test-memfuncs.c +++ b/mono/unit-tests/test-memfuncs.c @@ -89,5 +89,9 @@ main (void) } } + free (random_mem); + free (reference); + free (playground); + return 0; } diff --git a/scripts/launch.c b/scripts/launch.c index 856f12335b3..4a1bd46b747 100644 --- a/scripts/launch.c +++ b/scripts/launch.c @@ -15,12 +15,14 @@ main (int argc, char *argv []) if (last == NULL){ fprintf (stderr, "Do not know how to invoke the program given [%s]\n", argv [0]); + free (nargv); return 1; } len = strlen (last) + strlen (PROFILE_BASE_DIR) + 1; command = malloc (len); if (command == NULL){ fprintf (stderr, "Error allocating memory"); + free (nargv); return 1; } strcpy (command, PROFILE_BASE_DIR); diff --git a/support/inflate.c b/support/inflate.c index a8431abeacf..1eb2902b01d 100644 --- a/support/inflate.c +++ b/support/inflate.c @@ -1472,7 +1472,7 @@ z_streamp strm; { struct inflate_state FAR *state; - if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16; + if (strm == Z_NULL || strm->state == Z_NULL) return -(1L << 16); state = (struct inflate_state FAR *)strm->state; return ((long)(state->back) << 16) + (state->mode == COPY ? state->length : -- 2.25.1