dbd/mysql/statement.c

changeset 23
a4825c3e65e9
parent 21
7956401a0c5e
child 25
2cc3feba9277
--- a/dbd/mysql/statement.c	Sat Dec 20 02:37:22 2008 +0000
+++ b/dbd/mysql/statement.c	Sat Dec 20 11:15:15 2008 +0000
@@ -70,7 +70,8 @@
     int num_bind_params = n - 1;
     int expected_params;
 
-    unsigned char *buffer = NULL;
+    unsigned char b[1024];
+    unsigned char *buffer = &b[0];
     int offset = 0;
     
     MYSQL_BIND *bind = NULL;
@@ -100,6 +101,11 @@
     }
 
     bind = malloc(sizeof(MYSQL_BIND) * num_bind_params);
+    
+    if (bind == NULL) {
+        luaL_error(L, "Could not alloc bind params\n");
+    }
+
     memset(bind, 0, sizeof(MYSQL_BIND) * num_bind_params);
 
     for (p = 2; p <= n; p++) {
@@ -119,7 +125,6 @@
 		break;
 
 	    case LUA_TBOOLEAN:
-		buffer = realloc(buffer, offset + sizeof(int));
 		boolean = (int *)buffer + offset;
 		offset += sizeof(int);
 		*boolean = lua_toboolean(L, p);
@@ -135,7 +140,6 @@
 		 * num needs to be it's own 
 		 * memory here
                  */
-		buffer = realloc(buffer, offset + sizeof(double));
 		num = (double *)buffer + offset;
 		offset += sizeof(double);
 		*num = lua_tonumber(L, p);
@@ -147,7 +151,6 @@
 		break;
 
 	    case LUA_TSTRING:
-		buffer = realloc(buffer, offset + sizeof(size_t));
 		str_len = (size_t *)buffer + offset;
 		offset += sizeof(size_t);
 		str = lua_tolstring(L, p, str_len);
@@ -183,13 +186,9 @@
     }
 
 cleanup:
-    /*
-     * free the buffer with a resize to 0
-     */
-    realloc(buffer, 0);
-
-    if (bind) 
+    if (bind) { 
 	free(bind);
+    }
 
     if (error_message) {
 	lua_pushboolean(L, 0);
@@ -223,6 +222,7 @@
 	return 1;
     }
 
+
     column_count = mysql_num_fields(statement->metadata);
 
     if (column_count > 0) {

mercurial