summaryrefslogtreecommitdiff
path: root/ext/readline
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-01-08 21:02:08 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-01-08 21:02:08 +0000
commit88b16cebc818a75f36005f25998ea1a2e35fdfee (patch)
treea2a40b500057082ecc3aa64ef20b7a12a5a9aacc /ext/readline
parenta7c9064c8bb9a90ea0bba0863a38d3ef72c94252 (diff)
* gc.c (rb_objspace_free): global_List is allocated with xmalloc.
patched by Sokolov Yura. https://github.com/ruby/ruby/pull/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
Diffstat (limited to 'ext/readline')
-rw-r--r--ext/readline/readline.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/ext/readline/readline.c b/ext/readline/readline.c
index 888f5d8..c87afcb 100644
--- a/ext/readline/readline.c
+++ b/ext/readline/readline.c
@@ -670,12 +670,13 @@ readline_attempted_completion_function(const char *text, int start, int end)
if (TYPE(ary) != T_ARRAY)
ary = rb_Array(ary);
matches = RARRAY_LEN(ary);
- if (matches == 0)
- return NULL;
- result = ALLOC_N(char *, matches + 2);
+ if (matches == NULL) rb_mem_error();
+ result = (char**)malloc((matches + 2)*sizeof(char*));
+ if (result == NULL) rb_raise(rb_eNoMemError, "%s");
for (i = 0; i < matches; i++) {
temp = rb_obj_as_string(RARRAY_PTR(ary)[i]);
- result[i + 1] = ALLOC_N(char, RSTRING_LEN(temp) + 1);
+ result[i + 1] = (char*)malloc(RSTRING_LEN(temp) + 1);
+ if (result[i + 1] == NULL) rb_mem_error();
strcpy(result[i + 1], RSTRING_PTR(temp));
}
result[matches + 1] = NULL;
@@ -707,7 +708,8 @@ readline_attempted_completion_function(const char *text, int start, int end)
if (low > si) low = si;
i++;
}
- result[0] = ALLOC_N(char, low + 1);
+ result[0] = (char*)malloc(low + 1);
+ if (result[0] == NULL) rb_mem_error();
strncpy(result[0], result[1], low);
result[0][low] = '\0';
}