From 442083902d8652eac225cf6e9e2a9a8f0963d53a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Fri, 6 Jun 2008 13:59:44 +0000 Subject: [PATCH] Cosmetic fix in behaviour (return NULL DB context on error). Warning fixes. --- org.glite.lbjp-common.db/examples/db_expire.c | 2 +- org.glite.lbjp-common.db/examples/db_test.c | 2 +- org.glite.lbjp-common.db/src/db.c | 13 +++++++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/org.glite.lbjp-common.db/examples/db_expire.c b/org.glite.lbjp-common.db/examples/db_expire.c index 67fee31..2eb3ba6 100644 --- a/org.glite.lbjp-common.db/examples/db_expire.c +++ b/org.glite.lbjp-common.db/examples/db_expire.c @@ -65,7 +65,7 @@ static void print_error(glite_lbu_DBContext ctx) { } -int main(int argn, char *argv[]) { +int main(int argn __attribute((unused)), char *argv[]) { char *name, *user; const char *cs; glite_lbu_DBContext ctx; diff --git a/org.glite.lbjp-common.db/examples/db_test.c b/org.glite.lbjp-common.db/examples/db_test.c index c9d1ca9..a80b9dd 100644 --- a/org.glite.lbjp-common.db/examples/db_test.c +++ b/org.glite.lbjp-common.db/examples/db_test.c @@ -58,7 +58,7 @@ static void print_free_result(const char *name, unsigned long *lens, char **res) } -int main(int argn, char *argv[]) { +int main(int argn __attribute((unused)), char *argv[]) { char *name, *cmd; const char *cs; glite_lbu_DBContext ctx; diff --git a/org.glite.lbjp-common.db/src/db.c b/org.glite.lbjp-common.db/src/db.c index 0727f68..9827820 100644 --- a/org.glite.lbjp-common.db/src/db.c +++ b/org.glite.lbjp-common.db/src/db.c @@ -192,8 +192,11 @@ int glite_lbu_InitDBContext(glite_lbu_DBContext *ctx) { pthread_mutex_lock(&db_handle.lock); if (!db_handle.lib) { if ((!MYSQL_LIBPATH[0] || (db_handle.lib = dlopen(MYSQL_LIBPATH, RTLD_LAZY | RTLD_LOCAL)) == NULL) && - (db_handle.lib = dlopen("libmysqlclient.so", RTLD_LAZY | RTLD_LOCAL)) == NULL) + (db_handle.lib = dlopen("libmysqlclient.so", RTLD_LAZY | RTLD_LOCAL)) == NULL) { + free(*ctx); + *ctx = NULL; return ERR(*ctx, ENOENT, "can't load '%s' or 'libmysqlclient.so' (%s)", MYSQL_LIBPATH, dlerror()); + } do { LOAD(mysql_init, "mysql_init"); LOAD(mysql_get_client_version, "mysql_get_client_version"); @@ -241,6 +244,8 @@ int glite_lbu_InitDBContext(glite_lbu_DBContext *ctx) { dlclose(db_handle.lib); db_handle.lib = NULL; pthread_mutex_unlock(&db_handle.lock); + free(*ctx); + *ctx = NULL; return err; } } else pthread_mutex_unlock(&db_handle.lock); @@ -365,17 +370,17 @@ void glite_lbu_FreeStmt(glite_lbu_Statement *stmt) { int glite_lbu_QueryIndices(glite_lbu_DBContext ctx, const char *table, char ***key_names, char ****column_names) { glite_lbu_Statement stmt = NULL; - int i,j,ret; + size_t i,j,ret; /* XXX: "show index from" columns. Matches at least MySQL 4.0.11 */ char *sql, *showcol[12]; int Key_name,Seq_in_index,Column_name,Sub_part; char **keys = NULL; - int *cols = NULL; + size_t *cols = NULL; char **col_names = NULL; - int nkeys = 0; + size_t nkeys = 0; char ***idx = NULL; -- 1.8.2.3