[runtime] Replace uses of alloc functions with glib variants
authorVlad Brezae <brezaevlad@gmail.com>
Tue, 30 Aug 2016 00:30:51 +0000 (00:30 +0000)
committerVlad Brezae <brezaevlad@gmail.com>
Mon, 12 Sep 2016 14:28:52 +0000 (17:28 +0300)
28 files changed:
mono/io-layer/io.c
mono/io-layer/processes.c
mono/io-layer/wapi_glob.c
mono/metadata/assembly.c
mono/metadata/exception.c
mono/metadata/icall.c
mono/metadata/locales.c
mono/metadata/marshal.c
mono/metadata/mempool.c
mono/metadata/mono-route.c
mono/metadata/null-gc.c
mono/metadata/object.c
mono/metadata/sgen-mono.c
mono/mini/aot-compiler.c
mono/mini/mini-exceptions.c
mono/profiler/decode.c
mono/profiler/mono-profiler-vtune.c
mono/profiler/proflog.c
mono/profiler/utils.c
mono/sgen/sgen-los.c
mono/utils/checked-build.c
mono/utils/lock-free-alloc.c
mono/utils/mono-codeman.c
mono/utils/mono-counters.c
mono/utils/mono-dl.c
mono/utils/mono-mmap.c
mono/utils/mono-proclib.c
mono/utils/mono-uri.c

index 496efa70bf2c349b406ddb0a722b5e6f5f57a18a..baf297ae7450123d50878ba4869eaf1df5e66ea0 100644 (file)
@@ -2038,7 +2038,7 @@ write_file (int src_fd, int dest_fd, struct stat *st_src, gboolean report_errors
        MonoThreadInfo *info = mono_thread_info_current ();
 
        buf_size = buf_size < 8192 ? 8192 : (buf_size > 65536 ? 65536 : buf_size);
-       buf = (char *) malloc (buf_size);
+       buf = (char *) g_malloc (buf_size);
 
        for (;;) {
                remain = read (src_fd, buf, buf_size);
@@ -2049,7 +2049,7 @@ write_file (int src_fd, int dest_fd, struct stat *st_src, gboolean report_errors
                        if (report_errors)
                                _wapi_set_last_error_from_errno ();
 
-                       free (buf);
+                       g_free (buf);
                        return FALSE;
                }
                if (remain == 0) {
@@ -2065,7 +2065,7 @@ write_file (int src_fd, int dest_fd, struct stat *st_src, gboolean report_errors
                                if (report_errors)
                                        _wapi_set_last_error_from_errno ();
                                MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: write failed.", __func__);
-                               free (buf);
+                               g_free (buf);
                                return FALSE;
                        }
 
@@ -2074,7 +2074,7 @@ write_file (int src_fd, int dest_fd, struct stat *st_src, gboolean report_errors
                }
        }
 
-       free (buf);
+       g_free (buf);
        return TRUE ;
 }
 
index 654c43771ebd5b4ad8e3bb421b227e61cca5dba0..35cd67eb5c0d60435aad18ee1a774c2ee52f94b9 100644 (file)
@@ -1476,7 +1476,7 @@ static int load_modules_callback (struct dl_phdr_info *info, size_t size, void *
            + sizeof (info->dlpi_phnum))
                return (-1);
 
-       struct dl_phdr_info *cpy = calloc(1, sizeof(struct dl_phdr_info));
+       struct dl_phdr_info *cpy = g_calloc (1, sizeof(struct dl_phdr_info));
        if (!cpy)
                return (-1);
 
@@ -1512,7 +1512,7 @@ static GSList *load_modules (void)
                MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: inode=%d, filename=%s, address_start=%p, address_end=%p", __func__,
                                   mod->inode, mod->filename, mod->address_start, mod->address_end);
 
