Commit 33c8c8f8 authored by Kouhei Sutou's avatar Kouhei Sutou

Stop to use freed value

parent a9abf65f
...@@ -114,11 +114,13 @@ mrb_file_s_unlink(mrb_state *mrb, mrb_value obj) ...@@ -114,11 +114,13 @@ mrb_file_s_unlink(mrb_state *mrb, mrb_value obj)
mrb_get_args(mrb, "*", &argv, &argc); mrb_get_args(mrb, "*", &argv, &argc);
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
const char *utf8_path;
pathv = mrb_convert_type(mrb, argv[i], MRB_TT_STRING, "String", "to_str"); pathv = mrb_convert_type(mrb, argv[i], MRB_TT_STRING, "String", "to_str");
path = mrb_locale_from_utf8(mrb_string_value_cstr(mrb, &pathv), -1); utf8_path = mrb_string_value_cstr(mrb, &pathv);
path = mrb_locale_from_utf8(utf8_path, -1);
if (UNLINK(path) < 0) { if (UNLINK(path) < 0) {
mrb_locale_free(path); mrb_locale_free(path);
mrb_sys_fail(mrb, path); mrb_sys_fail(mrb, utf8_path);
} }
mrb_locale_free(path); mrb_locale_free(path);
} }
...@@ -415,10 +417,11 @@ mrb_file_s_chmod(mrb_state *mrb, mrb_value klass) { ...@@ -415,10 +417,11 @@ mrb_file_s_chmod(mrb_state *mrb, mrb_value klass) {
mrb_get_args(mrb, "i*", &mode, &filenames, &argc); mrb_get_args(mrb, "i*", &mode, &filenames, &argc);
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
char *path = mrb_locale_from_utf8(mrb_str_to_cstr(mrb, filenames[i]), -1); const char *utf8_path = mrb_str_to_cstr(mrb, filenames[i]);
char *path = mrb_locale_from_utf8(utf8_path, -1);
if (CHMOD(path, mode) == -1) { if (CHMOD(path, mode) == -1) {
mrb_locale_free(path); mrb_locale_free(path);
mrb_sys_fail(mrb, path); mrb_sys_fail(mrb, utf8_path);
} }
mrb_locale_free(path); mrb_locale_free(path);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment