Mercurial > pidgin
changeset 18891:7db556e97dd1
Make msim_escape_or_unescape() take a const gchar *, and duplicate it itself
so that it is not freed. Makes code clearer.
author | Jeffrey Connelly <jaconnel@calpoly.edu> |
---|---|
date | Sat, 11 Aug 2007 04:38:52 +0000 |
parents | 00499df91ffe |
children | 138e9be2f917 |
files | libpurple/protocols/myspace/message.c |
diffstat | 1 files changed, 9 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/myspace/message.c Sat Aug 11 04:34:20 2007 +0000 +++ b/libpurple/protocols/myspace/message.c Sat Aug 11 04:38:52 2007 +0000 @@ -22,7 +22,7 @@ #include "myspace.h" #include "message.h" -static gchar *msim_unescape_or_escape(gchar *msg, gboolean escape); +static gchar *msim_unescape_or_escape(const gchar *msg, gboolean escape); static void msim_msg_free_element(gpointer data, gpointer user_data); static void msim_msg_debug_string_element(gpointer data, gpointer user_data); static gchar *msim_msg_pack_using(MsimMessage *msg, GFunc gf, const gchar *sep, const gchar *begin, const gchar *end); @@ -44,18 +44,21 @@ /** * Unescape or escape a protocol message. * - * @param msg The message to be unescaped or escaped. WILL BE FREED. + * @param msg The message to be unescaped or escaped. * @param escape TRUE to escape, FALSE to unescape. * * @return The unescaped or escaped message. Caller must g_free(). */ static gchar * -msim_unescape_or_escape(gchar *msg, gboolean escape) +msim_unescape_or_escape(const gchar *original_msg, gboolean escape) { - gchar *tmp; + gchar *tmp, *msg; guint i; struct MSIM_ESCAPE_REPLACEMENT* replacement; + /* Freed in loop below. */ + msg = g_strdup(original_msg); + /* Replace each code in msim_replacement_code with * corresponding entry in msim_replacement_text. */ for (i = 0; (replacement = &msim_escape_replacements[i]); ++i) { @@ -87,13 +90,13 @@ gchar * msim_escape(const gchar *msg) { - return msim_unescape_or_escape(g_strdup(msg), TRUE); + return msim_unescape_or_escape(msg, TRUE); } gchar * msim_unescape(const gchar *msg) { - return msim_unescape_or_escape(g_strdup(msg), FALSE); + return msim_unescape_or_escape(msg, FALSE); } /** Create a new MsimMessage.