Skip to content

Commit e9c1e1f

Browse files
committed
Avoid 0 byte allocation call when statement takes no parameters
1 parent 973390f commit e9c1e1f

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

ext/mysql2/statement.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,6 @@ static VALUE rb_mysql_stmt_execute(int argc, VALUE *argv, VALUE self) {
266266
// Get count of ordinary arguments, and extract hash opts/keyword arguments
267267
c = rb_scan_args(argc, argv, "*:", NULL, &opts);
268268

269-
// Scratch space for string encoding exports, allocate on the stack
270-
params_enc = alloca(sizeof(VALUE) * c);
271-
272269
stmt = stmt_wrapper->stmt;
273270

274271
bind_count = mysql_stmt_param_count(stmt);
@@ -278,6 +275,8 @@ static VALUE rb_mysql_stmt_execute(int argc, VALUE *argv, VALUE self) {
278275

279276
// setup any bind variables in the query
280277
if (bind_count > 0) {
278+
// Scratch space for string encoding exports, allocate on the stack
279+
params_enc = alloca(sizeof(VALUE) * c);
281280
bind_buffers = xcalloc(bind_count, sizeof(MYSQL_BIND));
282281
length_buffers = xcalloc(bind_count, sizeof(unsigned long));
283282

0 commit comments

Comments
 (0)