List:MySQL++« Previous MessageNext Message »
From:Thunder0 Date:November 21 2007 10:14am
Subject:Is method "const ColData Row::at(size_type i) const" leaking memory?
View as plain text  
Hi all,
this is my first message to the list.
I am using valgrind to check my application that is using mysqlpp to access
a mysql DB.

This is the valgrind message I am concerned about:

==22261== Thread 1:
==22261==
==22261== 111 bytes in 6 blocks are definitely lost in loss record 3 of 7
==22261==    at 0x4005628: operator new[](unsigned)
(vg_replace_malloc.c:197)
==22261==    by 0x404B05F: mysqlpp::Row::at(unsigned) const
(const_string.h:123)==22261==    by 0x404B3E6: mysqlpp::Row::operator[](char
const*) const (row.cpp:115)
==22261==    by 0x8061FFD:
btau::DBSession::retrieveLastLinkingitem(std::vector<btau::LinkingItemData,
std::allocator<btau::LinkingItemData> >&) const (DBSession.cpp:590)
==22261==    by 0x8076395:
btau::ApplicationDataLogicManager::saveTimestampAndLinkingItem(btau::TimeStampData&)
(ApplicationDataLogicManager.cpp:388)
==22261==    by 0x8089436:
btau::TSUMessageProcessingThread::manageTimeStampsaveRequest(TSURequest*)
(TSUMessageProcessingThread.cpp:526)
==22261==    by 0x8089D6D: btau::TSUMessageProcessingThread::Run()
(TSUMessageProcessingThread.cpp:402)
==22261==    by 0x809F402: Thread::StartThread(void*) (Thread.cpp:106)
==22261==    by 0x369432: start_thread (in /lib/libpthread-2.4.so)
==22261==    by 0x4126A1D: clone (in /lib/libc-2.4.so)

Here is the fragment of my software valgrind is referring to



		mysqlpp::Result res = query.store();
		mysqlpp::Row row;
		if(res.size() > 1){
			std::cout << "ERROR: the query select ID_N,XN,LN,SERIAL_N from
LINKING_ITEM where ID_N = (select max(ID_N) from LINKING_ITEM) returned more
than one record  " << std::endl;
			assert(false);
		}
		for(unsigned int i=0; i < res.size();i++){
			row = res.at(i);
			LinkingItemData retrievedData;
			
			std::string value(row["ID_N"]);// >>>>>> line 590 mentioned in
valgrind
message 
			retrievedData.setID(StringToValuesConverter::toULong(value));
			value.assign(row["XN"]);
			retrievedData.setXN(value);
			value.assign(row["LN"]);
			retrievedData.setLN(value);
			value.assign(row["SERIAL_N"]);
			retrievedData.setSerialN(StringToValuesConverter::toULong(value));
			value.assign(row["HASH_ALG"]);
			retrievedData.setHashAlg(value);
			value.assign(row["ID_AU_SOURCE"]);
			retrievedData.setIdAuSource(StringToValuesConverter::toULong(value));
			linkingItemList.push_back(retrievedData);
		}


Here is my suspect:

const ColData Row::at(size_type i) const
{
	if (initialized_) {
		const std::string& s = data_.at(i);
		return ColData(s.data(), s.length(), res_->types(i),
			is_nulls_[i]);
	}
	else {
		if (throw_exceptions())
			throw std::out_of_range("Row not initialized");
		else
			return ColData();
	}
}

when the "ColData" copy constructor is invoked, it is like it calls the
const_string copy constructor first, allocating a new buffer and then this
new "const_string" object is initialised by the ColData copy contstructor


	/// brief Copy ctor
	///
	/// param cd the other ColData_Tmpl object
	ColData_Tmpl(const ColData_Tmpl<Str>& cd) :
	Str(cd.data(), cd.length()),
	type_(cd.type_),
	null_(cd.null_)
	{
	}


I am not sure about this, could you please give me some help?

Many thanks. 
 --
 Email.it, the professional e-mail, gratis per te: http://www.email.it/f
 
 Sponsor:
 Fai squillare la PANTERA ROSA sul tuo cellulare: e' in REGALO
 Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=6613&d=20071121


Thread
Is method "const ColData Row::at(size_type i) const" leaking memory?Thunder021 Nov
  • Re: Is method "const ColData Row::at(size_type i) const" leakingmemory?Warren Young22 Nov
Re: Is method "const ColData Row::at(size_type i) const" leaking memory?Thunder026 Nov
  • Re: Is method "const ColData Row::at(size_type i) const" leakingmemory?Warren Young26 Nov
    • Re: Is method "const ColData Row::at(size_type i) const" leaking memory?Graham Reitz27 Nov
      • Re: Query object seg. faults on destruction...Graham Reitz27 Nov
        • Re: Query object seg. faults on destruction...Warren Young27 Nov
          • Re: Query object seg. faults on destruction...Graham Reitz27 Nov
            • Re: Query object seg. faults on destruction...Warren Young27 Nov
              • Re: Query object seg. faults on destruction...Graham Reitz28 Nov
Re: Is method "const ColData Row::at(size_type i) const" leaking memory?Thunder027 Nov
  • Re: Is method "const ColData Row::at(size_type i) const" leakingmemory?Warren Young27 Nov
Re: Is method "const ColData Row::at(size_type i) const" leaking memory?Thunder028 Nov
  • Re: Is method "const ColData Row::at(size_type i) const" leakingmemory?Warren Young28 Nov