-               free(info);
+               g_free (info);
 
                if (g_slist_find_custom (ret, mod, find_procmodule) == NULL) {
                        ret = g_slist_prepend (ret, mod);
@@ -1911,12 +1911,12 @@ get_process_name_from_proc (pid_t pid)
        if (sysctl(mib, 4, NULL, &size, NULL, 0) < 0)
                return(ret);
 
-       if ((pi = malloc(size)) == NULL)
+       if ((pi = g_malloc (size)) == NULL)
                return(ret);
 
        if (sysctl (mib, 4, pi, &size, NULL, 0) < 0) {
                if (errno == ENOMEM) {
-                       free(pi);
+                       g_free (pi);
                        MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Didn't allocate enough memory for kproc info", __func__);
                }
                return(ret);
@@ -1925,7 +1925,7 @@ get_process_name_from_proc (pid_t pid)
        if (strlen (pi->kp_proc.p_comm) > 0)
                ret = g_strdup (pi->kp_proc.p_comm);
 
-       free(pi);
+       g_free (pi);
 #endif
 #elif defined(USE_BSD_LOADER)
 #if defined(__FreeBSD__)
@@ -1938,12 +1938,12 @@ get_process_name_from_proc (pid_t pid)
                return(ret);
        }
 
-       if ((pi = malloc(size)) == NULL)
+       if ((pi = g_malloc (size)) == NULL)
                return(ret);
 
        if (sysctl (mib, 4, pi, &size, NULL, 0) < 0) {
                if (errno == ENOMEM) {
-                       free(pi);
+                       g_free (pi);
                        MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s: Didn't allocate enough memory for kproc info", __func__);
                }
                return(ret);
@@ -1951,7 +1951,7 @@ get_process_name_from_proc (pid_t pid)
 
        if (strlen (pi->ki_comm) > 0)
                ret = g_strdup (pi->ki_comm);
-       free(pi);
+       g_free (pi);
 #elif defined(__OpenBSD__)
        mib [0] = CTL_KERN;
        mib [1] = KERN_PROC;
@@ -1966,7 +1966,7 @@ retry:
                return(ret);
        }
 
-       if ((pi = malloc(size)) == NULL)
+       if ((pi = g_malloc (size)) == NULL)
                return(ret);
 
        mib[5] = (int)(size / sizeof(struct kinfo_proc));
@@ -1974,7 +1974,7 @@ retry:
        if ((sysctl (mib, 6, pi, &size, NULL, 0) < 0) ||
                (size != sizeof (struct kinfo_proc))) {
                if (errno == ENOMEM) {
-                       free(pi);
+                       g_free (pi);
                        goto retry;
                }
                return(ret);
@@ -1983,7 +1983,7 @@ retry:
        if (strlen (pi->p_comm) > 0)
                ret = g_strdup (pi->p_comm);
 
-       free(pi);
+       g_free (pi);
 #endif
 #elif defined(USE_HAIKU_LOADER)
        image_info imageInfo;
index 88864821be44d394939dd5d19a9c87239eee38f7..013b778a86579d088ef71551af526cffb572b192 100644 (file)
@@ -267,11 +267,11 @@ globextend(const gchar *path, wapi_glob_t *pglob, size_t *limitp)
 
        newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs);
        /* FIXME: Can just use realloc(). */
-       pathv = (char **)(pglob->gl_pathv ? realloc((char *)pglob->gl_pathv, newsize) :
-           malloc(newsize));
+       pathv = (char **)(pglob->gl_pathv ? g_realloc ((char *)pglob->gl_pathv, newsize) :
+           g_malloc (newsize));
        if (pathv == NULL) {
                if (pglob->gl_pathv) {
-                       free(pglob->gl_pathv);
+                       g_free (pglob->gl_pathv);
                        pglob->gl_pathv = NULL;
                }
                return(WAPI_GLOB_NOSPACE);
@@ -291,7 +291,7 @@ globextend(const gchar *path, wapi_glob_t *pglob, size_t *limitp)
        *limitp += len;
        if ((copy = (char *)malloc(len)) != NULL) {
                if (g_Ctoc(path, copy, len)) {
-                       free(copy);
+                       g_free (copy);
                        return(WAPI_GLOB_NOSPACE);
                }
                pathv[pglob->gl_offs + pglob->gl_pathc++] = copy;
@@ -361,8 +361,8 @@ _wapi_globfree(wapi_glob_t *pglob)
                pp = pglob->gl_pathv + pglob->gl_offs;
                for (i = pglob->gl_pathc; i--; ++pp)
                        if (*pp)
-                               free(*pp);
-               free(pglob->gl_pathv);
+                               g_free (*pp);
+               g_free (pglob->gl_pathv);
                pglob->gl_pathv = NULL;
        }
 }
index 0744389c400bf4539c0d88f3e530df2a95436b6e..96025d9d06a775c5539634654ff4fedeb998bc18 100644 (file)
@@ -2355,11 +2355,11 @@ mono_assembly_name_parse_full (const char *name, MonoAssemblyName *aname, gboole
                        if (!g_ascii_strcasecmp (retargetable, "yes")) {
                                flags |= ASSEMBLYREF_RETARGETABLE_FLAG;
                        } else if (g_ascii_strcasecmp (retargetable, "no")) {
-                               free (retargetable_uq);
+                               g_free (retargetable_uq);
                                goto cleanup_and_fail;
                        }
 
-                       free (retargetable_uq);
+                       g_free (retargetable_uq);
                        tmp++;
                        continue;
                }
@@ -2379,11 +2379,11 @@ mono_assembly_name_parse_full (const char *name, MonoAssemblyName *aname, gboole
                        else if (!g_ascii_strcasecmp (procarch, "AMD64"))
                                arch = MONO_PROCESSOR_ARCHITECTURE_AMD64;
                        else {
-                               free (procarch_uq);
+                               g_free (procarch_uq);
                                goto cleanup_and_fail;
                        }
 
-                       free (procarch_uq);
+                       g_free (procarch_uq);
                        tmp++;
                        continue;
                }
@@ -2411,11 +2411,11 @@ mono_assembly_name_parse_full (const char *name, MonoAssemblyName *aname, gboole
                key_uq == NULL ? key : key_uq,
                flags, arch, aname, save_public_key);
 
-       free (dllname_uq);
-       free (version_uq);
-       free (culture_uq);
-       free (token_uq);
-       free (key_uq);
+       g_free (dllname_uq);
+       g_free (version_uq);
+       g_free (culture_uq);
+       g_free (token_uq);
+       g_free (key_uq);
 
        g_strfreev (parts);
        return res;
index 09b498ab559bdeabe7fa97e88f6c76634f203809..02b738556c597c72fbc7ed9fe76a5acead5d97eb 100644 (file)
@@ -991,7 +991,7 @@ mono_exception_get_native_backtrace (MonoException *exc)
                }
        }
 
-       free (messages);
+       g_free (messages);
        return g_string_free (text, FALSE);
 #else
        return g_strdup ("");
index b331969129c56a55224645737b08f9170aabb97f..95374177657f2c3ec76172736bd339e1cdef396b 100644 (file)
@@ -6940,7 +6940,7 @@ ves_icall_System_Text_EncodingHelper_InternalCodePage (gint32 *int_code_page)
        
        if (strstr (codepage, "utf_8") != NULL)
                *int_code_page |= 0x10000000;
-       free (codepage);
+       g_free (codepage);
        
        if (want_name && *int_code_page == -1)
                return mono_string_new (mono_domain_get (), cset);
index bcb0dc3c0146748719a55c6a9002fc609a2c61b4..783b528339c41d84657ab7ae50fcd0b0eb5831b9 100644 (file)
@@ -434,7 +434,7 @@ get_darwin_locale (void)
                                        len += bytes_converted + 1;
                                }
 
