Bugs item #2606, was opened at 2005-10-09 22:13
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1698&aid=2606&group_id=426

Category: Core
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Paul Brannan (cout)
Assigned to: Nobody (None)
Summary: st.c calls ruby_xcalloc but frees with free()

Initial Comment:
Using version 1.8.3.

In st.c I see:

cout@bean:~/download/ruby-1.8.3$ grep alloc st.c
#include <malloc.h>
     * allocated initially
#define xmalloc ruby_xmalloc
#define xcalloc ruby_xcalloc
#define xrealloc ruby_xrealloc
void *xmalloc(long);
void *xcalloc(long, long);
void *xrealloc(void *, long);
#define alloc(type) (type*)xmalloc((unsigned)sizeof(type))
#define Calloc(n,s) (char*)xcalloc((n),(s))
    tbl = alloc(st_table);
    tbl->bins = (st_table_entry **)Calloc(size, sizeof(st_table_entry*));
    entry = alloc(st_table_entry);\
    new_bins = (st_table_entry**)Calloc(new_num_bins, sizeof(st_table_entry*));
    new_table = alloc(st_table);
        Calloc((unsigned)num_bins, sizeof(st_table_entry*));
            entry = alloc(st_table_entry);

Note that all the allocations are through alloc() and Calloc(), which resul in calls to ruby_xmalloc and ruby_xcalloc, respectively.

I also see:
cout@bean:~/download/ruby-1.8.3$ grep free st.c
#define xfree ruby_xfree
void xfree(void *);
st_free_table(table)
            free(ptr);
    free(table->bins);
    free(table);
    free(table->bins);
        free(new_table);
                free(new_table->bins);
                free(new_table);
        free(ptr);
            free(tmp);
                free(tmp);

To be symmetric st.c should use xfree() instead of free().

(This is not just an academic problem; I ran into this while trying to dynamically replace ruby_xmalloc() as part of a simple memory profiler).


----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1698&aid=2606&group_id=426