Skip to content

Commit

Permalink
Adjust memory handling after embedding image.
Browse files Browse the repository at this point in the history
  • Loading branch information
hoehermann committed Jan 24, 2022
1 parent 6880aaa commit 686e996
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Other improvements:

Features which are present in the go-whatsapp version but missing here:

* Embedding images in the conversation window.
* Geting list of participants in group chat.
* Support for proxy servers (whatsmeow limitation).

Expand Down
6 changes: 3 additions & 3 deletions src/c/qrcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ gowhatsapp_display_qrcode(PurpleAccount *account, const char * challenge, void *
void
gowhatsapp_handle_qrcode(PurpleConnection *pc, const char *challenge, const char *terminal, void *image_data, size_t image_data_len)
{
PurpleMessageFlags flags = PURPLE_MESSAGE_RECV;
PurpleRequestUiOps *ui_ops = purple_request_get_ui_ops();
if (!ui_ops->request_fields || image_data_len <= 0) {
// The UI hasn't implemented the func we want, just output as a message instead
PurpleMessageFlags flags = PURPLE_MESSAGE_RECV;
gchar *msg_out;
gpointer img_data = g_memdup(image_data, image_data_len);
int img_id = purple_imgstore_add_with_id(img_data, image_data_len, NULL);
int img_id = purple_imgstore_add_with_id(image_data, image_data_len, NULL);
if (img_id >= 0) {
msg_out = g_strdup_printf("%s: <img id=\"%u\" alt=\"%s\"/><br />%s", "Please scan this QR code with your phone", img_id, challenge, terminal);
flags |= PURPLE_MESSAGE_IMAGES;
} else {
g_free(image_data); // image data not handled by imgstore – needs to be deleted here
msg_out = g_strdup_printf("%s: %s<br />%s", "Please scan this QR code with your phone", challenge, terminal);
}
purple_serv_got_im(pc, "Logon QR Code", msg_out, flags, time(NULL));
Expand Down

0 comments on commit 686e996

Please sign in to comment.