diff -r abb9499bef51 -r 2cc3feba9277 dbd/mysql/statement.c --- a/dbd/mysql/statement.c Sat Dec 20 11:17:37 2008 +0000 +++ b/dbd/mysql/statement.c Sat Dec 20 23:53:07 2008 +0000 @@ -70,8 +70,7 @@ int num_bind_params = n - 1; int expected_params; - unsigned char b[1024]; - unsigned char *buffer = &b[0]; + unsigned char *buffer = NULL; int offset = 0; MYSQL_BIND *bind = NULL; @@ -100,14 +99,16 @@ return 2; } - bind = malloc(sizeof(MYSQL_BIND) * num_bind_params); - - if (bind == NULL) { - luaL_error(L, "Could not alloc bind params\n"); + if (num_bind_params) { + bind = malloc(sizeof(MYSQL_BIND) * num_bind_params); + if (bind == NULL) { + luaL_error(L, "Could not alloc bind params\n"); + } + + buffer = malloc(num_bind_params * sizeof(size_t)); + memset(bind, 0, sizeof(MYSQL_BIND) * num_bind_params); } - memset(bind, 0, sizeof(MYSQL_BIND) * num_bind_params); - for (p = 2; p <= n; p++) { int type = lua_type(L, p); int i = p - 2; @@ -190,6 +191,10 @@ free(bind); } + if (buffer) { + free(buffer); + } + if (error_message) { lua_pushboolean(L, 0); lua_pushfstring(L, error_message, errstr ? errstr : mysql_stmt_error(statement->stmt));