Fix a few cppcheck errors (#4281)
authorAlexander Köplinger <alex.koeplinger@outlook.com>
Mon, 23 Jan 2017 02:11:40 +0000 (03:11 +0100)
committerGitHub <noreply@github.com>
Mon, 23 Jan 2017 02:11:40 +0000 (03:11 +0100)
* [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
mono/mini/aot-compiler.c
mono/unit-tests/test-memfuncs.c
scripts/launch.c
support/inflate.c

index 79655b952b666631ee6a381d3f357422b8441dbc..ce3b9996133c7736e325536651b1d8d8b0196d9d 100644 (file)
@@ -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;
index 0d24eeb924d4bf9588ed4cd1e1515bf4d31b960b..701364be006eb4776bc2a7e94ba4ad1ebf8e7077 100644 (file)
@@ -10325,6 +10325,7 @@ load_profile_file (MonoAotCompile *acfg, char *filename)
                }
        }
 
+       fclose (infile);
        acfg->profile_data = g_list_append (acfg->profile_data, data);
 }
 
index 07c33a90eff324a61714991810a62093243072a1..af116e1906b2324321071d1df72986d89bfdb17e 100644 (file)
@@ -89,5 +89,9 @@ main (void)
                }
        }
 
+       free (random_mem);
+       free (reference);
+       free (playground);
+
        return 0;
 }
index 856f12335b32c22f3d6901a06fe0cacecdc9dfa4..4a1bd46b74718789b4b8362028d533b2abe9855c 100644 (file)
@@ -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);
index a8431abeacffd97e5028a9e54135a5f173528960..1eb2902b01d6261706e3ae6b045826da9063d165 100644 (file)
@@ -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 :