Am Freitag, 23. März 2007 09:33 schrieb Alexander Dahl: > > Please check the patch for errors or other things I that could be done > > better. > > licq crashed when closing: > > Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so. > 1". > [Thread debugging using libthread_db enabled] > [New Thread -1212832080 (LWP 28978)] > [KCrash handler] > #6 0xb7bd6a09 in free () from /lib/tls/i686/cmov/libc.so.6 > #7 0x080e1396 in CUserHistory::SetFile () > #8 0x6d754e0a in ?? () > #9 0x00000000 in ?? ()
Oh....that is the same mistake I made with the impulsd....variable not
initialized properly.
The new patch version in the attachment should solve the problem and fix the
memory leak when setting the encoding.
Stefan
--
____
/ \
/ ^ ^ \ Stefan Haun
I \/ I [EMAIL PROTECTED]
II II http://www.tuxathome.de
II II
I /\/\ I
Index: /home/tux/eclipse-workspace/Licq_Main/include/licq_history.h
===================================================================
--- /home/tux/eclipse-workspace/Licq_Main/include/licq_history.h (revision 4878)
+++ /home/tux/eclipse-workspace/Licq_Main/include/licq_history.h (working copy)
@@ -15,6 +15,7 @@
~CUserHistory();
void SetFile(const char *, unsigned long);
void SetFile(const char *, const char *, unsigned long);
+ void SetEncoding(const char*);
void Append(const char *);
bool Load(HistoryList &);
static void Clear(HistoryList &);
@@ -21,9 +22,16 @@
void Save(const char *);
const char *Description() { return m_szDescription; }
const char *FileName() { return m_szFileName; }
+ const char *Encoding() { return m_szEncoding; }
protected:
char *m_szFileName;
char *m_szDescription;
+ /*
+ * The history is stored using UTF-8. However, the user might
+ * have another encoding set. This property stores the encoding
+ * which is used by the licq backend.
+ */
+ char *m_szEncoding;
};
#endif
Index: /home/tux/eclipse-workspace/Licq_Main/include/licq_user.h
===================================================================
--- /home/tux/eclipse-workspace/Licq_Main/include/licq_user.h (revision 4878)
+++ /home/tux/eclipse-workspace/Licq_Main/include/licq_user.h (working copy)
@@ -708,7 +708,7 @@
void EventPush(CUserEvent *);
void WriteToHistory(const char *);
void SetHistoryFile(const char *);
- int GetHistory(HistoryList &h) { return m_fHistory.Load(h); }
+ int GetHistory(HistoryList &h);
static void ClearHistory(HistoryList &h) { CUserHistory::Clear(h); }
void SaveHistory(const char *buf) { m_fHistory.Save(buf); }
const char *HistoryName() { return m_fHistory.Description(); }
Index: /home/tux/eclipse-workspace/Licq_Main/src/history.cpp
===================================================================
--- /home/tux/eclipse-workspace/Licq_Main/src/history.cpp (revision 4878)
+++ /home/tux/eclipse-workspace/Licq_Main/src/history.cpp (working copy)
@@ -32,6 +32,7 @@
#include "licq_message.h"
#include "licq_icq.h"
#include "licq_user.h"
+#include "licq_translate.h"
//A sleazy hack
extern char *PPIDSTRING(unsigned long);
@@ -39,9 +40,8 @@
#define MAX_HISTORY_MSG_SIZE 8192
CUserHistory::CUserHistory()
-{
- m_szFileName = m_szDescription = NULL;
-}
+ : m_szFileName(NULL), m_szDescription(NULL), m_szEncoding(NULL)
+{}
CUserHistory::~CUserHistory()
{
@@ -47,6 +47,7 @@
{
if (m_szFileName != NULL) free(m_szFileName);
if (m_szDescription != NULL) free(m_szDescription);
+ if (m_szEncoding != NULL) free(m_szEncoding);
}
//---SetFile-------------------------------------------------------------------
@@ -100,6 +101,13 @@
}
}
+void CUserHistory::SetEncoding(const char* _encoding)
+{
+ if (m_szEncoding != NULL)
+ free(m_szEncoding);
+
+ m_szEncoding = strdup(_encoding);
+}
/* szResult[0] != ':' doubles to check if strlen(szResult) < 1 */
@@ -110,6 +118,11 @@
szResult[strlen(szResult) - 1] = '\0'; \
}
+/*
+ * At the end of this macro, the message is converted from
+ * UTF-8 to the users current encoding. This is the reverse
+ * step to the encoding in ICQUser::WriteToHistory(const char*)
+ */
#define GET_VALID_LINES \
{ \
unsigned short nPos = 0; \
@@ -131,6 +144,14 @@
} \
if (nPos > 0 && szMsg[nPos - 1] == '\n') \
szMsg[nPos - 1] = '\0'; \
+ if (Encoding() != NULL) { \
+ char* _utfMsg = strdup(szMsg); \
+ char* _localMsg = strdup(szMsg); \
+ _localMsg = gTranslator.FromUnicode(_utfMsg, m_szEncoding); \
+ strncpy(szMsg, _localMsg, MAX_HISTORY_MSG_SIZE + 1); \
+ free(_utfMsg); \
+ free(_localMsg); \
+ } \
}
#define SKIP_VALID_LINES \
Index: /home/tux/eclipse-workspace/Licq_Main/src/user.cpp
===================================================================
--- /home/tux/eclipse-workspace/Licq_Main/src/user.cpp (revision 4878)
+++ /home/tux/eclipse-workspace/Licq_Main/src/user.cpp (working copy)
@@ -38,6 +38,7 @@
#include "licq_packets.h"
#include "licq_icqd.h"
#include "licq_socket.h"
+#include "licq_translate.h"
#include "support.h"
#include "pthread_rdwr.h"
@@ -2562,6 +2563,16 @@
SaveLicqInfo();
}
+/// Load the users history
+int ICQUser::GetHistory(HistoryList &h)
+{
+ /*
+ * Set the encoding in case it has been changed.
+ */
+ m_fHistory.SetEncoding(UserEncoding());
+
+ return m_fHistory.Load(h);
+}
void ICQUser::SetIpPort(unsigned long _nIp, unsigned short _nPort)
{
@@ -3625,7 +3636,27 @@
void ICQUser::WriteToHistory(const char *_szText)
{
- m_fHistory.Append(_szText);
+ /* Encode to UTF-8
+ *
+ * This has been added to make assumptions about the encoding used
+ * in the history file possible. Each history is encoded in UTF-8,
+ * independent from the user's encoding.
+ */
+
+ // these are needed as char* by the encoding routine
+ char* _encoding = strdup(UserEncoding());
+ char* _text = strdup(_szText);
+
+ // encode to UTF-8
+ char* _utfText = gTranslator.ToUnicode(_text, _encoding);
+
+ // append to history
+ m_fHistory.Append(_utfText);
+
+ // delete auxiliary variables
+ free(_encoding);
+ free(_text);
+ free(_utfText);
}
pgpgdHqIHK7dt.pgp
Description: PGP signature
