Skip to content

Use g_list_free_full instead of foreach+free

Johannes Sasongko requested to merge sjohannes/chatty:g_list_free_full into master

Currently building Chatty results in warnings like this:

../src/chatty-conversation.c: In function ‘chatty_conv_message_get_last_msg’:
../src/chatty-conversation.c:1005:28: warning: cast between incompatible function types from ‘void (*)(PurpleLog *)’ {aka ‘void (*)(struct _PurpleLog *)’} to ‘void (*)(void *, void *)’ [-Wcast-function-type]
   g_list_foreach (history, (GFunc)purple_log_free, NULL);

This is because GFuncs are meant to take two arguments, whereas purple_log_free takes one arg. Anyway, since what we're doing here is deleting every list member and then the list itself, both can be done at once with g_list_free_full, which is designed for this exact purpose (it takes a single-arg function).

Merge request reports