Re: Patch attempting to take care of some memory errors

Håkan Kvist <[email protected]> Sat, 24 Feb 2007 16:15:29 +0100
Newsgroups gmane.network.centericq
Message-ID <[email protected]>
And here comes the patch.

Håkan

On Sat, Feb 24, 2007 at 04:12:12PM +0100, Håkan Kvist wrote:
> Hi.
> 
> I have fiddled a little bit with the code (see attatched patch).
> 
> What I have looked at is how memory is allocated and deallocated.
> 
> I have trid to make sure that:
> 
>  * Memory allocated by malloc() is released by free()
> 
>  * Memory allocated by new[] is released by delete[]
> 
>  * Memory allocated by new is released by delete
> 
> 
> One example is:
>     auto_ptr<char> msg(strdup("free for chat"));
> 
> This might look okay at first sight, but it will call free[] when
> attempting to free the pointer, wich is not correct (since strdup is a
> C function and returned pointer must be deallocated by free()).
> 
> 
> There was one or two places where memory was accessed outside the
> allocated space.
> 
> 
> There was one or two places where uninitialized memory where read.
> 
> 
> However, there is still work to do regarding leakage of memory, but
> valgrind[1] gives a much nicer printout now :-)
> 
> 
> regards
> Håkan
> 
> [1] http://www.valgrind.org
> _______________________________________________
> Cicq mailing list
> Cicq-xGejAJT2w6wWP6gT/[email protected]
> http://mailman.linuxpl.org/mailman/listinfo/cicq
> Questions? Check the FAQ first: http://centericq.de/faq/
-- 
Håkan Kvist                  el-post: [email protected]
telefon: 0703-14 21 14       hemsida: www.df.lth.se/~hagar

