better utilize glib functions, fix memory leak

This commit is contained in:
whydoubt
2004-05-30 08:06:42 +00:00
parent a5afa5c9e4
commit b6dd1b63c5
3 changed files with 22 additions and 24 deletions

View File

@@ -13,6 +13,8 @@ Sun May 30 00:04:55 CDT 2004 Jeff Smith <whydoubt@yahoo.com>
* src/util/mdb-sql.c: * src/util/mdb-sql.c:
* src/util/mdb-tables.c: * src/util/mdb-tables.c:
* src/util/sargtest.c: better utilize glib functions, fix memory leaks * src/util/sargtest.c: better utilize glib functions, fix memory leaks
* src/odbc/connectparams.c:
* src/odbc/odbc.c: better utilize glib functions, fix memory leak
Sat May 29 14:14:21 CDT 2004 Jeff Smith <whydoubt@yahoo.com> Sat May 29 14:14:21 CDT 2004 Jeff Smith <whydoubt@yahoo.com>
* src/libmdb/backend.c: * src/libmdb/backend.c:

View File

@@ -60,7 +60,7 @@ static gboolean cleanup (gpointer key, gpointer value, gpointer user_data);
ConnectParams* NewConnectParams () ConnectParams* NewConnectParams ()
{ {
ConnectParams* params = malloc (sizeof (ConnectParams)); ConnectParams* params = (ConnectParams *) g_malloc(sizeof (ConnectParams));
if (!params) if (!params)
return params; return params;
@@ -88,6 +88,7 @@ void FreeConnectParams (ConnectParams* params)
g_hash_table_foreach_remove (params->table, cleanup, NULL); g_hash_table_foreach_remove (params->table, cleanup, NULL);
g_hash_table_destroy (params->table); g_hash_table_destroy (params->table);
} }
g_free(params);
} }
} }
@@ -197,7 +198,7 @@ void SetConnectString (ConnectParams* params, const gchar* connectString)
/* /*
* Make a copy of the connection string so we can modify it * Make a copy of the connection string so we can modify it
*/ */
cs = strdup (connectString); cs = (char *) g_strdup(connectString);
s = cs; s = cs;
/* /*
* Loop over ';' seperated name=value pairs * Loop over ';' seperated name=value pairs
@@ -239,21 +240,21 @@ void SetConnectString (ConnectParams* params, const gchar* connectString)
/* /*
* cleanup strings * cleanup strings
*/ */
free (key); g_free (key);
free (oldvalue); g_free (oldvalue);
} }
/* /*
* Insert the name/value pair into the hash table. * Insert the name/value pair into the hash table.
* *
* Note that these strdup allocations are freed in cleanup, * Note that these g_strdup allocations are freed in cleanup,
* which is called by FreeConnectParams. * which is called by FreeConnectParams.
*/ */
g_hash_table_insert (params->table, strdup (name), strdup (value)); g_hash_table_insert (params->table, g_strdup (name), g_strdup (value));
p = strchr (s, '='); p = strchr (s, '=');
} }
free (cs); g_free (cs);
} }
/* /*
@@ -471,8 +472,8 @@ static void visit (gpointer key, gpointer value, gpointer user_data)
static gboolean cleanup (gpointer key, gpointer value, gpointer user_data) static gboolean cleanup (gpointer key, gpointer value, gpointer user_data)
{ {
free (key); g_free (key);
free (value); g_free (value);
return TRUE; return TRUE;
} }

View File

@@ -32,7 +32,7 @@
#include "connectparams.h" #include "connectparams.h"
static char software_version[] = "$Id: odbc.c,v 1.17 2004/04/13 03:17:20 whydoubt Exp $"; static char software_version[] = "$Id: odbc.c,v 1.18 2004/05/30 08:06:43 whydoubt Exp $";
static void *no_unused_var_warn[] = {software_version, static void *no_unused_var_warn[] = {software_version,
no_unused_var_warn}; no_unused_var_warn};
@@ -440,11 +440,10 @@ ODBCConnection* dbc;
TRACE("_SQLAllocConnect"); TRACE("_SQLAllocConnect");
env = (struct _henv *) henv; env = (struct _henv *) henv;
dbc = (SQLHDBC) malloc (sizeof (ODBCConnection)); dbc = (SQLHDBC) g_malloc0(sizeof (ODBCConnection));
memset(dbc,'\0',sizeof (ODBCConnection));
dbc->hdbc.henv=env; dbc->hdbc.henv=env;
dbc->params = NewConnectParams (); dbc->params = NewConnectParams ();
*phdbc=dbc; *phdbc=dbc;
return SQL_SUCCESS; return SQL_SUCCESS;
@@ -463,8 +462,7 @@ static SQLRETURN SQL_API _SQLAllocEnv(
struct _henv *env; struct _henv *env;
TRACE("_SQLAllocEnv"); TRACE("_SQLAllocEnv");
env = (SQLHENV) g_malloc(sizeof(struct _henv)); env = (SQLHENV) g_malloc0(sizeof(struct _henv));
memset(env,'\0',sizeof(struct _henv));
*phenv=env; *phenv=env;
env->sql = mdb_sql_init(); env->sql = mdb_sql_init();
return SQL_SUCCESS; return SQL_SUCCESS;
@@ -486,8 +484,7 @@ struct _hstmt *stmt;
TRACE("_SQLAllocStmt"); TRACE("_SQLAllocStmt");
dbc = (struct _hdbc *) hdbc; dbc = (struct _hdbc *) hdbc;
stmt = (SQLHSTMT) g_malloc(sizeof(struct _hstmt)); stmt = (SQLHSTMT) g_malloc0(sizeof(struct _hstmt));
memset(stmt,'\0',sizeof(struct _hstmt));
stmt->hdbc=hdbc; stmt->hdbc=hdbc;
*phstmt = stmt; *phstmt = stmt;
@@ -510,7 +507,7 @@ SQLRETURN SQL_API SQLBindCol(
SQLINTEGER FAR *pcbValue) SQLINTEGER FAR *pcbValue)
{ {
struct _hstmt *stmt = (struct _hstmt *) hstmt; struct _hstmt *stmt = (struct _hstmt *) hstmt;
struct _sql_bind_info *cur, *prev, *newitem; struct _sql_bind_info *cur, *newitem;
TRACE("SQLBindCol"); TRACE("SQLBindCol");
/* find available item in list */ /* find available item in list */
@@ -527,8 +524,7 @@ SQLRETURN SQL_API SQLBindCol(
cur->varaddr = (char *) rgbValue; cur->varaddr = (char *) rgbValue;
} else { } else {
/* didn't find it create a new one */ /* didn't find it create a new one */
newitem = (struct _sql_bind_info *) malloc(sizeof(struct _sql_bind_info)); newitem = (struct _sql_bind_info *) g_malloc0(sizeof(struct _sql_bind_info));
memset(newitem, 0, sizeof(struct _sql_bind_info));
newitem->column_number = icol; newitem->column_number = icol;
newitem->column_bindtype = fCType; newitem->column_bindtype = fCType;
newitem->column_bindlen = cbValueMax; newitem->column_bindlen = cbValueMax;
@@ -540,11 +536,10 @@ SQLRETURN SQL_API SQLBindCol(
} else { } else {
/* find the tail of the list */ /* find the tail of the list */
cur = stmt->bind_head; cur = stmt->bind_head;
while (cur) { while (cur->next) {
prev = cur;
cur = cur->next; cur = cur->next;
} }
prev->next = newitem; cur->next = newitem;
} }
} }