Does comparing a pointer that has been free'd invoke UB?
This seems to be a fairly common pattern e.g. in hexchat (may not compile, see also plugin docs . also note that hexchat_plugin_get_info hasn't been used in forever so I'm omitting it for simplicity): static hexchat_plugin *ph; static int timer_cb(void *userdata) { if (hexchat_set_context(ph, userdata)) { /* <-- is this line UB? */ /* omitted */ } return 0; } static int do_ub(char *word[], char *word_eol[], void *userdata) { void *context = hexchat_get_context(ph); hexchat_hook_timer(ph, 1000, timer_cb, context); hexchat_command(ph, "close"); /* free the context - in practice this would be