_______________________________________________
Cicq mailing list
Cicq-xGejAJT2w6wWP6gT/[email protected]
http://mailman.linuxpl.org/mailman/listinfo/cicq
Questions? Check the FAQ first: http://centericq.de/faq/
centericq_mem.patch (text/plain, 22.3 KB)
diff --git a/kkconsui/src/conscommon.cc b/kkconsui/src/conscommon.cc
index f294f2b..ba3a8a2 100644
--- a/kkconsui/src/conscommon.cc
+++ b/kkconsui/src/conscommon.cc
@@ -283,7 +283,7 @@ string makebidi(const string &buf, int lpad) {
     delete us;
     delete out_us;
     delete outstring;
-    delete cbuf;
+    free (cbuf); /* allocated by c-routine */
 
     if(lpad) {
 	pad.assign(lpad-r.size(), ' ');
diff --git a/kkconsui/src/linkedlist.cc b/kkconsui/src/linkedlist.cc
index 8bb577f..c25e24c 100644
--- a/kkconsui/src/linkedlist.cc
+++ b/kkconsui/src/linkedlist.cc
@@ -47,16 +47,19 @@ void linkedlist::add(void *p) {
 }
 
 void linkedlist::insert(int n, void *p) {
-    flinkedlist *l = flist, *k = new flinkedlist;
-    
     if(n <= count) {
+        flinkedlist *l = flist, *k = new flinkedlist;
+
 	for(i = 0; i < n-1; i++, l = l->next);
 	k->data = l->data;
 	l->data = p;
 	k->next = l->next;
 	l->next = k;
 	count++;
-    } else add(p);
+    }
+    else{
+      add(p);
+    }
 }
 
 void linkedlist::remove(int n) {
@@ -89,7 +92,7 @@ void linkedlist::empty() {
     for(i = 0, l = flist; i < count && l; i++) {
 	p = l;
 	l = l->next;
-	if(freeitem) freeitem(p->data); else free(p->data);
+	if(freeitem) freeitem(p->data); else delete (p->data);
 	delete p;
     }
 
diff --git a/kkconsui/src/screenarea.cc b/kkconsui/src/screenarea.cc
index 2b5a9c8..066fc2f 100644
--- a/kkconsui/src/screenarea.cc
+++ b/kkconsui/src/screenarea.cc
@@ -80,7 +80,7 @@ void screenarea::restore(int fx1, int fy1, int fx2, int fy2) {
 
 void screenarea::freebuffer() {
     while(!buffer.empty()) {
-	delete *buffer.begin();
+	delete[] buffer.front();
 	buffer.erase(buffer.begin());
     }
 }
diff --git a/kkconsui/src/texteditor.cc b/kkconsui/src/texteditor.cc
index 7e1c3e2..4b9e323 100644
--- a/kkconsui/src/texteditor.cc
+++ b/kkconsui/src/texteditor.cc
@@ -1031,13 +1031,15 @@ bool texteditor::fix_x(bool tab) {
     if(tab) {
 	int rm = rtabmargin(true, CURCOL, CURSTRING);
 	char *p = CURSTRING;
-	
-	if(p[CURCOL-1] == ' ')
-	if(strspn(p+CURCOL, " ") >= rm-CURCOL)
-	if(CURCOL != ltabmargin(true, rm, p)) {
-	    //if(rm <= curfile->sx+x2-x1) curfile->x = rm-curfile->sx;
-	    curfile->x += rm-curfile->x;
-	}
+
+	/* if CURCOL is 0 we'll be outside of the array => not good */
+	if(CURCOL > 0)
+	  if(p[CURCOL-1] == ' ')
+	    if(strspn(p+CURCOL, " ") >= rm-CURCOL)
+	      if(CURCOL != ltabmargin(true, rm, p)) {
+		//if(rm <= curfile->sx+x2-x1) curfile->x = rm-curfile->sx;
+		curfile->x += rm-curfile->x;
+	      }
     }
 
     return osx != curfile->sx;
@@ -1081,7 +1083,7 @@ void texteditor::eddel(bool usetabs) {
 			curfile->lines->replace(CURLINE, newline);
 		    }
 
-		    delete anext;
+		    free(anext);
 		} else {
 		    if(next) nextlen = strlen(next); else nextlen = 0;
 		    char *newline = new char[nextlen+strlen(p)+1];
@@ -2136,7 +2138,7 @@ void texteditor::editfilefree(void *p) {
 	delete ef->highlines;
 	delete ef->undo;
 	delete ef->markblock;
-	delete ef->id;
+	free (ef->id) ;	 /* this is allocated by a c-routine => must deallocated with free */
 	delete ef;
     }
 }
diff --git a/kkstrtext/kkstrtext.cc b/kkstrtext/kkstrtext.cc
index 4c0f2bc..a5bad23 100644
--- a/kkstrtext/kkstrtext.cc
+++ b/kkstrtext/kkstrtext.cc
@@ -47,7 +47,8 @@ char *trimlead(char *str, char *chr) {
 }
 
 char *trimtrail(char *str, char *chr) {
-    while(strchr(chr, str[strlen(str)-1]) && strlen(str)) str[strlen(str)-1] = 0;
+    while(strlen(str) && strchr(chr, str[strlen(str)-1])) 
+      str[strlen(str)-1] = 0;
     return str;
 }
 
@@ -416,7 +417,8 @@ string justpathname(const string &fname) {
 
 void charpointerfree(void *p) {
     char *cp = (char *) p;
-    if(cp) delete cp;
+    if(cp) 
+        free (cp);
 }
 
 void nothingfree(void *p) {
diff --git a/kkstrtext/kkstrtext.h b/kkstrtext/kkstrtext.h
diff --git a/libicq2000/src/Contact.cpp b/libicq2000/src/Contact.cpp
index fa9e46c..2728f5a 100644
--- a/libicq2000/src/Contact.cpp
+++ b/libicq2000/src/Contact.cpp
@@ -89,6 +89,7 @@ namespace ICQ2000 {
     m_tag_id = 0;
     m_server_based = false;
     m_authreq = false;
+    m_authawait = false;
   }
 
   unsigned int Contact::getUIN() const { return m_uin; }
diff --git a/src/hooks/gaduhook.cc b/src/hooks/gaduhook.cc
index be863a5..9462c8a 100644
--- a/src/hooks/gaduhook.cc
+++ b/src/hooks/gaduhook.cc
@@ -126,6 +126,7 @@ void gaduhook::init() {
 void gaduhook::connect() {
     icqconf::imaccount acc = conf.getourid(proto);
     static struct gg_login_params lp;
+    /* TODO investigate this, auto_ptr will free with delete, but allocated by malloc */
     static auto_ptr<char> pass(strdup(acc.password.c_str()));
 
     memset(&lp, 0, sizeof(lp));
@@ -142,6 +143,7 @@ void gaduhook::connect() {
 	lp.password = pass.get();
 	lp.async = 1;
 
+	/* TODO investigate this, auto_ptr will free with delete, but allocated by malloc */
 	static auto_ptr<char> descr(strdup(rusconv("kw", conf.getawaymsg(proto)).c_str()));
 
 	lp.status_descr = descr.get();
@@ -601,6 +603,7 @@ void gaduhook::userlistsend() {
     }
 
     auto_ptr<uin_t> cuins(new uin_t[uins.size()]);
+    /* TODO: allocated with new[], but will be freed by delete */
     auto_ptr<char> ctypes(new char[uins.size()]);
 
     for(vector<uin_t>::const_iterator iu = uins.begin(); iu != uins.end(); ++iu) {
diff --git a/src/hooks/icqhook.cc b/src/hooks/icqhook.cc
index b769eec..06263a1 100644
--- a/src/hooks/icqhook.cc
+++ b/src/hooks/icqhook.cc
@@ -1357,7 +1357,10 @@ void icqhook::socket_cb(SocketEvent *ev) {
 }
 
 void icqhook::want_auto_resp_cb(ICQMessageEvent *ev) {
-    char buf[128];
+    /* TODO: something should probably be logged here, but
+     * logging an UNITIALIZED BUFFER seems pretty stupid to me
+     */
+    /* char buf[128]; */
     string ident;
     imcontact cont = imcontact(ev->getSenderUIN(), icq);
     icqcontact *c = clist.get(cont);
@@ -1365,7 +1368,7 @@ void icqhook::want_auto_resp_cb(ICQMessageEvent *ev) {
     ident = cont.totext();
     if(c) ident += " (" + c->getdispnick() + ")";
 
-    logger.putmessage(buf);
+    /* logger.putmessage(buf); */
     ev->setAwayMessage(rusconv("kw", conf.getawaymsg(icq)));
 }
 
diff --git a/src/hooks/jabberhook.cc b/src/hooks/jabberhook.cc
index 2664889..613b402 100644
--- a/src/hooks/jabberhook.cc
+++ b/src/hooks/jabberhook.cc
@@ -112,15 +112,21 @@ void jabberhook::connect() {
 
     log(logConnecting);
 
-    auto_ptr<char> cjid(strdup(jid.c_str()));
-    auto_ptr<char> cpass(strdup(acc.password.c_str()));
-		auto_ptr<char> cserver(strdup(acc.server.c_str()));
+    /* TODO: is there really a need for COPYING these char-arrays
+     * shoudn't it be possible to feed the c_str() directly into jab_new
+     * and get rid of the copying ?
+     */
+    char *cjid = strdup(jid.c_str());
+    char *cpass = strdup(acc.password.c_str());
+    char *cserver = strdup(acc.server.c_str());
 
     regmode = flogged = fonline = false;
 
-    if(jc) delete jc;
+    if(jc){
+      jab_delete(jc);
+    }
 
-    jc = jab_new(cjid.get(), cpass.get(), cserver.get(), acc.port,
+    jc = jab_new(cjid, cpass, cserver, acc.port,
 	acc.additional["ssl"] == "1" ? 1 : 0);
 
     jab_packet_handler(jc, &packethandler);
@@ -135,6 +141,10 @@ void jabberhook::connect() {
 	statehandler(0, -1);
 	jab_start(jc);
     }
+
+    free (cjid);
+    free (cpass);
+    free (cserver);
 }
 
 void jabberhook::disconnect() {
@@ -146,7 +156,7 @@ void jabberhook::disconnect() {
 
     // close the connection
     jab_stop(jc);
-    delete(jc);
+    jab_delete(jc);
     jc = 0;
 }
 
@@ -248,18 +258,18 @@ bool jabberhook::send(const imevent &ev) {
 
 	} else if(ev.gettype() == imevent::authorization) {
 	    const imauthorization *m = static_cast<const imauthorization *> (&ev);
-	    auto_ptr<char> cjid(strdup(jidnormalize(ev.getcontact().nickname).c_str()));
+	    char *cjid = strdup(jidnormalize(ev.getcontact().nickname).c_str());
 	    xmlnode x = 0;
 
 	    switch(m->getauthtype()) {
 		case imauthorization::Granted:
-		    x = jutil_presnew(JPACKET__SUBSCRIBED, cjid.get(), 0);
+		    x = jutil_presnew(JPACKET__SUBSCRIBED, cjid, 0);
 		    break;
 		case imauthorization::Rejected:
-		    x = jutil_presnew(JPACKET__UNSUBSCRIBED, cjid.get(), 0);
+		    x = jutil_presnew(JPACKET__UNSUBSCRIBED, cjid, 0);
 		    break;
 		case imauthorization::Request:
-		    x = jutil_presnew(JPACKET__SUBSCRIBE, cjid.get(), 0);
+		    x = jutil_presnew(JPACKET__SUBSCRIBE, cjid, 0);
 		    break;
 	    }
 
@@ -268,6 +278,8 @@ bool jabberhook::send(const imevent &ev) {
 		xmlnode_free(x);
 	    }
 
+	    free(cjid);
+
 	    return true;
 	}
 
@@ -280,10 +292,11 @@ bool jabberhook::send(const imevent &ev) {
 	}
 #endif
 
-	auto_ptr<char> cjid(strdup(jidnormalize(c->getdesc().nickname).c_str()));
-	auto_ptr<char> ctext(strdup(text.c_str()));
+	/* TODO: do these really needs to be copied? */
+	char *cjid = strdup(jidnormalize(c->getdesc().nickname).c_str());
+	char *ctext = strdup(text.c_str());
 
-	xmlnode x = jutil_msgnew(TMSG_CHAT, cjid.get(), 0, ctext.get());
+	xmlnode x = jutil_msgnew(TMSG_CHAT, cjid, 0, ctext);
 
 	if(ischannel(c)) {
 	    xmlnode_put_attrib(x, "type", "groupchat");
@@ -300,6 +313,9 @@ bool jabberhook::send(const imevent &ev) {
 	jab_send(jc, x);
 	xmlnode_free(x);
 
+	free (cjid);
+	free (ctext);
+
 	return true;
     }
 
@@ -323,30 +339,31 @@ void jabberhook::sendnewuser(const imcontact &ic, bool report) {
 	return;
 
     if(!ischannel(ic)) {
-	auto_ptr<char> cjid(strdup(jidnormalize(ic.nickname).c_str()));
-	if(roster.find(cjid.get()) != roster.end()) {
+	char *cjid = strdup(jidnormalize(ic.nickname).c_str());
+	if(roster.find(cjid) != roster.end()) {
+	    free (cjid);
 	    return;
 	}
 
 	if(report) log(logContactAdd, ic.nickname.c_str());
 
-	x = jutil_presnew(JPACKET__SUBSCRIBE, cjid.get(), 0);
+	x = jutil_presnew(JPACKET__SUBSCRIBE, cjid, 0);
 	jab_send(jc, x);
 	xmlnode_free(x);
 
 	x = jutil_iqnew(JPACKET__SET, NS_ROSTER);
 	y = xmlnode_get_tag(x, "query");
 	z = xmlnode_insert_tag(y, "item");
-	xmlnode_put_attrib(z, "jid", cjid.get());
+	xmlnode_put_attrib(z, "jid", cjid);
 
-	roster[cjid.get()] = "";
+	roster[cjid] = "";
 
 	if(c = clist.get(ic)) {
 	    vector<icqgroup>::const_iterator ig = find(groups.begin(), groups.end(), c->getgroupid());
 	    if(ig != groups.end()) {
 		z = xmlnode_insert_tag(z, "group");
 		xmlnode_insert_cdata(z, ig->getname().c_str(), (unsigned) -1);
-		roster[cjid.get()] = ig->getname();
+		roster[cjid] = ig->getname();
 	    }
 	}
 
@@ -367,7 +384,8 @@ void jabberhook::sendnewuser(const imcontact &ic, bool report) {
 	}
 
 	requestinfo(c);
-
+	
+	free (cjid);
     } else {
 	if(c = clist.get(ic)) {
 	    cname = ic.nickname.substr(1);
@@ -375,12 +393,15 @@ void jabberhook::sendnewuser(const imcontact &ic, bool report) {
 	    if(!cname.empty()) {
 		cname += "/" + conf.getourid(proto).nickname;
 
-		auto_ptr<char> ccname(strdup(cname.c_str()));
-		auto_ptr<char> ourjid(strdup(getourjid().c_str()));
+		char *ccname = strdup(cname.c_str());
+		char *ourjid = strdup(getourjid().c_str());
 
-		x = jutil_presnew(JPACKET__UNKNOWN, ccname.get(), 0);
+		x = jutil_presnew(JPACKET__UNKNOWN, ccname, 0);
 		xmlnode_insert_cdata(xmlnode_insert_tag(x, "status"), "Online", (unsigned) -1);
 
+		free (ccname);
+		free (ourjid);
+
 		jab_send(jc, x);
 		xmlnode_free(x);
 	    }
@@ -397,18 +418,18 @@ void jabberhook::removeuser(const imcontact &ic, bool report) {
 	return;
 
     if(!ischannel(ic)) {
-	auto_ptr<char> cjid(strdup(jidnormalize(ic.nickname).c_str()));
+	char *cjid = strdup(jidnormalize(ic.nickname).c_str());
 
-	map<string, string>::iterator ir = roster.find(cjid.get());
+	map<string, string>::iterator ir = roster.find(cjid);
 
 	if(ir == roster.end()) return;
 	    else roster.erase(ir);
 
-	if(find(agents.begin(), agents.end(), cjid.get()) != agents.end()) {
-	    if(report) face.log(_("+ [jab] unregistering from the %s agent"), cjid.get());
+	if(find(agents.begin(), agents.end(), cjid) != agents.end()) {
+	    if(report) face.log(_("+ [jab] unregistering from the %s agent"), cjid);
 
 	    x = jutil_iqnew(JPACKET__SET, NS_REGISTER);
-	    xmlnode_put_attrib(x, "to", cjid.get());
+	    xmlnode_put_attrib(x, "to", cjid);
 	    y = xmlnode_get_tag(x, "query");
 	    xmlnode_insert_tag(y, "remove");
 	    jab_send(jc, x);
@@ -418,30 +439,34 @@ void jabberhook::removeuser(const imcontact &ic, bool report) {
 
 	if(report) log(logContactRemove, ic.nickname.c_str());
 
-	x = jutil_presnew(JPACKET__UNSUBSCRIBE, cjid.get(), 0);
+	x = jutil_presnew(JPACKET__UNSUBSCRIBE, cjid, 0);
 	jab_send(jc, x);
 	xmlnode_free(x);
 
 	x = jutil_iqnew(JPACKET__SET, NS_ROSTER);
 	y = xmlnode_get_tag(x, "query");
 	z = xmlnode_insert_tag(y, "item");
-	xmlnode_put_attrib(z, "jid", cjid.get());
+	xmlnode_put_attrib(z, "jid", cjid);
 	xmlnode_put_attrib(z, "subscription", "remove");
 	jab_send(jc, x);
 	xmlnode_free(x);
 
+	free (cjid);
+
     } else {
 	if(c = clist.get(ic)) {
 	    cname = ic.nickname.substr(1);
 
 	    if(!cname.empty()) {
 		cname += "/" + conf.getourid(proto).nickname;
-		auto_ptr<char> ccname(strdup(cname.c_str()));
-		x = jutil_presnew(JPACKET__UNKNOWN, ccname.get(), 0);
+		char *ccname = strdup(cname.c_str());
+		x = jutil_presnew(JPACKET__UNKNOWN, ccname, 0);
 		xmlnode_put_attrib(x, "type", "unavailable");
 		jab_send(jc, x);
 		xmlnode_free(x);
 
+		free(ccname);
+
 		map<string, vector<string> >::iterator icm = chatmembers.find(ic.nickname);
 		if(icm != chatmembers.end()) chatmembers.erase(icm);
 	    }
@@ -485,12 +510,13 @@ void jabberhook::requestinfo(const imcontact &ic) {
 	    }
 
 	} else {
-	    auto_ptr<char> cjid(strdup(jidnormalize(ic.nickname).c_str()));
+	    char *cjid = strdup(jidnormalize(ic.nickname).c_str());
 	    xmlnode x = jutil_iqnew(JPACKET__GET, NS_VCARD);
-	    xmlnode_put_attrib(x, "to", cjid.get());
+	    xmlnode_put_attrib(x, "to", cjid);
 	    xmlnode_put_attrib(x, "id", "VCARDreq");
 	    jab_send(jc, x);
 	    xmlnode_free(x);
+	    free (cjid);
 
 	}
     }
@@ -529,11 +555,16 @@ const string &serv, string &err) {
 
     regmode = true;
 
-    auto_ptr<char> cjid(strdup(jid.c_str()));
-    auto_ptr<char> cpass(strdup(pass.c_str()));
-    auto_ptr<char> cserver(strdup(serv.c_str()));
+    /* TODO: do these really need to be copied ??? */
+    char *cjid = strdup(jid.c_str());
+    char *cpass = strdup(pass.c_str());
+    char *cserver = strdup(serv.c_str());
+
+    jc = jab_new(cjid, cpass, cserver, port, 0);
 
-    jc = jab_new(cjid.get(), cpass.get(), cserver.get(), port, 0);
+    free (cjid);
+    free (cpass);
+    free (cserver);
 
     if(!jc->user) {
 	err = _("Wrong nickname given, cannot register");
@@ -982,10 +1013,11 @@ void jabberhook::postlogin() {
 }
 
 void jabberhook::conferencecreate(const imcontact &confid, const vector<imcontact> &lst) {
-    auto_ptr<char> jcid(strdup(confid.nickname.substr(1).c_str()));
-    xmlnode x = jutil_presnew(JPACKET__UNKNOWN, jcid.get(), 0);
+    char *jcid = strdup(confid.nickname.substr(1).c_str());
+    xmlnode x = jutil_presnew(JPACKET__UNKNOWN, jcid, 0);
     jab_send(jc, x);
     xmlnode_free(x);
+    free (jcid);
 }
 
 void jabberhook::vcput(xmlnode x, const string &name, const string &val) {
@@ -1128,13 +1160,13 @@ void jabberhook::updatecontact(icqcontact *c) {
     xmlnode x, y;
 
     if(logged()) {
-	auto_ptr<char> cjid(strdup(jidnormalize(c->getdesc().nickname).c_str()));
-	auto_ptr<char> cname(strdup(rusconv("ku", c->getdispnick()).c_str()));
+	char *cjid = strdup(jidnormalize(c->getdesc().nickname).c_str());
+        char *cname = strdup(rusconv("ku", c->getdispnick()).c_str());
 
 	x = jutil_iqnew(JPACKET__SET, NS_ROSTER);
 	y = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "item");
-	xmlnode_put_attrib(y, "jid", cjid.get());
-	xmlnode_put_attrib(y, "name", cname.get());
+	xmlnode_put_attrib(y, "jid", cjid);
+	xmlnode_put_attrib(y, "name", cname);
 
 	vector<icqgroup>::const_iterator ig = find(groups.begin(), groups.end(), c->getgroupid());
 	if(ig != groups.end()) {
@@ -1144,6 +1176,8 @@ void jabberhook::updatecontact(icqcontact *c) {
 
 	jab_send(jc, x);
 	xmlnode_free(x);
+	free (cjid);
+	free (cname);
     }
 }
 
@@ -1257,12 +1291,13 @@ void jabberhook::gotvcard(const imcontact &ic, xmlnode v) {
 }
 
 void jabberhook::requestversion(const imcontact &ic) {
-    auto_ptr<char> cjid(strdup(jidnormalize(ic.nickname).c_str()));
+    char *cjid = strdup(jidnormalize(ic.nickname).c_str());
     xmlnode x = jutil_iqnew(JPACKET__GET, NS_VERSION);
-    xmlnode_put_attrib(x, "to", cjid.get());
+    xmlnode_put_attrib(x, "to", cjid);
     xmlnode_put_attrib(x, "id", "versionreq");
     jab_send(jc, x);
     xmlnode_free(x);
+    free (cjid);
 }
 
 void jabberhook::gotversion(const imcontact &ic, xmlnode x) {
@@ -1622,18 +1657,20 @@ void jabberhook::packethandler(jconn conn, jpacket packet) {
 			imauthorization::Request, _("The user wants to subscribe to your network presence updates")));
 
 		} else {
-		    auto_ptr<char> cfrom(strdup(from.c_str()));
-		    x = jutil_presnew(JPACKET__SUBSCRIBED, cfrom.get(), 0);
+		    char *cfrom = strdup(from.c_str());
+		    x = jutil_presnew(JPACKET__SUBSCRIBED, cfrom, 0);
 		    jab_send(jhook.jc, x);
 		    xmlnode_free(x);
+		    free (cfrom);
 		}
 
 	    } else if(type == "unsubscribe") {
-		auto_ptr<char> cfrom(strdup(from.c_str()));
-		x = jutil_presnew(JPACKET__UNSUBSCRIBED, cfrom.get(), 0);
+		char *cfrom = strdup(from.c_str());
+		x = jutil_presnew(JPACKET__UNSUBSCRIBED, cfrom, 0);
 		jab_send(jhook.jc, x);
 		xmlnode_free(x);
 		em.store(imnotification(ic, _("The user has removed you from his contact list (unsubscribed you, using the Jabber language)")));
+		free (cfrom);
 
 	    }
 
diff --git a/src/hooks/yahoohook.cc b/src/hooks/yahoohook.cc
index a23b1ab..eae0421 100644
--- a/src/hooks/yahoohook.cc
+++ b/src/hooks/yahoohook.cc
@@ -264,8 +264,10 @@ void yahoohook::exectimers() {
     for(it = tobedone.begin(); it != tobedone.end(); ++it) {
 	switch(it->first) {
 	    case tbdConfLogon:
-		auto_ptr<char> room(strdup(it->second.c_str()));
-		yahoo_conference_logon(cid, 0, getmembers(it->second), room.get());
+	      /* TODO: investigate if copy is really needed here */
+		char *room = strdup(it->second.c_str());
+		yahoo_conference_logon(cid, 0, getmembers(it->second), room);
+		free (room);
 		break;
 	}
     }
@@ -453,15 +455,18 @@ void yahoohook::setautostatus(imstatus st) {
 	    logger.putourstatus(proto, getstatus(), ourstatus = st);
 
 	    if(st == freeforchat) {
-		auto_ptr<char> msg(strdup("free for chat"));
-		yahoo_set_away(cid, (yahoo_status) stat2int[st], msg.get(), 0);
+               /* TODO copy should not be needed here ?*/
+		char *msg = strdup("free for chat");
+		yahoo_set_away(cid, (yahoo_status) stat2int[st], msg, 0);
+		free (msg);
 
 	    } else if(st != away) {
 		yahoo_set_away(cid, (yahoo_status) stat2int[st], 0, 0);
 
 	    } else {
-		auto_ptr<char> msg(strdup(rusconv("ku", conf.getawaymsg(proto)).c_str()));
-		yahoo_set_away(cid, (yahoo_status) stat2int[st], msg.get(), 1);
+		char *msg = strdup(rusconv("ku", conf.getawaymsg(proto)).c_str());
+		yahoo_set_away(cid, (yahoo_status) stat2int[st], msg, 1);
+		free (msg);
 
 	    }
 	}
diff --git a/src/icqcontact.cc b/src/icqcontact.cc
index 187fb0b..29a1654 100644
--- a/src/icqcontact.cc
+++ b/src/icqcontact.cc
@@ -160,9 +160,9 @@ void icqcontact::save() {
 
 	    f.open(infoname.c_str());
 	    if(f.is_open()) {
-		string options;
+      	        string options(""); /* set initial value */
 		if(binfo.requiresauth) options += "a";
-		if(binfo.authawait) options += "w";
+		if(binfo.authawait) options += "w";   
 		if(usepgpkey) options += "p";
 
 		f << nick << endl <<
diff --git a/src/icqdialogs.cc b/src/icqdialogs.cc
diff --git a/src/icqface.cc b/src/icqface.cc
index 0e4b12b..8d67763 100644
--- a/src/icqface.cc
+++ b/src/icqface.cc
@@ -2316,11 +2316,13 @@ bool icqface::eventedit(imevent &ev) {
 	editor.open();
 	r = editdone;
 
-	auto_ptr<char> p(editor.save("\r\n"));
-	*m = immessage(ev.getcontact(), imevent::outgoing, p.get());
+	/* TODO, should we relly use a pointer here ? */
+	char *p = editor.save("\r\n");
+	*m = immessage(ev.getcontact(), imevent::outgoing, p);
 
 	if(c = clist.get(ev.getcontact()))
-	    c->setpostponed(r ? "" : p.get());
+	    c->setpostponed(r ? "" : p);
+	free (p);
 
     } else if(ev.gettype() == imevent::xml) {
 	editor.setcoords(sizeWArea.x1+2, sizeWArea.y1+3, sizeWArea.x2, sizeWArea.y2);
@@ -2333,17 +2335,20 @@ bool icqface::eventedit(imevent &ev) {
 	    editor.open();
 	    r = editdone;
 
-	    auto_ptr<char> p(editor.save("\r\n"));
-	    m->setfield("text", p.get());
+	    char *p = editor.save("\r\n");
+	    m->setfield("text", p);
 
 	    if(r)
-	    if(ev.getcontact().pname == livejournal)
-	    if(!setljparams(m))
-		continue;
+	      if(ev.getcontact().pname == livejournal)
+		if(!setljparams(m)){
+		  free(p);
+		  continue;
+		}
 
 	    if(c = clist.get(ev.getcontact()))
-		c->setpostponed(r ? "" : p.get());
+		c->setpostponed(r ? "" : p);
 
+	    free(p);
 	    break;
 	}
 
@@ -2369,8 +2374,9 @@ bool icqface::eventedit(imevent &ev) {
 
 	    r = editdone;
 
-	    auto_ptr<char> p(editor.save("\r\n"));
-	    *m = imurl(ev.getcontact(), imevent::outgoing, url, p.get());
+	    char *p = editor.save("\r\n");
+	    *m = imurl(ev.getcontact(), imevent::outgoing, url, p);
+	    free (p);
 	}
 
     } else if(ev.gettype() == imevent::sms) {
@@ -2395,9 +2401,10 @@ bool icqface::eventedit(imevent &ev) {
 	    editor.setcoords(sizeWArea.x1+2, sizeWArea.y1+3, sizeWArea.x2, sizeWArea.y2);
 	    editor.load(msg = m->getmessage(), "");
 	    editor.open();
-	    auto_ptr<char> p(editor.save("\r\n"));
-	    *m = imauthorization(ev.getcontact(), imevent::outgoing, imauthorization::Request, p.get());
+	    char *p = editor.save("\r\n");
+	    *m = imauthorization(ev.getcontact(), imevent::outgoing, imauthorization::Request, p);
 	    r = editdone;
+	    free(p);
 	} else {
 	    *m = imauthorization(ev.getcontact(), imevent::outgoing, imauthorization::Request, "");
 	    r = true;
@@ -2579,7 +2586,7 @@ void icqface::renderchathistory() {
     }
 
     while(events.size() > chatlines) {
-	delete *events.begin();
+	delete events.front();
 	events.erase(events.begin());
     }
 
@@ -3406,7 +3413,7 @@ int icqface::editmsgkeys(texteditor &e, int k) {
     if(k == '\r' && conf.getentersends(face.passinfo.pname)) {
 	p = e.save("");
 	face.editdone = strlen(p);
-	delete p;
+	free(p);
 	if(face.editdone) return -1; else return 0;
     }
 
@@ -3414,7 +3421,7 @@ int icqface::editmsgkeys(texteditor &e, int k) {
 	case key_send_message:
 	    p = e.save("");
 	    face.editdone = strlen(p);
-	    delete p;
+	    free(p);
 	    if(face.editdone) return -1; else break;
 	case key_multiple_recipients:
 	    face.multicontacts("");