Commit f44c99cd authored by h2so5's avatar h2so5

Replace malloc with mrb_malloc in mrbc

parent ab6c9c18
...@@ -47,12 +47,12 @@ usage(const char *name) ...@@ -47,12 +47,12 @@ usage(const char *name)
} }
static char * static char *
get_outfilename(char *infile, char *ext) get_outfilename(mrb_state *mrb, char *infile, char *ext)
{ {
char *outfile; char *outfile;
char *p; char *p;
outfile = (char*)malloc(strlen(infile) + strlen(ext) + 1); outfile = (char*)mrb_malloc(mrb, strlen(infile) + strlen(ext) + 1);
strcpy(outfile, infile); strcpy(outfile, infile);
if (*ext) { if (*ext) {
if ((p = strrchr(outfile, '.')) == NULL) if ((p = strrchr(outfile, '.')) == NULL)
...@@ -91,7 +91,7 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args) ...@@ -91,7 +91,7 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
result = EXIT_FAILURE; result = EXIT_FAILURE;
goto exit; goto exit;
} }
outfile = get_outfilename((*argv) + 2, ""); outfile = get_outfilename(mrb, (*argv) + 2, "");
break; break;
case 'B': case 'B':
args->ext = C_EXT; args->ext = C_EXT;
...@@ -150,7 +150,7 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args) ...@@ -150,7 +150,7 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
outfile = infile; outfile = infile;
} }
else { else {
outfile = get_outfilename(infile, args->ext); outfile = get_outfilename(mrb, infile, args->ext);
} }
} }
if (strcmp("-", outfile) == 0) { if (strcmp("-", outfile) == 0) {
...@@ -163,7 +163,7 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args) ...@@ -163,7 +163,7 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
} }
} }
exit: exit:
if (outfile && infile != outfile) free(outfile); if (outfile && infile != outfile) mrb_free(mrb, outfile);
return result; return result;
} }
......
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