-                               darwin_locale = (char *) malloc (len + 1);
+                               darwin_locale = (char *) g_malloc (len + 1);
                                CFStringGetBytes (locale_language, CFRangeMake (0, CFStringGetLength (locale_language)), kCFStringEncodingMacRoman, 0, FALSE, (UInt8 *) darwin_locale, len, &bytes_converted);
 
                                darwin_locale[bytes_converted] = '-';
@@ -454,9 +454,9 @@ get_darwin_locale (void)
 
                        if (locale_cfstr) {
                                len = CFStringGetMaximumSizeForEncoding (CFStringGetLength (locale_cfstr), kCFStringEncodingMacRoman) + 1;
-                               darwin_locale = (char *) malloc (len);
+                               darwin_locale = (char *) g_malloc (len);
                                if (!CFStringGetCString (locale_cfstr, darwin_locale, len, kCFStringEncodingMacRoman)) {
-                                       free (darwin_locale);
+                                       g_free (darwin_locale);
                                        CFRelease (locale);
                                        darwin_locale = NULL;
                                        return NULL;
index 5b290e74947ff5143a963c5a2e891c4d7d71fc3f..b457211c83da5d2ffd2116bae62c9acb98e4e408 100644 (file)
@@ -778,7 +778,7 @@ mono_free_lparray (MonoArray *array, gpointer* nativeArray)
        if (klass->element_class->byval_arg.type == MONO_TYPE_CLASS) {
                for(i = 0; i < array->max_length; ++i)
                        mono_marshal_free_ccw (mono_array_get (array, MonoObject*, i));
-               free(nativeArray);
+               g_free (nativeArray);
        }
 #endif
 }
index 6bf3410d818ec7115921f01c4e9c45dd27109e80..214c9e2128fd5349d51d9d9f46c6e542e9751db3 100644 (file)
@@ -215,7 +215,7 @@ mono_backtrace (int size)
         for (i = 1; i < symbols; ++i) {
                 g_print ("\t%s\n", names [i]);
         }
-        free (names);
+        g_free (names);
         mono_os_mutex_unlock (&mempool_tracing_lock);
 }
 
index d651b0e5b08387b9b4829e0ce74b612e1fc3cc54..5f3ecb93ea65582aaadb6081e7cfa9e1f2f0c7dc 100644 (file)
@@ -53,7 +53,7 @@ extern MonoBoolean ves_icall_System_Net_NetworkInformation_MacOsIPInterfacePrope
                return FALSE;
 
        // Allocate suffcient memory for available data based on the previous sysctl call
-       if ((buf = malloc(needed)) == NULL)
+       if ((buf = g_malloc (needed)) == NULL)
                return FALSE;
 
        // Second sysctl call to retrieve data into appropriately sized buffer
@@ -102,7 +102,7 @@ extern MonoBoolean ves_icall_System_Net_NetworkInformation_MacOsIPInterfacePrope
                mono_array_setref (*gw_addr_list, gwnum, addr_string);
                gwnum++;
        }
-       free(buf);
+       g_free (buf);
        return TRUE;
 }
 
