@@ -91,13 +91,11 @@ static struct plugin_instance *get_plugin_by_name(struct plugin_registry *regist
91
91
92
92
// clang-format off
93
93
static 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 ;
99
97
}
100
- });
98
+ }
101
99
102
100
return NULL ;
103
101
}
@@ -396,17 +394,24 @@ int plugin_registry_set_receiver(const char *channel, enum platch_codec codec, p
396
394
int plugin_registry_remove_receiver_v2_locked (struct plugin_registry * registry , const char * channel ) {
397
395
struct platch_obj_cb_data * data ;
398
396
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
405
412
406
- list_del (& data -> entry );
407
- free (data -> channel );
408
- free (data );
409
- });
413
+ free (data -> channel );
414
+ free (data );
410
415
411
416
return 0 ;
412
417
}
0 commit comments