Consistently use driver_(alloc,realloc,free).

This commit is contained in:
Gregory Burd 2011-11-28 16:02:00 -05:00
parent 1d28a6f5f5
commit 7ff11a42a8
2 changed files with 265 additions and 264 deletions

View file

@ -129,7 +129,7 @@ static int del_portref(int dbref, ErlDrvPort port);
static int alloc_dbref(); static int alloc_dbref();
static void abort_txn(PortData* d); static void abort_txn(PortData* d);
static void* zalloc(unsigned int size); static void* driver_calloc(unsigned int size);
static void* deadlock_check(void* arg); static void* deadlock_check(void* arg);
static void* checkpointer(void* arg); static void* checkpointer(void* arg);
@ -299,6 +299,9 @@ DRIVER_INIT(bdberl_drv)
} }
else else
{ {
G_DB_ENV_ERROR = G_DB_ENV->set_alloc(G_DB_ENV, driver_alloc, driver_realloc, driver_free);
DBG(" = %d\r\n", G_DB_ENV_ERROR);
DBG("G_DB_ENV->open(%p, 0, %08X, 0)", &G_DB_ENV, flags); DBG("G_DB_ENV->open(%p, 0, %08X, 0)", &G_DB_ENV, flags);
G_DB_ENV_ERROR = G_DB_ENV->open(G_DB_ENV, 0, flags, 0); G_DB_ENV_ERROR = G_DB_ENV->open(G_DB_ENV, 0, flags, 0);
DBG(" = %d\r\n", G_DB_ENV_ERROR); DBG(" = %d\r\n", G_DB_ENV_ERROR);
@ -1168,7 +1171,7 @@ static int open_database(const char* name, DBTYPE type, unsigned int flags, Port
assert(db != NULL); assert(db != NULL);
G_DATABASES[dbref].db = db; G_DATABASES[dbref].db = db;
G_DATABASES[dbref].name = strdup(name); G_DATABASES[dbref].name = strdup(name);
G_DATABASES[dbref].ports = zalloc(sizeof(PortList)); G_DATABASES[dbref].ports = driver_calloc(sizeof(PortList));
G_DATABASES[dbref].ports->port = data->port; G_DATABASES[dbref].ports->port = data->port;
// Make entry in hash table of names // Make entry in hash table of names
@ -1670,7 +1673,7 @@ static void do_async_get(void* arg)
async_cleanup_and_send_kv(d, rc, &key, &value); async_cleanup_and_send_kv(d, rc, &key, &value);
// Finally, clean up value buffer (driver_send_term made a copy) // Finally, clean up value buffer (driver_send_term made a copy)
free(value.data); driver_free(value.data);
} }
static void do_async_del(void* arg) static void do_async_del(void* arg)
@ -1800,7 +1803,7 @@ static void do_async_cursor_get(void* arg)
async_cleanup_and_send_kv(d, rc, &key, &value); async_cleanup_and_send_kv(d, rc, &key, &value);
// Finally, clean up value buffer (driver_send_term made a copy) // Finally, clean up value buffer (driver_send_term made a copy)
free(value.data); driver_free(value.data);
} }
@ -2043,15 +2046,13 @@ static void do_sync_driver_info(PortData *d)
} }
static void* zalloc(unsigned int size) static void* driver_calloc(unsigned int size)
{ {
void* res = driver_alloc(size); void* res = driver_alloc(size);
memset(res, '\0', size); memset(res, '\0', size);
return res; return res;
} }
#define zfree(p) driver_free(p)
static int add_portref(int dbref, ErlDrvPort port) static int add_portref(int dbref, ErlDrvPort port)
{ {
DBG("Adding port %p to dbref %d\r\n", port, dbref); DBG("Adding port %p to dbref %d\r\n", port, dbref);
@ -2072,7 +2073,7 @@ static int add_portref(int dbref, ErlDrvPort port)
} while (current != 0); } while (current != 0);
// At the end of the list -- allocate a new entry for this port // At the end of the list -- allocate a new entry for this port
current = (PortList*)zalloc(sizeof(PortList)); current = (PortList*)driver_calloc(sizeof(PortList));
current->port = port; current->port = port;
last->next = current; last->next = current;
return 1; return 1;
@ -2080,7 +2081,7 @@ static int add_portref(int dbref, ErlDrvPort port)
else else
{ {
// Current was initially NULL, so alloc the first one and add it. // Current was initially NULL, so alloc the first one and add it.
current = zalloc(sizeof(PortList)); current = driver_calloc(sizeof(PortList));
current->port = port; current->port = port;
G_DATABASES[dbref].ports = current; G_DATABASES[dbref].ports = current;
return 1; return 1;
@ -2108,7 +2109,7 @@ static int del_portref(int dbref, ErlDrvPort port)
} }
// Delete this entry // Delete this entry
zfree(current); driver_free(current);
return 1; return 1;
} }
@ -2142,7 +2143,7 @@ static int add_dbref(PortData* data, int dbref)
} while (current != 0); } while (current != 0);
// At the end of the list -- allocate a new entry // At the end of the list -- allocate a new entry
current = zalloc(sizeof(DbRefList)); current = driver_calloc(sizeof(DbRefList));
current->dbref = dbref; current->dbref = dbref;
last->next = current; last->next = current;
return 1; return 1;
@ -2150,7 +2151,7 @@ static int add_dbref(PortData* data, int dbref)
else else
{ {
// Current was initially NULL, so alloc the first one // Current was initially NULL, so alloc the first one
current = zalloc(sizeof(DbRefList)); current = driver_calloc(sizeof(DbRefList));
current->dbref = dbref; current->dbref = dbref;
data->dbrefs = current; data->dbrefs = current;
return 1; return 1;
@ -2183,7 +2184,7 @@ static int del_dbref(PortData* data, int dbref)
} }
// Delete this entry // Delete this entry
zfree(current); driver_free(current);
return 1; return 1;
} }

View file

@ -607,7 +607,7 @@ static void do_async_stat(void* arg)
// Finally, clean up value buffer (driver_send_term made a copy) // Finally, clean up value buffer (driver_send_term made a copy)
if (NULL != sp) if (NULL != sp)
{ {
free(sp); driver_free(sp);
} }
} }
@ -630,7 +630,7 @@ static void do_async_lock_stat(void* arg)
// Finally, clean up lock stats // Finally, clean up lock stats
if (NULL != lsp) if (NULL != lsp)
{ {
free(lsp); driver_free(lsp);
} }
} }
@ -653,7 +653,7 @@ static void do_async_log_stat(void* arg)
// Finally, clean up stats // Finally, clean up stats
if (NULL != lsp) if (NULL != lsp)
{ {
free(lsp); driver_free(lsp);
} }
} }
@ -677,11 +677,11 @@ static void do_async_memp_stat(void* arg)
// Finally, clean up stats // Finally, clean up stats
if (NULL != gsp) if (NULL != gsp)
{ {
free(gsp); driver_free(gsp);
} }
if (NULL != fsp) if (NULL != fsp)
{ {
free(fsp); driver_free(fsp);
} }
} }
@ -704,7 +704,7 @@ static void do_async_mutex_stat(void* arg)
// Finally, clean up stats // Finally, clean up stats
if (NULL != msp) if (NULL != msp)
{ {
free(msp); driver_free(msp);
} }
} }
@ -728,7 +728,7 @@ static void do_async_txn_stat(void* arg)
// Finally, clean up stats // Finally, clean up stats
if (NULL != tsp) if (NULL != tsp)
{ {
free(tsp); driver_free(tsp);
} }
} }