djberg96
3/3/2005 9:48:00 PM
Hi all,
Ruby 1.8.2
Solaris 9
gcc 3.4.2
The following function core dumps when I test it on Solaris (though
Windows XP with VC++ 7.0 does not complain). However, it seems to work
fine if I remove the call to free().
Should I not malloc() the char pointer in the first place? I
originally did this to silence -Wall. Is there still some connection
between 'rbName' and 'name' after the call to rb_str_new2()? Why would
calling free() causing a core dump?
static VALUE bar_test(VALUE klass){
VALUE rbName;
char* name;
name = malloc(128);
name = getenv("USER");
rbName = rb_str_new2(name);
free(name);
return rbName;
}
Note that I don't want to just remove free(), for fear of a memory
leak.
Regards,
Dan