This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

sigfault in destructor


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi, I have this backtrace, is it a libstdc++ bug, Am I doing something wrong ?
it happens when i try to delete an object that has an std::string member.
I'm attaching the source code in case it helps.
thanks,
Pablo


(gdb) backtrace 
#0  0x400bab4b in std::basic_streambuf<char, std::char_traits<char> 
>::xsputn(char const*, int) () from /usr/lib/libstdc++.so.5
#1  0x40079618 in std::basic_filebuf<char, std::char_traits<char> 
>::xsputn(char const*, int) () from /usr/lib/libstdc++.so.5
#2  0x400ba7af in std::basic_streambuf<char, std::char_traits<char> 
>::sputn(char const*, int) () from /usr/lib/libstdc++.so.5
#3  0x400aea44 in std::basic_ostream<char, std::char_traits<char> >& 
std::operator<< <char, std::char_traits<char>, std::allocator<char> 
>(std::basic_ostream<char, std::char_traits<char> >&, std::basic_string<char, 
std::char_traits<char>, std::allocator<char> > const&) () 
from /usr/lib/libstdc++.so.5
#4  0x08050559 in ~CAttach (this=0x82efe50) 
at /home/pablo/proyectos/lma/cuaderno/src/cclient.cpp:242
#5  0x08050424 in ~CMessage (this=0x82f1d28) 
at /home/pablo/proyectos/lma/cuaderno/src/cclient.cpp:232
#6  0x08050153 in CClient::close() (this=0x82ec510) 
at /home/pablo/proyectos/lma/cuaderno/src/cclient.cpp:211
#7  0x0804e6a4 in main (argc=3, argv=0xbffff804) 
at /home/pablo/proyectos/lma/cuaderno/src/cuaderno.cpp:39
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAkrhiGPVnf3kOUAwRAslEAKC5TgMrD4pujjo45pqLGRFNPdnepgCgtoWU
zec2xlqU2CXC/c1wbXl8r/k=
=E+Wa
-----END PGP SIGNATURE-----
/***************************************************************************
 *   Copyright (C) 2004 by Pablo Yaggi                                     *
 *   pyaggi@aulamagna.com.ar                                               *
 *                                                                         *
 ***************************************************************************/
#include <stdio.h>
#include <cstdlib>
#include <cclient.h>
#include <vector>
#include <fstream>
CClient::CClient()
{
	mailbox=NULL;
}


CClient::~CClient()
{
	if (mailbox)
		close();	
}

const char * CClient::lastError()
{
	return error.data() ;
}
bool CClient::open (const char* url,const char* pass)
{
	mail::account::openInfo accountOpenInfo;
	accountOpenInfo.url=url;
	accountOpenInfo.pwd=pass;
	accountOpenInfo.extraString="";
	accountOpenInfo.loginCallbackObj=NULL;
	if (mailbox)
	{
		delete mailbox;
		mailbox=NULL;
	}
	mailbox=new mail::ACCOUNT;
	if (!mailbox->login(accountOpenInfo))
	{
		error=mailbox->getErrmsg();
		mailbox=NULL;
		return false;
	}
	std::cout << "yipi!!!\n";
	return (true);
}
void CStore::store(size_t messageNumber, std::string messageContents)
{
	rawData.append(messageContents);
	
}
void CStore::fixData()
{
	int pos=0,posn;
//	std::cout <<"\n******************************************************************************************\n";
	while ((posn=rawData.find(0x0a,pos))!=std::string::npos)
	{			
//		std::cout << "- " << rawData.substr(pos,posn-pos)+"\n";	
		data.push_back(rawData.substr(pos,posn-pos)+"\n");
		pos=posn+1;
	}
	if (pos<rawData.size())
		data.push_back(rawData.substr(pos));
}
bool CClient::receiveAll()
{
	mail::ACCOUNT::FolderList folderList;
	if (!mailbox->getTopLevelFolders(folderList))
	{
		error=mailbox->getErrmsg();
		return false;
	}
	
	if (!mailbox->openFolder(folderList[0],NULL))
	{
		error=mailbox->getErrmsg();
		return false;
	}
	int cant=mailbox->getFolderIndexSize();
	
	for (int c=0;c<cant;c++)
	{
		CStore st;
		mail::xenvelope e;	
		mail::mimestruct s;
		
		e=mailbox->getMessageEnvelope(c);		
		s=mailbox->getMessageStructure(c);
		
	
		class CMessage *m=new class CMessage;
		m->setEnvelope(e);
		msgs.push_back(m);
	   	
		std::vector<size_t> v;
        	v.push_back(c);
		
		mailbox->getMessageContent(v,false,false,true,(mail::ACCOUNT::Store&)st);
		st.fixData();
		
		if (m->parse(s,&st))
			msgs.push_back(m);
		else
			delete m;
	}

	return (true);

}

