Permalink
Browse files

fix memory leaks, remove redundant header file

git-svn-id: http://kazuho.31tools.com/svn/incline/trunk@250 4d3e2a30-9d6d-0410-bc8c-dac56cff10b3
  • Loading branch information...
kazuho
kazuho committed Nov 3, 2009
1 parent 66af2b7 commit 00772dc1eae67227248b66f31400709d574b08ab
Showing with 17 additions and 30 deletions.
  1. +1 −1 src/Makefile.am
  2. +1 −0 src/getoptpp.h
  3. +10 −7 src/incline.cc
  4. +0 −17 src/incline.h
  5. +3 −3 src/incline_dbms.cc
  6. +2 −1 src/incline_dbms.h
  7. +0 −1 src/incline_mgr.cc
View
@@ -1,5 +1,5 @@
bin_PROGRAMS = incline
-incline_SOURCES = getoptpp.h incline_dbms.cc incline_dbms.h incline_def.cc incline_def.h incline_driver.cc incline_driver.h incline_mgr.cc incline_mgr.h incline_util.cc incline_util.h incline.cc incline.h interthr_call.h picojson.h start_thread.h tmd.h
+incline_SOURCES = getoptpp.h incline_dbms.cc incline_dbms.h incline_def.cc incline_def.h incline_driver.cc incline_driver.h incline_mgr.cc incline_mgr.h incline_util.cc incline_util.h incline.cc interthr_call.h picojson.h start_thread.h tmd.h
incline_SOURCES += incline_driver_standalone.cc incline_driver_standalone.h
incline_SOURCES += incline_def_async.cc incline_def_async.h incline_driver_async.cc incline_driver_async.h
incline_SOURCES += incline_def_async_qtable.cc incline_def_async_qtable.h incline_driver_async_qtable.cc incline_driver_async_qtable.h
View
@@ -211,6 +211,7 @@ namespace getoptpp {
success = false;
}
}
+ delete [] opts;
return success;
}
}
View
@@ -6,7 +6,10 @@ extern "C" {
#include <iterator>
#include "getoptpp.h"
#include "incline_config.h"
-#include "incline.h"
+#include "incline_def_sharded.h"
+#include "incline_dbms.h"
+#include "incline_driver_sharded.h"
+#include "incline_mgr.h"
using namespace std;
@@ -18,7 +21,7 @@ static getoptpp::opt_flag opt_print_only(0, "print-only",
static getoptpp::opt_str opt_forwarder_log_file(0, "forwarder-log-file", false,
"", "");
-static incline_mgr* mgr = NULL;
+static auto_ptr<incline_mgr> mgr;
static void run_all_stmt(incline_dbms* dbh, const vector<string>& stmt)
{
@@ -57,11 +60,11 @@ inline incline_driver_sharded* shard_driver()
static incline_dbms* dbh()
{
- static incline_dbms* dbh = NULL;
- if (dbh == NULL) {
- dbh = incline_dbms::factory_->create();
+ static auto_ptr<incline_dbms> h;
+ if (h.get() == NULL) {
+ h.reset(incline_dbms::factory_->create());
}
- return dbh;
+ return h.get();
}
int
@@ -104,7 +107,7 @@ main(int argc, char** argv)
cerr << "unknown mode:" << *opt_mode << endl;
exit(1);
}
- mgr = new incline_mgr(driver);
+ mgr.reset(new incline_mgr(driver));
}
{ // parse source
View
@@ -1,17 +0,0 @@
-#ifndef incline_h
-#define incline_h
-
-#include "incline_def.h"
-#include "incline_def_async.h"
-#include "incline_def_async_qtable.h"
-#include "incline_def_sharded.h"
-#include "incline_dbms.h"
-#include "incline_driver.h"
-#include "incline_driver_async.h"
-#include "incline_driver_async_qtable.h"
-#include "incline_driver_sharded.h"
-#include "incline_mgr.h"
-#include "incline_util.h"
-#include "picojson.h"
-
-#endif
View
@@ -24,7 +24,7 @@ getoptpp::opt_str incline_dbms::opt_user_('u', "user", false, "database user",
"root");
getoptpp::opt_str incline_dbms::opt_password_('p', "password", false,
"database password", "");
-incline_dbms::factory* incline_dbms::factory_ = NULL;
+auto_ptr<incline_dbms::factory> incline_dbms::factory_;
pair<string, unsigned short>
incline_dbms::factory::get_hostport() const
@@ -52,13 +52,13 @@ incline_dbms::setup_factory()
{
#ifdef WITH_MYSQL
if (*opt_rdbms_ == "mysql" || *opt_rdbms_ == "mysqld") {
- factory_ = new incline_mysql::factory();
+ factory_.reset(new incline_mysql::factory());
return true;
}
#endif
#ifdef WITH_PGSQL
if (*opt_rdbms_ == "pgsql" || *opt_rdbms_ == "postgresql") {
- factory_ = new incline_pgsql::factory();
+ factory_.reset(new incline_pgsql::factory());
return true;
}
#endif
View
@@ -5,6 +5,7 @@
#include <string>
#include <vector>
#include <map>
+#include <memory>
#include "getoptpp.h"
class incline_dbms {
@@ -78,7 +79,7 @@ class incline_dbms {
static getoptpp::opt_int opt_port_;
static getoptpp::opt_str opt_user_;
static getoptpp::opt_str opt_password_;
- static factory* factory_;
+ static std::auto_ptr<factory> factory_;
static bool setup_factory();
};
View
@@ -1,5 +1,4 @@
#include <algorithm>
-#include <memory>
#include <set>
#include "incline_dbms.h"
#include "incline_driver.h"

0 comments on commit 00772dc

Please sign in to comment.