Received: from www.xshare.com (www.fileseeker.net [212.84.237.17]) by hub.hub.org (8.10.1/8.10.1) with ESMTP id e9FIF7q31722 for ; Sun, 15 Oct 2000 14:15:07 -0400 (EDT) Received: from holodeck.leveld.de ([212.84.237.15] helo=holodeck) by www.xshare.com with smtp (Exim 3.13 #1) id 13ksJO-000L2U-00 for pgsql-interfaces@postgresql.org; Sun, 15 Oct 2000 18:15:06 +0000 Message-ID: <005501c036d4$6e37c810$0fed54d4@leveld.de> From: "Oliver Fischer" To: Subject: PQclear() causes coredump Date: Sun, 15 Oct 2000 20:19:17 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.00.2919.6600 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 X-Archive-Number: 200010/116 X-Sequence-Number: 1473 Hi Folks, I write a program in c++ using PostgreSQL 7.0 at the moment. During this, I have written some small classes for accessing the database. One of this classes is QtResultSet. I use them to manage my statments. To avoid memory leaks, I use the dtor to free the resultset with PQclear(). Unfortunaly every call to PQclear causes a coredump. What is my mistake? === QtResultSet.h === #include #include #include #include #include "../errors/QtExceptions.h" #ifndef __QTRESULTSET__ #define __QTRESULTSET__ namespace qt { namespace database { using namespace std; using namespace qt::errors; class QtResultSet { public: virtual ~QtResultSet(); vector fieldnames() throw(QtDbConnectionBadErr, QtDbFatalErr, QtDbNonfatalErr, QtDbBadResponseErr); vector fetch(int) throw(QtDbConnectionBadErr, QtDbFatalErr, QtDbNonfatalErr, QtDbBadResponseErr); vector fetch(void) throw(QtDbConnectionBadErr, QtDbFatalErr, QtDbNonfatalErr, QtDbBadResponseErr); string get_error(); int rows(); int fields(); void execute() throw(QtDbConnectionBadErr, QtDbFatalErr, QtDbNonfatalErr, QtDbBadResponseErr); friend class QtConnection; protected: QtResultSet(PGconn *, const string &); private: void fetch_row(int, vector*); bool binarydata_m; int rows_m; int fields_m; int currentrow_m; string query_m; string error_m; PGresult *pgresult_mp; PGconn *pgconn_mp; }; } } #endif === QtResultSet.cpp === #include #include #include "QtResultSet.h" #include "../errors/QtExceptions.h" namespace qt { namespace database { using namespace std; using namespace qt::errors; QtResultSet::~QtResultSet() { PQclear(this->pgresult_mp); } QtResultSet::QtResultSet(PGconn *pgconn, const string &query) { pgconn_mp = pgconn; query_m = query; fields_m = 0; rows_m = 0; currentrow_m = 0; } void QtResultSet::execute() throw(QtDbConnectionBadErr, QtDbFatalErr, QtDbNonfatalErr, QtDbBadResponseErr) try { pgresult_mp = PQexec(pgconn_mp, query_m.c_str()); ExecStatusType res = PQresultStatus(pgresult_mp); if (res == (PGRES_COMMAND_OK || PGRES_TUPLES_OK)) { rows_m = PQntuples(pgresult_mp); fields_m = PQnfields(pgresult_mp); binarydata_m = PQbinaryTuples(pgresult_mp); currentrow_m = -1; } else { error_m = PQresultErrorMessage(pgresult_mp); switch (res) { case PGRES_EMPTY_QUERY: break; case PGRES_BAD_RESPONSE: throw QtDbBadResponseErr(); break; case PGRES_NONFATAL_ERROR: throw QtDbNonfatalErr(); break; case PGRES_FATAL_ERROR: throw QtDbFatalErr(); break; } } } catch (...) { #ifdef QTDEBUG cerr << "Exception catched and PQclear() called." << endl; #endif QTDEBUG PQclear(pgresult_mp); #ifdef QTDEBUG cerr << "Exception rethrown." << endl; #endif QTDEBUG throw; } } int QtResultSet::fields() { return fields_m; } int QtResultSet::rows() { return rows_m; } vector QtResultSet::fieldnames() throw(QtDbConnectionBadErr, QtDbFatalErr, QtDbNonfatalErr, QtDbBadResponseErr) { vector row; for (int i = 0; i < rows_m; i++) { row.push_back(PQfname(pgresult_mp, i)); } return row; } vector QtResultSet::fetch(void) throw(QtDbConnectionBadErr, QtDbFatalErr, QtDbNonfatalErr, QtDbBadResponseErr) { vector row; if (currentrow_m < (rows_m - 1)) { this->fetch_row(++currentrow_m, &row); } else { } return row; } vector QtResultSet::fetch(int id) throw(QtDbConnectionBadErr, QtDbFatalErr, QtDbNonfatalErr, QtDbBadResponseErr) { vector row; if ((id > 0) && (id < rows_m)) { this->fetch_row(id, &row); } else { } return row; } void QtResultSet::fetch_row(int rowid, vector *rowdata) { for (int i = 0; i < fields_m; i++) { rowdata->push_back(string("Aber Hallo")); } } string QtResultSet::get_error() { return this->error_m; } // QtResultSet::get_error } // namespace database } // namespace qt BYe, Oliver -- Oliver Fischer Level of Detail, Brunnenstr. 196, D-10119 Berlin Tel. +49/30/280 491 43 -- Oliver Fischer Level of Detail, Brunnenstr. 196, D-10119 Berlin Tel. +49/30/280 491 43