diff -u -urp ulogd-1.24.orig/mysql/ulogd_MYSQL.c ulogd-1.24/mysql/ulogd_MYSQL.c --- ulogd-1.24.orig/mysql/ulogd_MYSQL.c 2007-03-22 21:14:10.000000000 +0000 +++ ulogd-1.24/mysql/ulogd_MYSQL.c 2007-03-22 21:28:17.000000000 +0000 @@ -147,6 +147,9 @@ static int mysql_output(ulog_iret_t *res struct in_addr addr; #endif + if( stmt_val == NULL || dbh == NULL) + return 1; + stmt_ins = stmt_val; for (f = fields; f; f = f->next) { @@ -394,8 +397,11 @@ static int mysql_open_db(char *server, i if (connect_timeout_ce.u.value) mysql_options(dbh, MYSQL_OPT_CONNECT_TIMEOUT, (const char *) &connect_timeout_ce.u.value); - if (!mysql_real_connect(dbh, server, user, pass, db, port, NULL, 0)) + if (!mysql_real_connect(dbh, server, user, pass, db, port, NULL, 0)) { + mysql_close(dbh); + dbh = NULL; return -1; + } return 0; } @@ -433,10 +439,17 @@ static int _mysql_init_db(ulog_iret_t *r /* read the fieldnames to know which values to insert */ if (mysql_get_columns(table_ce.u.string)) { + mysql_close(dbh); + dbh = NULL; ulogd_log(ULOGD_ERROR, "unable to get mysql columns\n"); return init_reconnect(); } - mysql_createstmt(); + + if( mysql_createstmt()) { + mysql_close(dbh); + dbh = NULL; + return init_reconnect(); + } /* enable plugin */ mysql_plugin.output = &mysql_output; diff -u -urp ulogd-1.24.orig/pgsql/ulogd_PGSQL.c ulogd-1.24/pgsql/ulogd_PGSQL.c --- ulogd-1.24.orig/pgsql/ulogd_PGSQL.c 2007-03-22 21:14:10.000000000 +0000 +++ ulogd-1.24/pgsql/ulogd_PGSQL.c 2007-03-22 21:28:17.000000000 +0000 @@ -112,6 +112,9 @@ static int pgsql_output(ulog_iret_t *res struct in_addr addr; #endif + if( stmt_val == NULL || dbh == NULL) + return 1; + stmt_ins = stmt_val; for (f = fields; f; f = f->next) { @@ -441,6 +444,7 @@ static int pgsql_open_db(char *server, i free(connstr); if (PQstatus(dbh)!=CONNECTION_OK) { exit_nicely(dbh); + dbh = NULL; return 1; } @@ -459,23 +463,34 @@ static int pgsql_init(void) } if (pgsql_namespace()) { - return 1; + PQfinish(dbh); + dbh = NULL; ulogd_log(ULOGD_ERROR, "unable to test for pgsql schemas\n"); + return 1; } /* read the fieldnames to know which values to insert */ if (pgsql_get_columns(table_ce.u.string)) { + PQfinish(dbh); + dbh = NULL; ulogd_log(ULOGD_ERROR, "unable to get pgsql columns\n"); return 1; } - pgsql_createstmt(); + if (pgsql_createstmt()) { + PQfinish(dbh); + dbh = NULL; + return 1; + } return 0; } static void pgsql_fini(void) { - PQfinish(dbh); + if( dbh) + PQfinish(dbh); + if( stmt) + free(stmt); } static ulog_output_t pgsql_plugin = { diff -u -urp ulogd-1.24.orig/sqlite3/ulogd_SQLITE3.c ulogd-1.24/sqlite3/ulogd_SQLITE3.c --- ulogd-1.24.orig/sqlite3/ulogd_SQLITE3.c 2007-03-22 21:14:10.000000000 +0000 +++ ulogd-1.24/sqlite3/ulogd_SQLITE3.c 2007-03-22 21:28:17.000000000 +0000 @@ -98,6 +98,8 @@ static int _sqlite3_output(ulog_iret_t * char *ipaddr; struct in_addr addr; #endif + if (p_stmt == NULL || dbh == NULL) + return 1; col_counter = 1; for (f = fields; f; f = f->next) { @@ -263,15 +265,16 @@ static int _sqlite3_createstmt(void) DEBUGP("about to prepare statement.\n"); - sqlite3_prepare(dbh,stmt,-1,&p_stmt,0); - - DEBUGP("statement prepared.\n"); - - if (!p_stmt) { + if( sqlite3_prepare(dbh,stmt,-1,&p_stmt,0) != SQLITE_OK) { + p_stmt = NULL; + free( stmt); + stmt = NULL; ulogd_log(ULOGD_ERROR,"unable to prepare statement"); return 1; } + DEBUGP("statement prepared.\n"); + return 0; } @@ -376,6 +379,7 @@ static int _sqlite3_init(void) config_parse_file("SQLITE3", &buffer_ce); if (_sqlite3_open_db(db_ce.u.string)) { + dbh = NULL; ulogd_log(ULOGD_ERROR, "can't open the database file\n"); return 1; } @@ -386,6 +390,8 @@ static int _sqlite3_init(void) /* read the fieldnames to know which values to insert */ if (_sqlite3_get_columns(table_ce.u.string)) { + sqlite3_close(dbh); + dbh = NULL; ulogd_log(ULOGD_ERROR, "unable to get sqlite columns\n"); return 1; } @@ -400,7 +406,11 @@ static int _sqlite3_init(void) ulogd_log(ULOGD_ERROR,"can't create a new transaction\n"); /* create and prepare the actual insert statement */ - _sqlite3_createstmt(); + if(_sqlite3_createstmt()) { + sqlite3_close(dbh); + dbh = NULL; + return 1; + } return 0; } diff -u -urp ulogd-1.24.orig/ulogd.c ulogd-1.24/ulogd.c --- ulogd-1.24.orig/ulogd.c 2005-11-25 19:58:27.000000000 +0000 +++ ulogd-1.24/ulogd.c 2007-03-22 21:28:17.000000000 +0000 @@ -595,14 +595,15 @@ static void sigterm_handler(int signal) ipulog_destroy_handle(libulog_h); free(libulog_buf); - if (logfile != stdout && logfile != &syslog_dummy) - fclose(logfile); for (p = ulogd_outputs; p; p = p->next) { if (p->fini) (*p->fini)(); } + if (logfile != stdout && logfile != &syslog_dummy) + fclose(logfile); + exit(0); }