Skip to content

Commit e309e22

Browse files
committed
try another source code permutation to fix analyzer warnings
1 parent 1faa70f commit e309e22

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

src/pluginregistry.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,11 @@ static struct plugin_instance *get_plugin_by_name(struct plugin_registry *regist
9191

9292
// clang-format off
9393
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;
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
396394
int 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
}

src/util/list.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,9 @@ static inline void list_replace(struct list_head *from, struct list_head *to) {
9393
}
9494

9595
static inline void list_del(struct list_head *item) {
96-
// We need this to suppress a false positive `use-after-free` coming from pluginregistry.c.
97-
ANALYZER_SUPPRESS({
98-
item->prev->next = item->next;
99-
item->next->prev = item->prev;
100-
item->prev = item->next = NULL;
101-
});
96+
item->prev->next = item->next;
97+
item->next->prev = item->prev;
98+
item->prev = item->next = NULL;
10299
}
103100

104101
static inline void list_delinit(struct list_head *item) {

0 commit comments

Comments
 (0)