@@ -91,13 +91,11 @@ static struct plugin_instance *get_plugin_by_name(struct plugin_registry *regist
9191
9292// clang-format off
9393static struct platch_obj_cb_data * get_cb_data_by_channel_locked (struct plugin_registry * registry , const char * channel ) {
94- ANALYZER_SUPPRESS ({
95- list_for_each_entry (struct platch_obj_cb_data , data , & registry -> callbacks , entry ) {
96- if (streq (data -> channel , channel )) {
97- return data ;
98- }
94+ list_for_each_entry (struct platch_obj_cb_data , data , & registry -> callbacks , entry ) {
95+ if (streq (data -> channel , channel )) {
96+ return data ;
9997 }
100- });
98+ }
10199
102100 return NULL ;
103101}
@@ -396,17 +394,24 @@ int plugin_registry_set_receiver(const char *channel, enum platch_codec codec, p
396394int plugin_registry_remove_receiver_v2_locked (struct plugin_registry * registry , const char * channel ) {
397395 struct platch_obj_cb_data * data ;
398396
399- // clang analyzer reports false-positives for using deallocated memory here.
400- ANALYZER_SUPPRESS ({
401- data = get_cb_data_by_channel_locked (registry , channel );
402- if (data == NULL ) {
403- return EINVAL ;
404- }
397+ data = get_cb_data_by_channel_locked (registry , channel );
398+ if (data == NULL ) {
399+ return EINVAL ;
400+ }
401+
402+ list_del (& data -> entry );
403+
404+ // Analyzer thinks get_cb_data_by_channel might still return our data
405+ // after list_del and emits a "use-after-free" warning.
406+ // assert()s can change the assumptions of the analyzer, so we use them here.
407+ #ifdef DEBUG
408+ list_for_each_entry (struct platch_obj_cb_data , data_iter , & registry -> callbacks , entry ) {
409+ ASSUME (data_iter != data );
410+ }
411+ #endif
405412
406- list_del (& data -> entry );
407- free (data -> channel );
408- free (data );
409- });
413+ free (data -> channel );
414+ free (data );
410415
411416 return 0 ;
412417}
0 commit comments