@@ -185,13 +185,19 @@ static void *nogvl_stmt_store_result(void *ptr) {
185
185
}
186
186
}
187
187
188
+ /* Free each bind_buffer[i].buffer except when params_enc is non-nil, this means
189
+ * the buffer is a Ruby string pointer and not our memory to manage.
190
+ */
188
191
#define FREE_BINDS \
189
192
for (i = 0; i < argc; i++) { \
190
193
if (bind_buffers[i].buffer && NIL_P(params_enc[i])) { \
191
194
xfree(bind_buffers[i].buffer); \
192
195
} \
193
196
} \
194
- if (argc > 0) xfree(bind_buffers);
197
+ if (argc > 0) { \
198
+ xfree(bind_buffers); \
199
+ xfree(length_buffers); \
200
+ }
195
201
196
202
/* call-seq: stmt.execute
197
203
*
@@ -247,22 +253,22 @@ static VALUE execute(int argc, VALUE *argv, VALUE self) {
247
253
case T_FIXNUM :
248
254
#if SIZEOF_INT < SIZEOF_LONG
249
255
bind_buffers [i ].buffer_type = MYSQL_TYPE_LONGLONG ;
250
- bind_buffers [i ].buffer = malloc (sizeof (long long int ));
256
+ bind_buffers [i ].buffer = xmalloc (sizeof (long long int ));
251
257
* (long * )(bind_buffers [i ].buffer ) = FIX2LONG (argv [i ]);
252
258
#else
253
259
bind_buffers [i ].buffer_type = MYSQL_TYPE_LONG ;
254
- bind_buffers [i ].buffer = malloc (sizeof (int ));
260
+ bind_buffers [i ].buffer = xmalloc (sizeof (int ));
255
261
* (long * )(bind_buffers [i ].buffer ) = FIX2INT (argv [i ]);
256
262
#endif
257
263
break ;
258
264
case T_BIGNUM :
259
265
bind_buffers [i ].buffer_type = MYSQL_TYPE_LONGLONG ;
260
- bind_buffers [i ].buffer = malloc (sizeof (long long int ));
266
+ bind_buffers [i ].buffer = xmalloc (sizeof (long long int ));
261
267
* (LONG_LONG * )(bind_buffers [i ].buffer ) = rb_big2ll (argv [i ]);
262
268
break ;
263
269
case T_FLOAT :
264
270
bind_buffers [i ].buffer_type = MYSQL_TYPE_DOUBLE ;
265
- bind_buffers [i ].buffer = malloc (sizeof (double ));
271
+ bind_buffers [i ].buffer = xmalloc (sizeof (double ));
266
272
* (double * )(bind_buffers [i ].buffer ) = NUM2DBL (argv [i ]);
267
273
break ;
268
274
case T_STRING :
@@ -282,7 +288,7 @@ static VALUE execute(int argc, VALUE *argv, VALUE self) {
282
288
// TODO: what Ruby type should support MYSQL_TYPE_TIME
283
289
if (CLASS_OF (argv [i ]) == rb_cTime || CLASS_OF (argv [i ]) == cDateTime ) {
284
290
bind_buffers [i ].buffer_type = MYSQL_TYPE_DATETIME ;
285
- bind_buffers [i ].buffer = malloc (sizeof (MYSQL_TIME ));
291
+ bind_buffers [i ].buffer = xmalloc (sizeof (MYSQL_TIME ));
286
292
287
293
MYSQL_TIME t ;
288
294
VALUE rb_time = argv [i ];
@@ -301,7 +307,7 @@ static VALUE execute(int argc, VALUE *argv, VALUE self) {
301
307
302
308
bind_buffers [i ].buffer_type = MYSQL_TYPE_DATE ;
303
309
304
- bind_buffers [i ].buffer = malloc (sizeof (MYSQL_TIME ));
310
+ bind_buffers [i ].buffer = xmalloc (sizeof (MYSQL_TIME ));
305
311
306
312
MYSQL_TIME t ;
307
313
VALUE rb_time = argv [i ];
0 commit comments