index 47d7dc5b1decdcde5b5cec33b24527f639ddc41d..1ab1e0ebb2d3279e98a411d2151779e1bdfc1062 100644 (file)
@@ -191,7 +191,7 @@ mono_gc_free_fixed (void* addr)
 void *
 mono_gc_alloc_obj (MonoVTable *vtable, size_t size)
 {
-       MonoObject *obj = calloc (1, size);
+       MonoObject *obj = g_calloc (1, size);
 
        obj->vtable = vtable;
 
@@ -201,7 +201,7 @@ mono_gc_alloc_obj (MonoVTable *vtable, size_t size)
 void *
 mono_gc_alloc_vector (MonoVTable *vtable, size_t size, uintptr_t max_length)
 {
-       MonoArray *obj = calloc (1, size);
+       MonoArray *obj = g_calloc (1, size);
 
        obj->obj.vtable = vtable;
        obj->max_length = max_length;
@@ -212,7 +212,7 @@ mono_gc_alloc_vector (MonoVTable *vtable, size_t size, uintptr_t max_length)
 void *
 mono_gc_alloc_array (MonoVTable *vtable, size_t size, uintptr_t max_length, uintptr_t bounds_size)
 {
-       MonoArray *obj = calloc (1, size);
+       MonoArray *obj = g_calloc (1, size);
 
        obj->obj.vtable = vtable;
        obj->max_length = max_length;
@@ -226,7 +226,7 @@ mono_gc_alloc_array (MonoVTable *vtable, size_t size, uintptr_t max_length, uint
 void *
 mono_gc_alloc_string (MonoVTable *vtable, size_t size, gint32 len)
 {
-       MonoString *obj = calloc (1, size);
+       MonoString *obj = g_calloc (1, size);
 
        obj->object.vtable = vtable;
        obj->length = len;
index 0aede5fbb2092feb2ec7ad9c1b53ddfce4a1e903..917bfd954dba27041bf05c7061747d898e0c3f09 100644 (file)
@@ -1206,7 +1206,7 @@ mono_method_get_imt_slot (MonoMethod *method)
                break;
        }
        
-       free (hashes_start);
+       g_free (hashes_start);
        /* Report the result */
        return c % MONO_IMT_SIZE;
 }
@@ -1334,7 +1334,7 @@ imt_sort_slot_entries (MonoImtBuilderEntry *entries) {
 
        imt_emit_ir (sorted_array, 0, number_of_entries, result);
 
-       free (sorted_array);
+       g_free (sorted_array);
        return result;
 }
 
@@ -1514,7 +1514,7 @@ build_imt_slots (MonoClass *klass, MonoVTable *vt, MonoDomain *domain, gpointer*
                        entry = next;
                }
        }
-       free (imt_builder);
+       g_free (imt_builder);
        /* we OR the bitmap since we may build just a single imt slot at a time */
        vt->imt_collisions_bitmap |= imt_collisions_bitmap;
 }
index c4feb7fa150a82831e45d81a6abd870d995ad25c..c902fcdbe5a92ad3aa5427b21c4bceed9ce42e0a 100644 (file)
@@ -968,11 +968,11 @@ void*
 mono_gc_alloc_fixed (size_t size, MonoGCDescriptor descr, MonoGCRootSource source, const char *msg)
 {
        /* FIXME: do a single allocation */
-       void *res = calloc (1, size);
+       void *res = g_calloc (1, size);
        if (!res)
                return NULL;
        if (!mono_gc_register_root ((char *)res, size, descr, source, msg)) {
-               free (res);
+               g_free (res);
                res = NULL;
        }
        return res;
@@ -982,7 +982,7 @@ void
 mono_gc_free_fixed (void* addr)
 {
        mono_gc_deregister_root ((char *)addr);
-       free (addr);
+       g_free (addr);
 }
 
 /*
index 5379f3bcf069d932f91ce5f850fad728f5f23121..9164369a23078387448629393409342226a4aecd 100644 (file)
@@ -8685,7 +8685,7 @@ mono_aot_method_hash (MonoMethod *method)
                break;
        }
        
-       free (hashes_start);
+       g_free (hashes_start);
        
        return c;
 }
index 0fabbf8314b4add9e535f5690e9be12163dbddaa..265be946e51a8309da60e9c35721695acc315a7e 100644 (file)
@@ -2389,7 +2389,7 @@ mono_handle_native_sigsegv (int signal, void *ctx, MONO_SIG_HANDLER_INFO_TYPE *i
        for (i =0; i < size; ++i) {
                mono_runtime_printf_err ("\t%s", names [i]);
        }
-       free (names);
+       g_free (names);
 
        /* Try to get more meaningful information using gdb */
 
index b213528caaa35b55a02a43f0c8b2329a40eeab75..338150494dd0315582003170457d0172b9294b31 100644 (file)
@@ -633,7 +633,7 @@ add_class (intptr_t klass, const char *name)
        /* we resolved an unknown class (unless we had the code unloaded) */
        if (cd) {
                /*printf ("resolved unknown: %s\n", name);*/
-               free (cd->name);
+               g_free (cd->name);
                cd->name = pstrdup (name);
                return cd;
        }
@@ -699,7 +699,7 @@ add_method (intptr_t method, const char *name, intptr_t code, int len)
                cd->code = code;
                cd->len = len;
                /*printf ("resolved unknown: %s\n", name);*/
-               free (cd->name);
+               g_free (cd->name);
                cd->name = pstrdup (name);
                return cd;
        }
@@ -1099,7 +1099,7 @@ add_heap_class_rev (HeapClassDesc *from, HeapClassDesc *to)
                                add_rev_class_hashed (n, to->rev_hash_size, to->rev_hash [i].klass, to->rev_hash [i].count);
                }
                if (to->rev_hash)
-                       free (to->rev_hash);
+                       g_free (to->rev_hash);
                to->rev_hash = n;
        }
        to->rev_count += add_rev_class_hashed (to->rev_hash, to->rev_hash_size, from, 1);
@@ -1217,7 +1217,7 @@ add_heap_shot_class (HeapShot *hs, ClassDesc *klass, uint64_t size)
                                add_heap_hashed (n, &res, hs->hash_size, hs->class_hash [i]->klass, hs->class_hash [i]->total_size, hs->class_hash [i]->count);
                }
                if (hs->class_hash)
-                       free (hs->class_hash);
+                       g_free (hs->class_hash);
                hs->class_hash = n;
        }
        res = NULL;
@@ -1269,7 +1269,7 @@ heap_shot_obj_add_refs (HeapShot *hs, uintptr_t objaddr, uintptr_t num, uintptr_
                HeapObjectDesc* ho = alloc_heap_obj (objaddr, hash [i]->hklass, hash [i]->num_refs + num);
                *ref_offset = hash [i]->num_refs;
                memcpy (ho->refs, hash [i]->refs, hash [i]->num_refs * sizeof (uintptr_t));
-               free (hash [i]);
+               g_free (hash [i]);
                hash [i] = ho;
                return ho;
        }
@@ -1319,7 +1319,7 @@ add_heap_shot_obj (HeapShot *hs, HeapObjectDesc *obj)
                                add_heap_hashed_obj (n, hs->objects_hash_size, hs->objects_hash [i]);
                }
                if (hs->objects_hash)
-                       free (hs->objects_hash);
+                       g_free (hs->objects_hash);
                hs->objects_hash = n;
        }
        hs->objects_count += add_heap_hashed_obj (hs->objects_hash, hs->objects_hash_size, obj);
@@ -1413,7 +1413,7 @@ heap_shot_mark_objects (HeapShot *hs)
                }
        }
        fprintf (outfile, "Total unmarked: %zd/%zd\n", num_unmarked, hs->objects_count);
-       free (marks);
+       g_free (marks);
 }
 
 static void
@@ -1423,10 +1423,10 @@ heap_shot_free_objects (HeapShot *hs)
        for (i = 0; i < hs->objects_hash_size; ++i) {
                HeapObjectDesc *ho = hs->objects_hash [i];
                if (ho)
-                       free (ho);
+                       g_free (ho);
        }
        if (hs->objects_hash)
-               free (hs->objects_hash);
+               g_free (hs->objects_hash);
        hs->objects_hash = NULL;
        hs->objects_hash_size = 0;
        hs->objects_count = 0;
@@ -1726,7 +1726,7 @@ add_trace_bt (BackTrace *bt, TraceDesc *trace, uint64_t value)
                                add_trace_hashed (n, trace->size, trace->traces [i].bt, trace->traces [i].count);
                }
                if (trace->traces)
