Prevent the VALUEs in args from getting garbage collected too early (#7916)

Prevent the VALUEs in args from getting garbage collected too early.
This commit is contained in:
Kevin Backhouse 2022-06-28 13:43:51 +01:00 committed by GitHub
parent f78fb0a7e1
commit 88d62b47bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 5 deletions

View File

@ -15,6 +15,10 @@ limitations under the License.
#define ARRAYSIZE(x) (sizeof(x) / sizeof(x[0]))
// The maximum number of arguments of any of the target functions.
// Increase as needed.
#define MAX_NARGS 2
enum RubyDataType { RDT_CString };
struct TargetFunction {
@ -143,12 +147,10 @@ int run_fuzz_function(struct ByteStream *bs, struct TargetFunction *fcn) {
return -1;
}
VALUE *args = calloc(fcn->nargs_, sizeof(VALUE));
if (!args) {
return -1;
}
VALUE args[MAX_NARGS] = {};
int result = -1;
int i;
assert(fcn->nargs_ <= MAX_NARGS);
for (i = 0; i < fcn->nargs_; i++) {
VALUE v = generate_value(bs, fcn->argTypes_[i]);
if (!v) {
@ -166,7 +168,6 @@ int run_fuzz_function(struct ByteStream *bs, struct TargetFunction *fcn) {
}
out:
free(args);
return result;
}