diff options
author | David Sommerseth <dazo@users.sourceforge.net> | 2009-09-07 21:10:22 +0200 |
---|---|---|
committer | David Sommerseth <dazo@users.sourceforge.net> | 2009-09-07 21:10:22 +0200 |
commit | 66b29488a7ed5909564ed03b3e89cd0d008df09e (patch) | |
tree | 2ef1558a3c54b37b59a775f4734cb467cac183cb /database/sqlite/sqlite.c | |
parent | 428d4fd45100c5c9b799f2fb127775b8b2382ecc (diff) | |
download | eurephia-66b29488a7ed5909564ed03b3e89cd0d008df09e.tar.gz eurephia-66b29488a7ed5909564ed03b3e89cd0d008df09e.tar.xz eurephia-66b29488a7ed5909564ed03b3e89cd0d008df09e.zip |
Moved all malloc() operations over to a calloc wrapper, malloc_nullsafe()
This also improves debugging as well, if debug logging is enabled and log level is >= 40.
Diffstat (limited to 'database/sqlite/sqlite.c')
-rw-r--r-- | database/sqlite/sqlite.c | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/database/sqlite/sqlite.c b/database/sqlite/sqlite.c index 9148616..5faa0b7 100644 --- a/database/sqlite/sqlite.c +++ b/database/sqlite/sqlite.c @@ -108,8 +108,7 @@ static int _cb_parse_result(void *NotUsed, int argc, char **argv, char **colName // If no header records are found, populate this structure if( glob_results->headerrec == NULL ) { for( i = 0; i < argc; i++ ) { - hrec = (_sqlite_header *) malloc(sizeof(_sqlite_header)+2); - memset(hrec, 0, sizeof(_sqlite_header)+2); + hrec = (_sqlite_header *) malloc_nullsafe(NULL, sizeof(_sqlite_header)+2); hrec->fieldid = i; hrec->name = strdup_nullsafe(colName[i]); @@ -134,8 +133,7 @@ static int _cb_parse_result(void *NotUsed, int argc, char **argv, char **colName // Add all data fields for this record into a tuple structure hrec = glob_results->headerrec; for( i = 0; i < argc; i++ ) { - new_frec = (_sqlite_tuples *) malloc(sizeof(_sqlite_tuples)+2); - memset(new_frec, 0, sizeof(_sqlite_tuples)+2); + new_frec = (_sqlite_tuples *) malloc_nullsafe(NULL, sizeof(_sqlite_tuples)+2); // trec contains the head of a new record set with fields if( trec == NULL ) { @@ -221,8 +219,7 @@ dbresult *sqlite_query(eurephiaCTX *ctx, char *fmt, ... ) { // prepare a new (global) result set ... // do not delete the old ones, since we return this "global" // result as a new individual result - glob_results = malloc(sizeof(dbresult)+2); - memset(glob_results, 0, sizeof(dbresult)+2); + glob_results = malloc_nullsafe(ctx, sizeof(dbresult)+2); glob_results->num_tuples = 0; // prepare SQL query @@ -566,11 +563,8 @@ int main() { mwStatistics(3); #endif - ctx = malloc(sizeof(eurephiaCTX)+2); - memset(ctx, 0, sizeof(eurephiaCTX)+2); - - ctx->dbc = malloc(sizeof(eDBconn)+2); - memset(ctx->dbc, 0, sizeof(eDBconn)+2); + ctx = malloc_nullsafe(NULL, sizeof(eurephiaCTX)+2); + ctx->dbc = malloc_nullsafe(NULL, sizeof(eDBconn)+2); rc = sqlite3_open("./vpnaccess", (void *) &ctx->dbc->dbhandle); if( rc ) { |