From b8f455ee7c46ad7524e9b09ae4ee64e0401247dc Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sun, 3 Dec 2017 11:00:40 -0500 Subject: [PATCH] some cleanup, add a note about the lines that cause zm to crash --- src/zm_db.cpp | 7 ++++--- src/zm_db.h | 31 +++++++++++-------------------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/zm_db.cpp b/src/zm_db.cpp index bb83d09ab..ac09dca13 100644 --- a/src/zm_db.cpp +++ b/src/zm_db.cpp @@ -25,11 +25,12 @@ MYSQL dbconn; -int zmDbConnected = false; +bool zmDbConnected = false; void zmDbConnect() { - if ( zmDbConnected ) - return; + // If these lines are uncommented, we get memory corruption and crashes + //if ( zmDbConnected ) + //return; if ( !mysql_init( &dbconn ) ) { Error( "Can't initialise database connection: %s", mysql_error( &dbconn ) ); diff --git a/src/zm_db.h b/src/zm_db.h index f9b158be8..f53a8c738 100644 --- a/src/zm_db.h +++ b/src/zm_db.h @@ -23,35 +23,26 @@ #include class zmDbRow { - private: - MYSQL_RES *result_set; - MYSQL_ROW row; - public: - zmDbRow() { result_set = NULL; row = NULL; }; - MYSQL_RES *fetch( const char *query ); - zmDbRow( MYSQL_RES *, MYSQL_ROW *row ); - ~zmDbRow(); + private: + MYSQL_RES *result_set; + MYSQL_ROW row; + public: + zmDbRow() { result_set = NULL; row = NULL; }; + MYSQL_RES *fetch( const char *query ); + zmDbRow( MYSQL_RES *, MYSQL_ROW *row ); + ~zmDbRow(); - char *operator[](unsigned int index) const { - return row[index]; - } + char *operator[](unsigned int index) const { + return row[index]; + } }; -#ifdef __cplusplus -extern "C" { -#endif extern MYSQL dbconn; -extern int zmDbConnected; - void zmDbConnect(); void zmDbClose(); MYSQL_RES * zmDbFetch( const char *query ); zmDbRow *zmDbFetchOne( const char *query ); -#ifdef __cplusplus -} /* extern "C" */ -#endif - #endif // ZM_DB_H