mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-04-05 20:31:00 +08:00
better utilize glib functions, fix memory leak
This commit is contained in:
parent
a5afa5c9e4
commit
b6dd1b63c5
@ -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-tables.c:
|
||||
* 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>
|
||||
* src/libmdb/backend.c:
|
||||
|
@ -60,7 +60,7 @@ static gboolean cleanup (gpointer key, gpointer value, gpointer user_data);
|
||||
|
||||
ConnectParams* NewConnectParams ()
|
||||
{
|
||||
ConnectParams* params = malloc (sizeof (ConnectParams));
|
||||
ConnectParams* params = (ConnectParams *) g_malloc(sizeof (ConnectParams));
|
||||
if (!params)
|
||||
return params;
|
||||
|
||||
@ -88,6 +88,7 @@ void FreeConnectParams (ConnectParams* params)
|
||||
g_hash_table_foreach_remove (params->table, cleanup, NULL);
|
||||
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
|
||||
*/
|
||||
cs = strdup (connectString);
|
||||
cs = (char *) g_strdup(connectString);
|
||||
s = cs;
|
||||
/*
|
||||
* Loop over ';' seperated name=value pairs
|
||||
@ -239,21 +240,21 @@ void SetConnectString (ConnectParams* params, const gchar* connectString)
|
||||
/*
|
||||
* cleanup strings
|
||||
*/
|
||||
free (key);
|
||||
free (oldvalue);
|
||||
g_free (key);
|
||||
g_free (oldvalue);
|
||||
}
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
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, '=');
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
free (key);
|
||||
free (value);
|
||||
g_free (key);
|
||||
g_free (value);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -32,7 +32,7 @@
|
||||
|
||||
#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,
|
||||
no_unused_var_warn};
|
||||
|
||||
@ -440,11 +440,10 @@ ODBCConnection* dbc;
|
||||
|
||||
TRACE("_SQLAllocConnect");
|
||||
env = (struct _henv *) henv;
|
||||
dbc = (SQLHDBC) malloc (sizeof (ODBCConnection));
|
||||
memset(dbc,'\0',sizeof (ODBCConnection));
|
||||
dbc = (SQLHDBC) g_malloc0(sizeof (ODBCConnection));
|
||||
dbc->hdbc.henv=env;
|
||||
|
||||
dbc->params = NewConnectParams ();
|
||||
|
||||
dbc->params = NewConnectParams ();
|
||||
*phdbc=dbc;
|
||||
|
||||
return SQL_SUCCESS;
|
||||
@ -463,8 +462,7 @@ static SQLRETURN SQL_API _SQLAllocEnv(
|
||||
struct _henv *env;
|
||||
|
||||
TRACE("_SQLAllocEnv");
|
||||
env = (SQLHENV) g_malloc(sizeof(struct _henv));
|
||||
memset(env,'\0',sizeof(struct _henv));
|
||||
env = (SQLHENV) g_malloc0(sizeof(struct _henv));
|
||||
*phenv=env;
|
||||
env->sql = mdb_sql_init();
|
||||
return SQL_SUCCESS;
|
||||
@ -486,8 +484,7 @@ struct _hstmt *stmt;
|
||||
TRACE("_SQLAllocStmt");
|
||||
dbc = (struct _hdbc *) hdbc;
|
||||
|
||||
stmt = (SQLHSTMT) g_malloc(sizeof(struct _hstmt));
|
||||
memset(stmt,'\0',sizeof(struct _hstmt));
|
||||
stmt = (SQLHSTMT) g_malloc0(sizeof(struct _hstmt));
|
||||
stmt->hdbc=hdbc;
|
||||
*phstmt = stmt;
|
||||
|
||||
@ -510,7 +507,7 @@ SQLRETURN SQL_API SQLBindCol(
|
||||
SQLINTEGER FAR *pcbValue)
|
||||
{
|
||||
struct _hstmt *stmt = (struct _hstmt *) hstmt;
|
||||
struct _sql_bind_info *cur, *prev, *newitem;
|
||||
struct _sql_bind_info *cur, *newitem;
|
||||
|
||||
TRACE("SQLBindCol");
|
||||
/* find available item in list */
|
||||
@ -527,8 +524,7 @@ SQLRETURN SQL_API SQLBindCol(
|
||||
cur->varaddr = (char *) rgbValue;
|
||||
} else {
|
||||
/* didn't find it create a new one */
|
||||
newitem = (struct _sql_bind_info *) malloc(sizeof(struct _sql_bind_info));
|
||||
memset(newitem, 0, sizeof(struct _sql_bind_info));
|
||||
newitem = (struct _sql_bind_info *) g_malloc0(sizeof(struct _sql_bind_info));
|
||||
newitem->column_number = icol;
|
||||
newitem->column_bindtype = fCType;
|
||||
newitem->column_bindlen = cbValueMax;
|
||||
@ -540,11 +536,10 @@ SQLRETURN SQL_API SQLBindCol(
|
||||
} else {
|
||||
/* find the tail of the list */
|
||||
cur = stmt->bind_head;
|
||||
while (cur) {
|
||||
prev = cur;
|
||||
while (cur->next) {
|
||||
cur = cur->next;
|
||||
}
|
||||
prev->next = newitem;
|
||||
cur->next = newitem;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user