-                       free (trace->traces);
+                       g_free (trace->traces);
                trace->traces = n;
        }
        trace->count += add_trace_hashed (trace->traces, trace->size, bt, value);
@@ -2371,7 +2371,7 @@ decode_buffer (ProfContext *ctx)
                                if (debug)
                                        fprintf (outfile, "handle (%s) %u created for object %p\n", get_handle_name (htype), handle, (void*)OBJ_ADDR (objdiff));
                                if (frames != sframes)
-                                       free (frames);
+                                       g_free (frames);
                        } else if (subtype == TYPE_GC_HANDLE_DESTROYED || subtype == TYPE_GC_HANDLE_DESTROYED_BT) {
                                int has_bt = subtype == TYPE_GC_HANDLE_DESTROYED_BT;
                                int num_bt = 0;
@@ -2402,7 +2402,7 @@ decode_buffer (ProfContext *ctx)
                                if (debug)
                                        fprintf (outfile, "handle (%s) %u destroyed\n", get_handle_name (htype), handle);
                                if (frames != sframes)
-                                       free (frames);
+                                       g_free (frames);
                        } else if (subtype == TYPE_GC_FINALIZE_START) {
                                // TODO: Generate a finalizer report based on these events.
                                if (debug)
@@ -2543,7 +2543,7 @@ decode_buffer (ProfContext *ctx)
                                        tracked_creation (OBJ_ADDR (objdiff), cd, len, bt, time_base);
                        }
                        if (frames != sframes)
-                               free (frames);
+                               g_free (frames);
                        break;
                }
                case TYPE_METHOD: {
@@ -2666,9 +2666,9 @@ decode_buffer (ProfContext *ctx)
                                                hs->roots_extra = thread->roots_extra;
                                                hs->roots_types = thread->roots_types;
                                        } else {
-                                               free (thread->roots);
-                                               free (thread->roots_extra);
-                                               free (thread->roots_types);
+                                               g_free (thread->roots);
+                                               g_free (thread->roots_extra);
+                                               g_free (thread->roots_types);
                                        }
                                        thread->num_roots = 0;
                                        thread->size_roots = 0;
@@ -2753,7 +2753,7 @@ decode_buffer (ProfContext *ctx)
                        if (debug)
                                fprintf (outfile, "monitor %s for object %p\n", monitor_ev_name (event), (void*)OBJ_ADDR (objdiff));
                        if (frames != sframes)
-                               free (frames);
+                               g_free (frames);
                        break;
                }
                case TYPE_EXCEPTION: {
@@ -2799,7 +2799,7 @@ decode_buffer (ProfContext *ctx)
                                                add_trace_thread (thread, &exc_traces, 1);
                                }
                                if (frames != sframes)
-                                       free (frames);
+                                       g_free (frames);
                                if (debug)
                                        fprintf (outfile, "throw %p\n", (void*)OBJ_ADDR (objdiff));
                        }
@@ -3698,9 +3698,9 @@ heap_shot_summary (HeapShot *hs, int hs_num, HeapShot *last_hs)
                if (cd->root_references)
                        fprintf (outfile, "\t\t%zd root references (%zd pinning)\n", cd->root_references, cd->pinned_references);
                dump_rev_claases (rev_sorted, cd->rev_count);
-               free (rev_sorted);
+               g_free (rev_sorted);
        }
-       free (sorted);
+       g_free (sorted);
 }
 
 static int
@@ -4216,7 +4216,7 @@ main (int argc, char *argv[])
                        *top++ = 0;
                        from_secs = atof (val);
                        to_secs = atof (top);
-                       free (val);
+                       g_free (val);
                        if (from_secs > to_secs) {
                                usage ();
                                return 1;
index 3f071a108798834e9b64cbc978a537336940bb8b..78de58aaa08de08e66e16439a294f494979335c5 100644 (file)
@@ -109,7 +109,7 @@ method_jit_result (MonoProfiler *prof, MonoMethod *method, MonoJitInfo* jinfo, i
                                sourceLoc = mono_debug_lookup_source_location (method, dmji->line_numbers[i].native_offset, mono_domain_get());
                                if (sourceLoc == NULL)
                                {
-                                       free(vtuneMethod.line_number_table);
+                                       g_free (vtuneMethod.line_number_table);
                                        vtuneMethod.line_number_table = NULL;
                                        vtuneMethod.line_number_size = 0;
                                        break;
@@ -126,9 +126,9 @@ method_jit_result (MonoProfiler *prof, MonoMethod *method, MonoJitInfo* jinfo, i
                iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, &vtuneMethod);
 
                if (vtuneMethod.source_file_name != NULL)
-                       free(vtuneMethod.source_file_name);
+                       g_free (vtuneMethod.source_file_name);
                if (vtuneMethod.line_number_table != NULL)
-                       free(vtuneMethod.line_number_table);
+                       g_free (vtuneMethod.line_number_table);
        
                g_free (signature);
                g_free (name);
index 6df5322437a596a4cb2b497ca36362b3825b3b3b..17f43836afdee6caccfd37e4889a97851a61b939 100644 (file)
@@ -1939,7 +1939,7 @@ class_loaded (MonoProfiler *prof, MonoClass *klass, int result)
        if (runtime_inited)
                mono_free (name);
        else
-               free (name);
+               g_free (name);
 
        send_if_needed (prof);
 
@@ -1983,7 +1983,7 @@ class_unloaded (MonoProfiler *prof, MonoClass *klass)
        if (runtime_inited)
                mono_free (name);
        else
-               free (name);
+               g_free (name);
 
        send_if_needed (prof);
 
@@ -2562,7 +2562,7 @@ add_code_pointer (uintptr_t ip)
                                add_code_page (n, size_code_pages, code_pages [i]);
                }
                if (code_pages)
-                       free (code_pages);
+                       g_free (code_pages);
                code_pages = n;
        }
        num_code_pages += add_code_page (code_pages, size_code_pages, ip & CPAGE_MASK);
@@ -2742,7 +2742,7 @@ elf_dl_callback (struct dl_phdr_info *info, size_t size, void *data)
                        filename = buf;
                }
        }
