Markus Mottl avatar Markus Mottl committed b884e0c

Replaced calls to malloc to caml_stat_alloc

Comments (0)

Files changed (1)

     caml_alloc_final(1 + sizeof(stmt_wrap), &finalize_stmt_gc, 1, 100);
   stmt_wrap *stmtw = &Sqlite3_stmtw_val(v_stmt);
   stmtw->stmt = NULL;
-
-  if (! (stmtw->sql = malloc(sql_len + 1)))
-    raise_sqlite3_Error(
-      "SQL query string allocation failed for %d characters", sql_len + 1);
-  else {
-    stmtw->sql = memcpy(stmtw->sql, sql, sql_len);
-    stmtw->sql[sql_len] = '\0';
-    stmtw->sql_len = sql_len;
-    stmtw->tail = NULL;
-    stmtw->db_wrap = dbw;
-    dbw->ref_count++;
-    rc = sqlite3_prepare(dbw->db, sql, sql_len,
-                         &(stmtw->stmt), (const char **) &(stmtw->tail));
-    if (rc != SQLITE_OK) raise_sqlite3_current(dbw->db, "prepare");
-    else if (!stmtw->stmt) raise_sqlite3_Error("No code compiled from %s", sql);
-    return v_stmt;
-  }
+  stmtw->sql = caml_stat_alloc(sql_len + 1);
+  stmtw->sql = memcpy(stmtw->sql, sql, sql_len);
+  stmtw->sql[sql_len] = '\0';
+  stmtw->sql_len = sql_len;
+  stmtw->tail = NULL;
+  stmtw->db_wrap = dbw;
+  dbw->ref_count++;
+  rc = sqlite3_prepare(dbw->db, sql, sql_len,
+                       &(stmtw->stmt), (const char **) &(stmtw->tail));
+  if (rc != SQLITE_OK) raise_sqlite3_current(dbw->db, "prepare");
+  else if (!stmtw->stmt) raise_sqlite3_Error("No code compiled from %s", sql);
+  return v_stmt;
 }
 
 CAMLprim value caml_sqlite3_prepare(value v_db, value v_sql)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.