summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authork0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-25 12:33:38 +0000
committerk0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-07-25 12:33:38 +0000
commitf10582d8e7a16bca5b954e173ed6a66acf092f36 (patch)
tree1648f9dae83560314187ca1dc632b207eb9b5eac
parent3a1e3d35e233c84e9af13b78e6de936ccdf44e70 (diff)
mjit.c: prevent memory leak on realloc failure
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64050 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--mjit.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/mjit.c b/mjit.c
index eca9957..3d5b74b 100644
--- a/mjit.c
+++ b/mjit.c
@@ -327,15 +327,18 @@ form_args(int num, ...)
va_list argp;
size_t len, n;
int i;
- char **args, **res;
+ char **args, **res, **tmp;
va_start(argp, num);
res = NULL;
for (i = len = 0; i < num; i++) {
args = va_arg(argp, char **);
n = args_len(args);
- if ((res = (char **)realloc(res, sizeof(char *) * (len + n + 1))) == NULL)
+ if ((tmp = (char **)realloc(res, sizeof(char *) * (len + n + 1))) == NULL) {
+ free(res);
return NULL;
+ }
+ res = tmp;
MEMCPY(res + len, args, char *, n + 1);
len += n;
}