-       obj = calloc (sizeof (BinaryObject), 1);
+       obj = g_calloc (sizeof (BinaryObject), 1);
        obj->addr = (void*)info->dlpi_addr;
        obj->name = pstrdup (filename);
        obj->next = prof->binary_objects;
@@ -2816,7 +2816,7 @@ symbol_for (uintptr_t code)
                names = backtrace_symbols (&ip, 1);
                if (names) {
                        const char* p = names [0];
-                       free (names);
+                       g_free (names);
                        return p;
                }
                */
@@ -3143,13 +3143,13 @@ setup_perf_event (void)
        int i, count = 0;
        mmap_mask = num_pages * getpagesize () - 1;
        num_perf = mono_cpu_count ();
-       perf_data = calloc (num_perf, sizeof (PerfData));
+       perf_data = g_calloc (num_perf, sizeof (PerfData));
        for (i = 0; i < num_perf; ++i) {
                count += setup_perf_event_for_cpu (perf_data + i, i);
        }
        if (count)
                return 1;
-       free (perf_data);
+       g_free (perf_data);
        perf_data = NULL;
        return 0;
 }
@@ -3187,7 +3187,7 @@ counters_add_agent (MonoCounter *counter)
                if (agent->counter == counter) {
                        agent->value_size = 0;
                        if (agent->value) {
-                               free (agent->value);
+                               g_free (agent->value);
                                agent->value = NULL;
                        }
                        mono_os_mutex_unlock (&counters_mutex);
@@ -3316,7 +3316,7 @@ counters_sample (MonoProfiler *profiler, uint64_t timestamp)
        counters_emit (profiler);
 
        buffer_size = 8;
-       buffer = calloc (1, buffer_size);
+       buffer = g_calloc (1, buffer_size);
 
        mono_os_mutex_lock (&counters_mutex);
 
@@ -3352,7 +3352,7 @@ counters_sample (MonoProfiler *profiler, uint64_t timestamp)
                        continue; // FIXME error
                } else if (size > buffer_size) {
                        buffer_size = size;
-                       buffer = realloc (buffer, buffer_size);
+                       buffer = g_realloc (buffer, buffer_size);
                }
 
                memset (buffer, 0, buffer_size);
@@ -3363,7 +3363,7 @@ counters_sample (MonoProfiler *profiler, uint64_t timestamp)
                type = mono_counter_get_type (counter);
 
                if (!agent->value) {
-                       agent->value = calloc (1, size);
+                       agent->value = g_calloc (1, size);
                        agent->value_size = size;
                } else {
                        if (type == MONO_COUNTER_STRING) {
@@ -3413,14 +3413,14 @@ counters_sample (MonoProfiler *profiler, uint64_t timestamp)
                }
 
                if (type == MONO_COUNTER_STRING && size > agent->value_size) {
-                       agent->value = realloc (agent->value, size);
+                       agent->value = g_realloc (agent->value, size);
                        agent->value_size = size;
                }
 
                if (size > 0)
                        memcpy (agent->value, buffer, size);
        }
-       free (buffer);
+       g_free (buffer);
 
        emit_value (logbuffer, 0);
 
@@ -4350,8 +4350,8 @@ log_shutdown (MonoProfiler *prof)
 
        PROF_TLS_FREE ();
 
-       free (prof->args);
-       free (prof);
+       g_free (prof->args);
+       g_free (prof);
 }
 
 static char*
@@ -4660,7 +4660,7 @@ handle_writer_queue_entry (MonoProfiler *prof)
                        mono_free (name);
 
                free_info:
-                       free (info);
+                       g_free (info);
                }
 
                g_ptr_array_free (entry->methods, TRUE);
@@ -4889,7 +4889,7 @@ create_profiler (const char *args, const char *filename, GPtrArray *filters)
                        int s = strlen (nf) + 32;
                        char *p = (char *)malloc (s);
                        snprintf (p, s, "|mprof-report '--out=%s' -", nf);
-                       free (nf);
+                       g_free (nf);
                        nf = p;
                }
        }
@@ -5074,7 +5074,7 @@ set_sample_mode (char* val, int allow_empty)
        if (strcmp (val, "mono") == 0) {
                do_mono_sample = 1;
                sample_type = SAMPLE_CYCLES;
-               free (val);
+               g_free (val);
                return;
        }
        for (smode = sample_modes; smode->name; smode++) {
@@ -5097,7 +5097,7 @@ set_sample_mode (char* val, int allow_empty)
        } else {
                sample_freq = 100;
        }
-       free (val);
+       g_free (val);
 }
 
 static void
@@ -5109,7 +5109,7 @@ set_hsmode (char* val, int allow_empty)
                return;
        if (strcmp (val, "ondemand") == 0) {
                hs_mode_ondemand = 1;
-               free (val);
+               g_free (val);
                return;
        }
        count = strtoul (val, &end, 10);
@@ -5121,7 +5121,7 @@ set_hsmode (char* val, int allow_empty)
                hs_mode_gc = count;
        else
                usage (1);
