Skip to content

Commit 88b16ce

Browse files
committed
* gc.c (rb_objspace_free): global_List is allocated with xmalloc.
patched by Sokolov Yura. ruby#78 * dln_find.c: remove useless replacement of free. * ext/readline/readline.c (readline_attempted_completion_function): strings for readline must allocated with malloc. * process.c (run_exec_dup2): use free; see also r20950. * re.c (onig_new_with_source): use malloc for oniguruma. * vm.c (ruby_vm_destruct): use free for VMs. * vm.c (thread_free): use free for threads. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent a7c9064 commit 88b16ce

File tree

7 files changed

+40
-19
lines changed

7 files changed

+40
-19
lines changed

ChangeLog

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
Mon Jan 9 04:24:59 2012 NARUSE, Yui <[email protected]>
2+
3+
* gc.c (rb_objspace_free): global_List is allocated with xmalloc.
4+
patched by Sokolov Yura. https://github.com/ruby/ruby/pull/78
5+
6+
* dln_find.c: remove useless replacement of free.
7+
8+
* ext/readline/readline.c (readline_attempted_completion_function):
9+
strings for readline must allocated with malloc.
10+
11+
* process.c (run_exec_dup2): use free; see also r20950.
12+
13+
* re.c (onig_new_with_source): use malloc for oniguruma.
14+
15+
* vm.c (ruby_vm_destruct): use free for VMs.
16+
17+
* vm.c (thread_free): use free for threads.
18+
19+
Mon Jan 9 04:24:59 2012 NARUSE, Yui <[email protected]>
20+
21+
* dln_find.c: remove useless replacement of free.
22+
23+
* ext/readline/readline.c (filename_completion_proc_call):
24+
matches should use xfree.
25+
26+
* ext/readline/readline.c (username_completion_proc_call): ditto.
27+
128
Mon Jan 9 01:12:35 2012 NARUSE, Yui <[email protected]>
229

330
* numeric.c (rb_enc_uint_char): raise RangeError when added codepoint

dln_find.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@ char *dln_argv0;
4545
# include <strings.h>
4646
#endif
4747

48-
#ifndef xmalloc
49-
void *xmalloc();
50-
void *xcalloc();
51-
void *xrealloc();
52-
#endif
53-
54-
#define free(x) xfree(x)
55-
5648
#include <stdio.h>
5749
#if defined(_WIN32)
5850
#include "missing/file.h"

ext/readline/readline.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -670,12 +670,13 @@ readline_attempted_completion_function(const char *text, int start, int end)
670670
if (TYPE(ary) != T_ARRAY)
671671
ary = rb_Array(ary);
672672
matches = RARRAY_LEN(ary);
673-
if (matches == 0)
674-
return NULL;
675-
result = ALLOC_N(char *, matches + 2);
673+
if (matches == NULL) rb_mem_error();
674+
result = (char**)malloc((matches + 2)*sizeof(char*));
675+
if (result == NULL) rb_raise(rb_eNoMemError, "%s");
676676
for (i = 0; i < matches; i++) {
677677
temp = rb_obj_as_string(RARRAY_PTR(ary)[i]);
678-
result[i + 1] = ALLOC_N(char, RSTRING_LEN(temp) + 1);
678+
result[i + 1] = (char*)malloc(RSTRING_LEN(temp) + 1);
679+
if (result[i + 1] == NULL) rb_mem_error();
679680
strcpy(result[i + 1], RSTRING_PTR(temp));
680681
}
681682
result[matches + 1] = NULL;
@@ -707,7 +708,8 @@ readline_attempted_completion_function(const char *text, int start, int end)
707708
if (low > si) low = si;
708709
i++;
709710
}
710-
result[0] = ALLOC_N(char, low + 1);
711+
result[0] = (char*)malloc(low + 1);
712+
if (result[0] == NULL) rb_mem_error();
711713
strncpy(result[0], result[1], low);
712714
result[0][low] = '\0';
713715
}

gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ rb_objspace_free(rb_objspace_t *objspace)
507507
struct gc_list *list, *next;
508508
for (list = global_List; list; list = next) {
509509
next = list->next;
510-
free(list);
510+
xfree(list);
511511
}
512512
}
513513
if (objspace->heap.free_bitmap) {

process.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,11 +2151,11 @@ run_exec_dup2(VALUE ary, VALUE save, char *errmsg, size_t errmsg_buflen)
21512151
}
21522152
}
21532153

2154-
xfree(pairs);
2154+
free(pairs);
21552155
return 0;
21562156

21572157
fail:
2158-
xfree(pairs);
2158+
free(pairs);
21592159
return -1;
21602160
}
21612161

re.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ onig_new_with_source(regex_t** reg, const UChar* pattern, const UChar* pattern_e
769769
{
770770
int r;
771771

772-
*reg = (regex_t* )xmalloc(sizeof(regex_t));
772+
*reg = (regex_t* )malloc(sizeof(regex_t));
773773
if (IS_NULL(*reg)) return ONIGERR_MEMORY;
774774

775775
r = onig_reg_init(*reg, option, ONIGENC_CASE_FOLD_DEFAULT, enc, syntax);

vm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,7 @@ ruby_vm_destruct(rb_vm_t *vm)
16201620
#endif
16211621
ruby_vm_run_at_exit_hooks(vm);
16221622
rb_vm_gvl_destroy(vm);
1623-
ruby_xfree(vm);
1623+
free(vm);
16241624
ruby_current_vm = 0;
16251625
}
16261626
RUBY_FREE_LEAVE("vm");
@@ -1795,7 +1795,7 @@ thread_free(void *ptr)
17951795
free(th->altstack);
17961796
}
17971797
#endif
1798-
ruby_xfree(ptr);
1798+
free(ptr);
17991799
}
18001800
if (ruby_current_thread == th)
18011801
ruby_current_thread = NULL;

0 commit comments

Comments
 (0)