bool CMessage::parse(mail::mimestruct m,class CStore *c,int level)
{
	if (level==0)
	{
		if (!c->data.size())
			return false;
		parsing=0;
		while (c->data[parsing]=="\n")
			parsing++;
		
	}
	if (parsing>=c->data.size())
		return false;
	std::cout << "\n" << level << " mime_id: " << m.mime_id << " type: " << m.type <<  " subtype: " << m.subtype <<" content_id: " << m.content_id<<" content_lines: " << m.content_lines << " datasize: " << c->data.size() <<"\n";
	if (level)
	{
		if (c->data.size()>=parsing+2 && c->data[parsing].find(c->data[parsing+2])!=std::string::npos )
			parsing+=2;
		int times=1;
		if (m.messagerfc822())
			times=2;
		for (int tc=0;tc<times;tc++)
		{
			while (c->data[parsing]!="\n")
			{
				std::cout << "." << c->data[parsing];
				parsing++;
				if (c->data.size() <= parsing)
				{
					if (level==0)
						return true;
					else
						return false;
				}
			}
			parsing++;
			
		}
	}
	
	if (m.type=="MULTIPART" || m.messagerfc822())
	{
		if (level)
			parsing++;
		for (int i=0;i<m.getNumChildren();i++)
		{
	
			mail::mimestruct *ch=m.getChild(i);
			parse(*ch,c,level+1);
		
		}
	}
	else
	{
		char *fnc=tempnam("/tmp",NULL);
		std::string fn=fnc;
		free(fnc);
	
		std::ofstream out(fn.data());			
			
		for (int li=0;li<m.content_lines;li++)
		{
			out << c->data[parsing];
			parsing++;
			if (parsing>=c->data.size())
				return (false);
		}

		CAttach *a=new CAttach;
		a->file=fn;
	//	a->mime=m;
		if (m.type_parameters.exists("FILENAME"))
			a->name=m.type_parameters.get("FILENAME");
		else if (m.type_parameters.exists ("NAME"))
			a->name=m.type_parameters.get("NAME");
		else if (m.content_id!="")
			a->name=m.content_id+"."+m.subtype;
		else
			a->name=fn+"."+m.subtype;
		std::cout << a->file << " " <<a->name << "\n";
		atts.push_back(a);

		parsing++;
		if (parsing>=c->data.size())
			return true;
		if (c->data[parsing].size()>5 && c->data[parsing].find("--",3)!=std::string::npos && c->data[parsing].find ("--",3)!=c->data[parsing].find("--"))
			parsing+=2;
	}
	
	
	
	return true;
}
void CClient::close ()
{
	delete mailbox;
	int max=msgs.size();
	for (int i=0;i<max;i++)
		delete msgs.at(i);
	msgs.erase(msgs.begin(),msgs.end());
	
}
class CMessage* CClient::first()
{
	return NULL;
}
class CMessage* CClient::next()
{
	return NULL;
}
    
CMessage::CMessage ()
{
	parsing=0;
}
CMessage::~CMessage ()
{
	int max=atts.size();
	for (int i=0;i<max;i++)
		delete atts.at(i);
	
}
char * CMessage::subject()
{
	return "";
}

CAttach::~CAttach()
{
	std::cout<<file;
  	remove(file.data());
}
CAttach::CAttach()
{
}
/***************************************************************************
 *   Copyright (C) 2004 by Pablo Yaggi                                     *
 *   pyaggi@aulamagna.com.ar                                               *
 *                                                                         *
 ***************************************************************************/
#ifndef CCLIENT_H
#define CCLIENT_H
#include <string>
#include <sstream>
#include <libmail/mail.H>
#include <libmail/sync.H>
#include <vector>
#include <libmail/structure.H>
#include <libmail/envelope.H>
#include <libmail/rfcaddr.H>

/**
C++ Wrapper to libmail

@author Pablo Yaggi
*/
class CAttach {
public:
	CAttach();
	~CAttach();
	std::string file;
	std::string name;
//	mail::mimestruct mime;
};
class CMessage {
	mail::xenvelope e;	
	std::vector<class CAttach *> atts;
	unsigned int parsing;
		
public:
	void setEnvelope (mail::xenvelope xe){e=xe;}
	bool parse (mail::mimestruct xe,class CStore *,int level=0);
	CMessage ();
	~CMessage ();
	char *subject();
};
class CStore : public mail::ACCOUNT::Store {
	std::string rawData;
public:
	std::vector<std::string>data;
     	void store(size_t messageNumber, std::string messageContents);
	void fixData();
} ;
 
class CClient{
	mail::ACCOUNT *mailbox;
	std::string error;
	std::vector<class CMessage*>msgs;
	
	

public:
    CClient();
	
    ~CClient();

    const char * lastError();
    bool open (const char* url,const char *pass);
    bool receiveAll();
    void close ();

    class CMessage* first();
    class CMessage* next();    
    
};



#endif

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]