From 3cf8a1a8e2f9c5aad66f22f9c59b96d2d617a3f3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Thu, 29 Apr 2010 22:12:06 +0000 Subject: [PATCH] xmpp_fetch_mortuary_backend(): copy the string over so we can use it later and free it. else we will free a non-malloced pointer or loose that buffer before we want to use it. Btw, theres no need for specifying generic_free_handler, thats default. --- citadel/modules/xmpp/xmpp_presence.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/citadel/modules/xmpp/xmpp_presence.c b/citadel/modules/xmpp/xmpp_presence.c index c2c1af5cf..a57c12466 100644 --- a/citadel/modules/xmpp/xmpp_presence.c +++ b/citadel/modules/xmpp/xmpp_presence.c @@ -207,6 +207,7 @@ void xmpp_fetch_mortuary_backend(long msgnum, void *userdata) { const char *ptr = NULL; const char *endptr = NULL; int in_body = 0; + int len; char buf[256]; msg = CtdlFetchMessage(msgnum, 1); @@ -218,9 +219,12 @@ void xmpp_fetch_mortuary_backend(long msgnum, void *userdata) { ptr = msg->cm_fields['M']; endptr = ptr + strlen(ptr); // only do strlen once :) - while (ptr = memreadline(ptr, buf, (sizeof buf - 2)), ((ptr < endptr) && (*ptr != 0)) ) { + while (ptr = memreadlinelen(ptr, buf, (sizeof buf - 2), &len), ((ptr < endptr) && (*ptr != 0)) ) { if (in_body) { - Put(mortuary, buf, strlen(buf), buf, generic_free_handler); + char *pch; + pch = malloc(len + 1); + memcpy(pch, buf, len + 1); + Put(mortuary, pch, len, pch, NULL); } if (IsEmptyStr(buf)) in_body = 1; } -- 2.30.2