1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

wrapper object before alloc

* error.c (rb_name_err_mesg_new): new wrapper object before
  allocate data area and get rid of potential memory leak.
  GC guards are no longer needed.

* file.c (stat_new_0): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50510 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2015-05-16 12:56:29 +00:00
parent 5ffb21ebbd
commit cb54008be6
2 changed files with 5 additions and 6 deletions

View file

@ -1155,16 +1155,13 @@ static const rb_data_type_t name_err_mesg_data_type = {
VALUE
rb_name_err_mesg_new(VALUE obj, VALUE mesg, VALUE recv, VALUE method)
{
VALUE result = TypedData_Wrap_Struct(rb_cNameErrorMesg, &name_err_mesg_data_type, 0);
VALUE *ptr = ALLOC_N(VALUE, NAME_ERR_MESG_COUNT);
VALUE result;
ptr[0] = mesg;
ptr[1] = recv;
ptr[2] = method;
result = TypedData_Wrap_Struct(rb_cNameErrorMesg, &name_err_mesg_data_type, ptr);
RB_GC_GUARD(mesg);
RB_GC_GUARD(recv);
RB_GC_GUARD(method);
RTYPEDDATA_DATA(result) = ptr;
return result;
}

4
file.c
View file

@ -406,12 +406,14 @@ static VALUE
stat_new_0(VALUE klass, const struct stat *st)
{
struct stat *nst = 0;
VALUE obj = TypedData_Wrap_Struct(klass, &stat_data_type, 0);
if (st) {
nst = ALLOC(struct stat);
*nst = *st;
RTYPEDDATA_DATA(obj) = nst;
}
return TypedData_Wrap_Struct(klass, &stat_data_type, nst);
return obj;
}
VALUE