From 19c51789967a2f63da033e60f6ef08848b9cd144 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Tue, 24 Jan 2017 22:19:50 +0100 Subject: Prevent a memory leak during the processing of the SASL response. We also get rid of an allocation in the process of doing so. --- src/irc/core/sasl.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/irc/core/sasl.c b/src/irc/core/sasl.c index 1021bea4..635b7dfb 100644 --- a/src/irc/core/sasl.c +++ b/src/irc/core/sasl.c @@ -174,10 +174,16 @@ static gboolean sasl_reassemble_incoming(IRC_SERVER_REC *server, const char *fra *decoded = g_string_new_len("", 0); } else { gsize dec_len; - gchar *tmp; - - tmp = (gchar *) g_base64_decode(enc_req->str, &dec_len); - *decoded = g_string_new_len(tmp, dec_len); + gint state = 0; + guint save = 0; + + /* Since we're not going to use the enc_req GString anymore we + * can perform the decoding in place. */ + dec_len = g_base64_decode_step(enc_req->str, enc_req->len, + (guchar *)enc_req->str, + &state, &save); + /* A copy of the data is made when the GString is created. */ + *decoded = g_string_new_len(enc_req->str, dec_len); } g_string_free(enc_req, TRUE); -- cgit v1.2.3