ruby-changes:51836
From: k0kubun <ko1@a...>
Date: Wed, 25 Jul 2018 21:33:48 +0900 (JST)
Subject: [ruby-changes:51836] k0kubun:r64050 (trunk): mjit.c: prevent memory leak on realloc failure
k0kubun 2018-07-25 21:33:38 +0900 (Wed, 25 Jul 2018) New Revision: 64050 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64050 Log: mjit.c: prevent memory leak on realloc failure Modified files: trunk/mjit.c Index: mjit.c =================================================================== --- mjit.c (revision 64049) +++ mjit.c (revision 64050) @@ -327,15 +327,18 @@ form_args(int num, ...) https://github.com/ruby/ruby/blob/trunk/mjit.c#L327 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; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/