* array.c (rb_ary_sort_bang): stop memory leak. [ruby-dev:34726]
* re.c (rb_reg_search): need to free allocated buffer in re_register. * regexec.c (onig_region_new): more pedantic malloc check. * regexec.c (onig_region_resize): ditto. * regexec.c (STATE_CHECK_BUFF_INIT): ditto. * regexec.c (onig_region_copy): use onig_region_resize. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16437 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
03ed3bde9a
commit
c39e8c6e85
14
ChangeLog
14
ChangeLog
@ -1,3 +1,17 @@
|
|||||||
|
Sat May 17 03:21:29 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* array.c (rb_ary_sort_bang): stop memory leak. [ruby-dev:34726]
|
||||||
|
|
||||||
|
* re.c (rb_reg_search): need to free allocated buffer in re_register.
|
||||||
|
|
||||||
|
* regexec.c (onig_region_new): more pedantic malloc check.
|
||||||
|
|
||||||
|
* regexec.c (onig_region_resize): ditto.
|
||||||
|
|
||||||
|
* regexec.c (STATE_CHECK_BUFF_INIT): ditto.
|
||||||
|
|
||||||
|
* regexec.c (onig_region_copy): use onig_region_resize.
|
||||||
|
|
||||||
Fri May 16 12:48:33 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Fri May 16 12:48:33 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* math.c (to_flo): rb_Float() accepts even strings for input.
|
* math.c (to_flo): rb_Float() accepts even strings for input.
|
||||||
|
5
array.c
5
array.c
@ -1513,16 +1513,17 @@ rb_ary_sort_bang(VALUE ary)
|
|||||||
RBASIC(tmp)->klass = 0;
|
RBASIC(tmp)->klass = 0;
|
||||||
ruby_qsort(RARRAY_PTR(tmp), RARRAY_LEN(tmp), sizeof(VALUE),
|
ruby_qsort(RARRAY_PTR(tmp), RARRAY_LEN(tmp), sizeof(VALUE),
|
||||||
rb_block_given_p()?sort_1:sort_2, &RBASIC(tmp)->klass);
|
rb_block_given_p()?sort_1:sort_2, &RBASIC(tmp)->klass);
|
||||||
sort_reentered(&RBASIC(tmp)->klass);
|
if (RARRAY(ary)->ptr != RARRAY(tmp)->ptr) {
|
||||||
|
xfree(RARRAY(ary)->ptr);
|
||||||
RARRAY(ary)->ptr = RARRAY(tmp)->ptr;
|
RARRAY(ary)->ptr = RARRAY(tmp)->ptr;
|
||||||
RARRAY(ary)->len = RARRAY(tmp)->len;
|
RARRAY(ary)->len = RARRAY(tmp)->len;
|
||||||
RARRAY(ary)->aux.capa = RARRAY(tmp)->aux.capa;
|
RARRAY(ary)->aux.capa = RARRAY(tmp)->aux.capa;
|
||||||
|
};
|
||||||
FL_UNSET(ary, ELTS_SHARED);
|
FL_UNSET(ary, ELTS_SHARED);
|
||||||
RARRAY(tmp)->ptr = 0;
|
RARRAY(tmp)->ptr = 0;
|
||||||
RARRAY(tmp)->len = 0;
|
RARRAY(tmp)->len = 0;
|
||||||
RARRAY(tmp)->aux.capa = 0;
|
RARRAY(tmp)->aux.capa = 0;
|
||||||
RBASIC(tmp)->klass = RBASIC(ary)->klass;
|
RBASIC(tmp)->klass = RBASIC(ary)->klass;
|
||||||
OBJ_FREEZE(tmp);
|
|
||||||
}
|
}
|
||||||
return ary;
|
return ary;
|
||||||
}
|
}
|
||||||
|
2
re.c
2
re.c
@ -1300,6 +1300,7 @@ rb_reg_search(VALUE re, VALUE str, int pos, int reverse)
|
|||||||
}
|
}
|
||||||
if (!busy) FL_UNSET(re, REG_BUSY);
|
if (!busy) FL_UNSET(re, REG_BUSY);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
|
onig_region_free(®s, 0);
|
||||||
if (result == ONIG_MISMATCH) {
|
if (result == ONIG_MISMATCH) {
|
||||||
rb_backref_set(Qnil);
|
rb_backref_set(Qnil);
|
||||||
return result;
|
return result;
|
||||||
@ -1323,6 +1324,7 @@ rb_reg_search(VALUE re, VALUE str, int pos, int reverse)
|
|||||||
}
|
}
|
||||||
|
|
||||||
onig_region_copy(RMATCH_REGS(match), ®s);
|
onig_region_copy(RMATCH_REGS(match), ®s);
|
||||||
|
onig_region_free(®s, 0);
|
||||||
RMATCH(match)->str = rb_str_new4(str);
|
RMATCH(match)->str = rb_str_new4(str);
|
||||||
RMATCH(match)->regexp = re;
|
RMATCH(match)->regexp = re;
|
||||||
RMATCH(match)->rmatch->char_offset_updated = 0;
|
RMATCH(match)->rmatch->char_offset_updated = 0;
|
||||||
|
48
regexec.c
48
regexec.c
@ -178,16 +178,34 @@ onig_region_resize(OnigRegion* region, int n)
|
|||||||
|
|
||||||
if (region->allocated == 0) {
|
if (region->allocated == 0) {
|
||||||
region->beg = (int* )xmalloc(n * sizeof(int));
|
region->beg = (int* )xmalloc(n * sizeof(int));
|
||||||
region->end = (int* )xmalloc(n * sizeof(int));
|
if (region->beg == 0)
|
||||||
|
|
||||||
if (region->beg == 0 || region->end == 0)
|
|
||||||
return ONIGERR_MEMORY;
|
return ONIGERR_MEMORY;
|
||||||
|
|
||||||
|
region->end = (int* )xmalloc(n * sizeof(int));
|
||||||
|
if (region->end == 0) {
|
||||||
|
xfree(region->beg);
|
||||||
|
return ONIGERR_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
region->allocated = n;
|
region->allocated = n;
|
||||||
}
|
}
|
||||||
else if (region->allocated < n) {
|
else if (region->allocated < n) {
|
||||||
region->beg = (int* )xrealloc(region->beg, n * sizeof(int));
|
int *tmp;
|
||||||
region->end = (int* )xrealloc(region->end, n * sizeof(int));
|
|
||||||
|
region->allocated = 0;
|
||||||
|
tmp = (int* )xrealloc(region->beg, n * sizeof(int));
|
||||||
|
if (tmp == 0) {
|
||||||
|
xfree(region->beg);
|
||||||
|
xfree(region->end);
|
||||||
|
return ONIGERR_MEMORY;
|
||||||
|
}
|
||||||
|
region->beg = tmp;
|
||||||
|
tmp = (int* )xrealloc(region->end, n * sizeof(int));
|
||||||
|
if (tmp == 0) {
|
||||||
|
xfree(region->beg);
|
||||||
|
return ONIGERR_MEMORY;
|
||||||
|
}
|
||||||
|
region->end = tmp;
|
||||||
|
|
||||||
if (region->beg == 0 || region->end == 0)
|
if (region->beg == 0 || region->end == 0)
|
||||||
return ONIGERR_MEMORY;
|
return ONIGERR_MEMORY;
|
||||||
@ -240,6 +258,7 @@ onig_region_new(void)
|
|||||||
OnigRegion* r;
|
OnigRegion* r;
|
||||||
|
|
||||||
r = (OnigRegion* )xmalloc(sizeof(OnigRegion));
|
r = (OnigRegion* )xmalloc(sizeof(OnigRegion));
|
||||||
|
if (r)
|
||||||
onig_region_init(r);
|
onig_region_init(r);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -268,19 +287,7 @@ onig_region_copy(OnigRegion* to, OnigRegion* from)
|
|||||||
|
|
||||||
if (to == from) return;
|
if (to == from) return;
|
||||||
|
|
||||||
if (to->allocated == 0) {
|
onig_region_resize(to, from->num_regs);
|
||||||
if (from->num_regs > 0) {
|
|
||||||
to->beg = (int* )xmalloc(RREGC_SIZE);
|
|
||||||
to->end = (int* )xmalloc(RREGC_SIZE);
|
|
||||||
to->allocated = from->num_regs;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (to->allocated < from->num_regs) {
|
|
||||||
to->beg = (int* )xrealloc(to->beg, RREGC_SIZE);
|
|
||||||
to->end = (int* )xrealloc(to->end, RREGC_SIZE);
|
|
||||||
to->allocated = from->num_regs;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < from->num_regs; i++) {
|
for (i = 0; i < from->num_regs; i++) {
|
||||||
to->beg[i] = from->beg[i];
|
to->beg[i] = from->beg[i];
|
||||||
to->end[i] = from->end[i];
|
to->end[i] = from->end[i];
|
||||||
@ -352,8 +359,10 @@ onig_region_copy(OnigRegion* to, OnigRegion* from)
|
|||||||
unsigned int size = (unsigned int )(((str_len) + 1) * (state_num) + 7) >> 3;\
|
unsigned int size = (unsigned int )(((str_len) + 1) * (state_num) + 7) >> 3;\
|
||||||
offset = ((offset) * (state_num)) >> 3;\
|
offset = ((offset) * (state_num)) >> 3;\
|
||||||
if (size > 0 && offset < size && size < STATE_CHECK_BUFF_MAX_SIZE) {\
|
if (size > 0 && offset < size && size < STATE_CHECK_BUFF_MAX_SIZE) {\
|
||||||
if (size >= STATE_CHECK_BUFF_MALLOC_THRESHOLD_SIZE) \
|
if (size >= STATE_CHECK_BUFF_MALLOC_THRESHOLD_SIZE) {\
|
||||||
(msa).state_check_buff = (void* )xmalloc(size);\
|
(msa).state_check_buff = (void* )xmalloc(size);\
|
||||||
|
CHECK_NULL_RETURN_MEMERR((msa).state_check_buff);\
|
||||||
|
}\
|
||||||
else \
|
else \
|
||||||
(msa).state_check_buff = (void* )xalloca(size);\
|
(msa).state_check_buff = (void* )xalloca(size);\
|
||||||
xmemset(((char* )((msa).state_check_buff)+(offset)), 0, \
|
xmemset(((char* )((msa).state_check_buff)+(offset)), 0, \
|
||||||
@ -378,7 +387,6 @@ onig_region_copy(OnigRegion* to, OnigRegion* from)
|
|||||||
}\
|
}\
|
||||||
} while(0)
|
} while(0)
|
||||||
#else
|
#else
|
||||||
#define STATE_CHECK_BUFF_INIT(msa, str_len, offset, state_num)
|
|
||||||
#define MATCH_ARG_FREE(msa) if ((msa).stack_p) xfree((msa).stack_p)
|
#define MATCH_ARG_FREE(msa) if ((msa).stack_p) xfree((msa).stack_p)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#define RUBY_VERSION "1.9.0"
|
#define RUBY_VERSION "1.9.0"
|
||||||
#define RUBY_RELEASE_DATE "2008-05-16"
|
#define RUBY_RELEASE_DATE "2008-05-17"
|
||||||
#define RUBY_VERSION_CODE 190
|
#define RUBY_VERSION_CODE 190
|
||||||
#define RUBY_RELEASE_CODE 20080516
|
#define RUBY_RELEASE_CODE 20080517
|
||||||
#define RUBY_PATCHLEVEL 0
|
#define RUBY_PATCHLEVEL 0
|
||||||
|
|
||||||
#define RUBY_VERSION_MAJOR 1
|
#define RUBY_VERSION_MAJOR 1
|
||||||
@ -9,7 +9,7 @@
|
|||||||
#define RUBY_VERSION_TEENY 0
|
#define RUBY_VERSION_TEENY 0
|
||||||
#define RUBY_RELEASE_YEAR 2008
|
#define RUBY_RELEASE_YEAR 2008
|
||||||
#define RUBY_RELEASE_MONTH 5
|
#define RUBY_RELEASE_MONTH 5
|
||||||
#define RUBY_RELEASE_DAY 16
|
#define RUBY_RELEASE_DAY 17
|
||||||
|
|
||||||
#ifdef RUBY_EXTERN
|
#ifdef RUBY_EXTERN
|
||||||
RUBY_EXTERN const char ruby_version[];
|
RUBY_EXTERN const char ruby_version[];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user