-       free (val);
+       g_free (val);
 }
 
 /*
@@ -5206,7 +5206,7 @@ mono_profiler_startup (const char *desc)
                                fast_time = 2;
                        else
                                usage (1);
-                       free (val);
+                       g_free (val);
                        continue;
                }
                if ((opt = match_option (p, "report", NULL)) != p) {
@@ -5256,7 +5256,7 @@ mono_profiler_startup (const char *desc)
                if ((opt = match_option (p, "port", &val)) != p) {
                        char *end;
                        command_port = strtoul (val, &end, 10);
-                       free (val);
+                       g_free (val);
                        continue;
                }
                if ((opt = match_option (p, "maxframes", &val)) != p) {
@@ -5264,7 +5264,7 @@ mono_profiler_startup (const char *desc)
                        num_frames = strtoul (val, &end, 10);
                        if (num_frames > MAX_FRAMES)
                                num_frames = MAX_FRAMES;
-                       free (val);
+                       g_free (val);
                        notraces = num_frames == 0;
                        continue;
                }
@@ -5273,13 +5273,13 @@ mono_profiler_startup (const char *desc)
                        max_allocated_sample_hits = strtoul (val, &end, 10);
                        if (!max_allocated_sample_hits)
                                max_allocated_sample_hits = G_MAXINT32;
-                       free (val);
+                       g_free (val);
                        continue;
                }
                if ((opt = match_option (p, "calldepth", &val)) != p) {
                        char *end;
                        max_call_depth = strtoul (val, &end, 10);
-                       free (val);
+                       g_free (val);
                        continue;
                }
                if ((opt = match_option (p, "counters", NULL)) != p) {
index c3e14e4af89065ae8683cd821e6d155251eab515..cfa7589a6b2bd0edaf550bea60c8250e680bc536 100644 (file)
@@ -26,7 +26,7 @@
 #include <pthread.h>
 #include <sched.h>
 #endif
-
+#include <glib.h>
 
 #ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
@@ -61,7 +61,7 @@ typedef struct {
 
 #ifdef HOST_WIN32
 static int tls_data;
-#define DECL_TLS_DATA TlsData *tls; tls = (TlsData *) TlsGetValue (tls_data); if (tls == NULL) { tls = (TlsData *) calloc (sizeof (TlsData), 1); TlsSetValue (tls_data, tls); }
+#define DECL_TLS_DATA TlsData *tls; tls = (TlsData *) TlsGetValue (tls_data); if (tls == NULL) { tls = (TlsData *) g_calloc (sizeof (TlsData), 1); TlsSetValue (tls_data, tls); }
 #define TLS_INIT(x) x = TlsAlloc()
 #elif HAVE_KW_THREAD
 static __thread TlsData tls_data;
@@ -69,7 +69,7 @@ static __thread TlsData tls_data;
 #define TLS_INIT(x)
 #else
 static pthread_key_t tls_data;
-#define DECL_TLS_DATA TlsData *tls; tls = (TlsData *) pthread_getspecific (tls_data); if (tls == NULL) { tls = (TlsData *) calloc (sizeof (TlsData), 1); pthread_setspecific (tls_data, tls); }
+#define DECL_TLS_DATA TlsData *tls; tls = (TlsData *) pthread_getspecific (tls_data); if (tls == NULL) { tls = (TlsData *) g_calloc (sizeof (TlsData), 1); pthread_setspecific (tls_data, tls); }
 #define TLS_INIT(x) pthread_key_create(&x, NULL)
 #endif
 
index deb4439afbf0fc3f031dfd52cb127d21cd478e77..454cb89fda70eb88ce31bd6277b148fb323acf64 100644 (file)
@@ -323,7 +323,7 @@ sgen_los_free_object (LOSObject *obj)
        los_num_objects--;
 
 #ifdef USE_MALLOC
-       free (obj);
+       g_free (obj);
 #else
        if (size > LOS_SECTION_OBJECT_LIMIT) {
                int pagesize = mono_pagesize ();
@@ -379,7 +379,7 @@ sgen_los_alloc_large_inner (GCVTable vtable, size_t size)
        sgen_ensure_free_space (size, GENERATION_OLD);
 
 #ifdef USE_MALLOC
-       obj = malloc (size + sizeof (LOSObject));
+       obj = g_malloc (size + sizeof (LOSObject));
        memset (obj, 0, size + sizeof (LOSObject));
 #else
        if (size > LOS_SECTION_OBJECT_LIMIT) {
index 6f5606bdb80919b7890bd9bed1da15997a77757d..43a690c75920671419df88b5d2dc80ba1f8c1ca0 100644 (file)
@@ -146,7 +146,7 @@ translate_backtrace (gpointer native_trace[], int size)
                        g_string_append_printf (bt, "\tat %s\n", names [i]);
        }
 
-       free (names);
+       g_free (names);
        return g_string_free (bt, FALSE);
 }
 
index 399bd68c8379148ca15cebf0d0d114c91baf9620..08b4deff37c0379b92524ce00ee5788e717b57b0 100644 (file)
@@ -246,7 +246,7 @@ desc_alloc (MonoMemAccountType type)
        if (desc)
                return desc;
 
-       return calloc (1, sizeof (Descriptor));
+       return g_calloc (1, sizeof (Descriptor));
 }
 
 static void
index a6188e27350e9b13d744ba6f01024ba4f4da5617..56948bdd901da23ae66edd34b6e7d19cf218c902 100644 (file)
@@ -234,7 +234,7 @@ free_chunklist (CodeChunk *chunk)
                        dlfree (dead->data);
                }
                code_memory_used -= dead->size;
-               free (dead);
+               g_free (dead);
        }
 }
 
@@ -249,7 +249,7 @@ mono_code_manager_destroy (MonoCodeManager *cman)
 {
        free_chunklist (cman->full);
        free_chunklist (cman->current);
-       free (cman);
+       g_free (cman);
 }
 
 /**
@@ -398,7 +398,7 @@ new_codechunk (CodeChunk *last, int dynamic, int size)
 #endif
        }
 
-       chunk = (CodeChunk *) malloc (sizeof (CodeChunk));
+       chunk = (CodeChunk *) g_malloc (sizeof (CodeChunk));
        if (!chunk) {
                if (flags == CODE_FLAG_MALLOC)
                        dlfree (ptr);
index 2ca19a8b3d645fca66230e58f15d4b0e2b9cccf2..ae33b4a9f39336cb31f1c31f31d43ee7e4d497ed 100644 (file)
@@ -166,7 +166,7 @@ register_internal (const char *name, int type, void *addr, int size)
                }
        }
 
-       counter = (MonoCounter *) malloc (sizeof (MonoCounter));
+       counter = (MonoCounter *) g_malloc (sizeof (MonoCounter));
        if (!counter) {
                mono_os_mutex_unlock (&counters_mutex);
                return;
@@ -648,8 +648,8 @@ mono_counters_cleanup (void)
        while (counter) {
                MonoCounter *tmp = counter;
                counter = counter->next;
-               free ((void*)tmp->name);
-               free (tmp);
+               g_free ((void*)tmp->name);
+               g_free (tmp);
        }
 
        mono_os_mutex_unlock (&counters_mutex);
index 43116130309eec7195e24a87f8d39e10e544dbce..6c0f582cf6d1ddc170d86bf4f6fb40374138525a 100644 (file)
@@ -140,7 +140,7 @@ mono_dl_open (const char *name, int flags, char **error_msg)
        if (error_msg)
                *error_msg = NULL;
 
-       module = (MonoDl *) malloc (sizeof (MonoDl));
+       module = (MonoDl *) g_malloc (sizeof (MonoDl));
        if (!module) {
                if (error_msg)
                        *error_msg = g_strdup ("Out of memory");
@@ -174,7 +174,7 @@ mono_dl_open (const char *name, int flags, char **error_msg)
                const char *ext;
                /* This platform does not support dlopen */
                if (name == NULL) {
-                       free (module);
+                       g_free (module);
                        return NULL;
                }
                
