Fix memory leak

This commit is contained in:
mjentsch 2015-01-02 19:55:43 +01:00
parent 817ab52aae
commit f834b7cd38
3 changed files with 8 additions and 7 deletions

View file

@ -457,9 +457,9 @@ void chat_add_all_users (PurpleConversation *pc, struct tgl_chat *chat) {
}
/**
* This function generates a png image to visulize the sha1 key from an encrypted chat.
* This function generates a png image to visualize the sha1 key from an encrypted chat.
*/
int generate_ident_icon (unsigned char* sha1_key)
int generate_ident_icon (struct tgl_state *TLS, unsigned char* sha1_key)
{
int colors[4] = {
0xffffff,
@ -469,6 +469,7 @@ int generate_ident_icon (unsigned char* sha1_key)
};
unsigned img_size = 160;
unsigned char* image = (unsigned char*)malloc (img_size * img_size * 4);
assert (image);
unsigned x, y, i, j, idx = 0;
int bitpointer = 0;
for (y = 0; y < 8; y++)
@ -502,9 +503,9 @@ int generate_ident_icon (unsigned char* sha1_key)
int imgStoreId = -1;
if(!error)
{
imgStoreId = purple_imgstore_add_with_id(g_memdup(png, pngsize), pngsize, NULL);
imgStoreId = purple_imgstore_add_with_id (png, pngsize, NULL);
used_images_add ((connection_data*)TLS->ev_base, imgStoreId);
}
g_free(image);
g_free(png);
return imgStoreId;
}

View file

@ -32,6 +32,6 @@ PurpleConversation *chat_show (PurpleConnection *gc, int id);
int chat_add_message (struct tgl_state *TLS, struct tgl_message *M, char *text);
void chat_add_all_users (PurpleConversation *pc, struct tgl_chat *chat);
void request_code_entered (gpointer data, const gchar *code);
int generate_ident_icon(unsigned char* sha1_key);
int generate_ident_icon(struct tgl_state *TLS, unsigned char* sha1_key);
#endif

View file

@ -488,12 +488,12 @@ static void on_userpic_loaded (struct tgl_state *TLS, void *extra, int success,
purple_notify_user_info_add_pair (info, "Profile image", profile_image);
//TODO: get the sha1key from the secret chat
unsigned char sha1_key[20] = {129, 236, 235, 161, 62, 139, 244, 162, 120, 99, 99, 26, 171, 224, 25, 125};
int sha1key_store_id = generate_ident_icon(sha1_key);
int sha1key_store_id = generate_ident_icon(TLS, sha1_key);
if(sha1key_store_id != -1)
{
char *ident_icon = g_strdup_printf("<br><img id=\"%u\">", sha1key_store_id);
purple_notify_user_info_add_pair(info, "Identification icon", ident_icon);
g_free(ident_icon);
g_free(ident_icon);
}
purple_notify_userinfo (conn->gc, who, info, NULL, NULL);