Browse files

Fix buffer allocation in make_object_info2

  • Loading branch information...
1 parent f0eec68 commit 8b05e5f99def434daa72e713d477b23e5b333944 @dgud dgud committed with dgud Mar 14, 2011
Showing with 11 additions and 7 deletions.
  1. +11 −7 c_src/cl_nif.c
View
18 c_src/cl_nif.c
@@ -2324,15 +2324,17 @@ ERL_NIF_TERM make_object_info2(ErlNifEnv* env, ERL_NIF_TERM key, ecl_object_t*
i++;
if (i == num_info)
return enif_make_badarg(env); // or error ?
- if (!(buf = enif_alloc(sizeof(cl_long) * MAX_INFO_SIZE)))
- ecl_make_error(env, CL_OUT_OF_RESOURCES);
if (!(err = (*func)(obj1->opaque, obj2->opaque, info[i].info_id,
- sizeof(cl_long) * MAX_INFO_SIZE, buf, &returned_size))) {
- result = enif_make_tuple2(env, ATOM(ok), make_info_value(env, &info[i], buf, returned_size));
- enif_free(buf);
- return result;
+ 0, NULL, &returned_size))) {
+ if (!(buf = enif_alloc(returned_size)))
+ return ecl_make_error(env, CL_OUT_OF_RESOURCES);
+ if (!(err = (*func)(obj1->opaque, obj2->opaque, info[i].info_id,
+ returned_size, buf, &returned_size))) {
+ result = enif_make_tuple2(env, ATOM(ok), make_info_value(env, &info[i], buf, returned_size));
+ enif_free(buf);
+ return result;
+ }
}
- enif_free(buf);
return ecl_make_error(env, err);
}
@@ -2653,6 +2655,8 @@ static ERL_NIF_TERM ecl_create_buffer(ErlNifEnv* env, int argc,
ErlNifBinary bin;
void* host_ptr = 0;
cl_int err;
+ UNUSED(argc);
+
if (!get_ecl_object(env, argv[0], &context_r, false, &o_context))
return enif_make_badarg(env);

0 comments on commit 8b05e5f

Please sign in to comment.