@@ -193,7 +193,7 @@ mono_dl_open (const char *name, int flags, char **error_msg)
                        if (error_msg) {
                                *error_msg = mono_dl_current_error_string ();
                        }
-                       free (module);
+                       g_free (module);
                        return NULL;
                }
        }
@@ -224,11 +224,11 @@ mono_dl_symbol (MonoDl *module, const char *name, void **symbol)
        } else {
 #if MONO_DL_NEED_USCORE
                {
-                       char *usname = malloc (strlen (name) + 2);
+                       char *usname = g_malloc (strlen (name) + 2);
                        *usname = '_';
                        strcpy (usname + 1, name);
                        sym = mono_dl_lookup_symbol (module, usname);
-                       free (usname);
+                       g_free (usname);
                }
 #else
                sym = mono_dl_lookup_symbol (module, name);
@@ -264,7 +264,7 @@ mono_dl_close (MonoDl *module)
        } else
                mono_dl_close_handle (module);
        
-       free (module);
+       g_free (module);
 }
 
 /**
index 88f1a3d4b592613a32f8afe28704c81b83fef16f..491318465faf804a0767d46b45b838d8020814b5 100644 (file)
@@ -547,7 +547,7 @@ mono_pagesize (void)
 void*
 mono_valloc (void *addr, size_t length, int flags, MonoMemAccountType type)
 {
-       return malloc (length);
+       return g_malloc (length);
 }
 
 void*
@@ -561,7 +561,7 @@ mono_valloc_aligned (size_t size, size_t alignment, int flags, MonoMemAccountTyp
 int
 mono_vfree (void *addr, size_t length, MonoMemAccountType type)
 {
-       free (addr);
+       g_free (addr);
        return 0;
 }
 
index 7a589314f1f43b5032ec78182bd4a377e00ba22e..79da32b45118f4e6f992207c723ce14f880477c0 100644 (file)
@@ -80,7 +80,7 @@ mono_process_list (int *size)
 #ifdef KERN_PROC2
        int mib [6];
        size_t data_len = sizeof (struct kinfo_proc2) * 400;
-       struct kinfo_proc2 *processes = malloc (data_len);
+       struct kinfo_proc2 *processes = g_malloc (data_len);
 #else
        int mib [4];
        size_t data_len = sizeof (struct kinfo_proc) * 16;
@@ -105,7 +105,7 @@ mono_process_list (int *size)
 
        res = sysctl (mib, 6, processes, &data_len, NULL, 0);
        if (res < 0) {
-               free (processes);
+               g_free (processes);
                return NULL;
        }
 #else
@@ -119,10 +119,10 @@ mono_process_list (int *size)
                res = sysctl (mib, 4, NULL, &data_len, NULL, 0);
                if (res)
                        return NULL;
-               processes = (struct kinfo_proc *) malloc (data_len);
+               processes = (struct kinfo_proc *) g_malloc (data_len);
                res = sysctl (mib, 4, processes, &data_len, NULL, 0);
                if (res < 0) {
-                       free (processes);
+                       g_free (processes);
                        if (errno != ENOMEM)
                                return NULL;
                        limit --;
@@ -140,7 +140,7 @@ mono_process_list (int *size)
        buf = (void **) g_realloc (buf, res * sizeof (void*));
        for (i = 0; i < res; ++i)
                buf [i] = GINT_TO_POINTER (processes [i].kinfo_pid_member);
-       free (processes);
+       g_free (processes);
        if (size)
                *size = res;
        return buf;
index 7a2c4ac8100ebd9afec9607a8b7b0640c498f3a5..8ebc25a69b303019f66ecd117a2e9f7a5843a0c1 100644 (file)
@@ -36,7 +36,7 @@ mono_escape_uri_string (const gchar *string)
 #if TEST
 int main ()
 {
-       char *s = malloc (256);
+       char *s = g_malloc (256);
        int i = 0;
        
        s [255] = 0;