### Bug Summary

File: | epan/funnel.c
Warning: | line 98, column 26 Use of memory after it is freed

### Annotated Source Code

Press '?' to see keyboard shortcuts

Show analyzer invocation
clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name funnel.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -ffloat16-excess-precision=fast -fbfloat16-excess-precision=fast -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/builds/wireshark/wireshark/build -fcoverage-compilation-dir=/builds/wireshark/wireshark/build -resource-dir /usr/lib/llvm-21/lib/clang/21 -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -isystem /builds/wireshark/wireshark/epan -isystem /builds/wireshark/wireshark/build/epan -isystem /usr/include/mit-krb5 -isystem /usr/include/libxml2 -isystem /usr/include/lua5.4 -D G_DISABLE_DEPRECATED -D G_DISABLE_SINGLE_INCLUDES -D WS_BUILD_DLL -D WS_DEBUG -D WS_DEBUG_UTF_8 -D epan_EXPORTS -I /builds/wireshark/wireshark/build -I /builds/wireshark/wireshark -I /builds/wireshark/wireshark/include -I /builds/wireshark/wireshark/wiretap -D _GLIBCXX_ASSERTIONS -internal-isystem /usr/lib/llvm-21/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/builds/wireshark/wireshark/= -fmacro-prefix-map=/builds/wireshark/wireshark/build/= -fmacro-prefix-map=../= -Wno-format-nonliteral -Wno-pointer-sign -std=gnu11 -ferror-limit 19 -fvisibility=hidden -fwrapv -fwrapv-pointer -fstrict-flex-arrays=3 -stack-protector 2 -fstack-clash-protection -fcf-protection=full -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fexceptions -fcolor-diagnostics -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /builds/wireshark/wireshark/sbout/2025-11-19-100322-3583-1 -x c /builds/wireshark/wireshark/epan/funnel.c

Keyboard shortcuts:

- Use 'j/k' keys for keyboard navigation
- Use 'Shift+S' to show/hide relevant lines
- Use '?' to toggle this window

Close
Show only relevant lines Show control flow arrows

1 | /*
2 | * funnel.c
3 | *
4 | * EPAN's GUI mini-API
5 | *
6 | * (c) 2006, Luis E. Garcia Ontanon <luis@ontanon.org>
7 | *
8 | * Wireshark - Network traffic analyzer
9 | * By Gerald Combs <gerald@wireshark.org>
10 | * Copyright 1998 Gerald Combs
11 | *
12 | * SPDX-License-Identifier: GPL-2.0-or-later
13 | */
14 |
15 | #include "config.h"
16 |
17 | #include <epan/funnel.h>
18 | #include <wsutil/glib-compat.h>
19 |
20 | typedef struct _funnel_menu_t {
21 | char *name;
22 | register_stat_group_t group;
23 | funnel_menu_callback callback;
24 | void *callback_data;
25 | funnel_menu_callback_data_free callback_data_free;
26 | bool_Bool retap;
27 | } funnel_menu_t;
28 |
29 | typedef struct _console_menu {
30 | char *name;
31 | funnel_console_eval_cb_t eval_cb;
32 | funnel_console_open_cb_t open_cb;
33 | funnel_console_close_cb_t close_cb;
34 | void *user_data;
35 | funnel_console_data_free_cb_t data_free_cb;
36 | } funnel_console_menu_t;
37 |
38 | /**
39 | * Represents a single packet menu entry and callback
40 | */
41 | typedef struct _funnel_packet_menu_t {
42 | char *name; /**< Name to display in the GUI */
43 | char *required_fields; /**< comma-separated list of fields
44 | that must be present for the
45 | packet menu to be displayed */
46 | funnel_packet_menu_callback callback; /**< Lua function to be called on
47 | menu item selection. */
48 | void *callback_data; /**< Lua state for the callback
49 | function */
50 | bool_Bool retap; /**< Whether or not to rescan the
51 | capture file's packets */
52 | } funnel_packet_menu_t;
53 |
54 |
55 | /* XXX This assumes one main window and one capture file. */
56 | static const funnel_ops_t* ops;
57 | static GSList* registered_menus;
58 | static GSList* added_menus;
59 | static GSList* removed_menus;
60 | static bool_Bool menus_registered;
61 |
62 | /*
63 | * List of all registered funnel_packet_menu_t's
64 | */
65 | static GSList* registered_packet_menus;
66 |
67 | static GSList* registered_console_menus;
68 |
69 | /*
70 | * true if the packet menus were modified since the last registration
71 | */
72 | static bool_Bool packet_menus_modified;
73 |
74 | static void free_funnel_packet_menu(gpointer data, gpointer user_data);
75 |
76 | const funnel_ops_t* funnel_get_funnel_ops(void) { return ops; }
77 | void funnel_set_funnel_ops(const funnel_ops_t* o) { ops = o; }
78 |
79 | static void free_funnel_menu(gpointer data, gpointer user_data _U___attribute__((unused))) {
80 | funnel_menu_t* m = (funnel_menu_t*)data;
81 | g_free(m->name);
82 | if (m->callback_data_free) {
7 | ← | Assuming field 'callback_data_free' is null | →
8 | ← | Taking false branch | →
83 | m->callback_data_free(m->callback_data);
84 | }
85 | g_free(m);
9 | ← | Memory is released | →
86 | }
87 |
88 | static void funnel_remove_menu (GSList** menu_list, funnel_menu_t *menu)
89 | {
90 | GSList* current = *menu_list;
91 | while (current != NULL((void*)0))
2 | ← | Assuming 'current' is not equal to NULL | →
3 | ← | Loop condition is true. Entering loop body | →
92 | {
93 | GSList* next = current->next; // Store the next pointer BEFORE potentially removing current
94 | funnel_menu_t* m = (funnel_menu_t*)current->data;
95 | if (m->callback == menu->callback)
4 | ← | Assuming 'm->callback' is equal to 'menu->callback' | →
5 | ← | Taking true branch | →
96 | {
97 | free_funnel_menu(m, NULL((void*)0));
6 | ← | Calling 'free_funnel_menu' | →
10 | ← | Returning; memory was released via 1st parameter | →
98 | *menu_list = g_slist_remove(*menu_list, current->data);
11 | ← | Use of memory after it is freed
99 | }
100 |
101 | current = next; // Move to the stored next pointer
102 | }
103 | }
104 |
105 | static void funnel_clear_menu (GSList** menu_list, GFunc free_func)
106 | {
107 | g_slist_foreach(*menu_list, free_func, NULL((void*)0));
108 | g_slist_free(*menu_list);
109 | *menu_list = NULL((void*)0);
110 | }
111 |
112 | void funnel_register_menu(const char *name,
113 | register_stat_group_t group,
114 | funnel_menu_callback callback,
115 | void *callback_data,
116 | funnel_menu_callback_data_free callback_data_free,
117 | bool_Bool retap)
118 | {
119 | funnel_menu_t* m = g_new(funnel_menu_t, 1)((funnel_menu_t *) g_malloc_n ((1), sizeof (funnel_menu_t)));
120 | m->name = g_strdup(name)g_strdup_inline (name);
121 | m->group = group;
122 | m->callback = callback;
123 | m->callback_data = callback_data;
124 | m->callback_data_free = callback_data_free;
125 | m->retap = retap;
126 |
127 | registered_menus = g_slist_append(registered_menus, m);
128 | if (menus_registered) {
129 | funnel_menu_t* m_r = (funnel_menu_t *)g_memdup2(m, sizeof *m);
130 | m_r->name = g_strdup(name)g_strdup_inline (name);
131 | added_menus = g_slist_append(added_menus, m_r);
132 | }
133 | }
134 |
135 | void funnel_deregister_menus(funnel_menu_callback callback)
136 | {
137 | funnel_menu_t* m = g_new0(funnel_menu_t, 1)((funnel_menu_t *) g_malloc0_n ((1), sizeof (funnel_menu_t)));
138 | m->callback = callback;
139 |
140 | funnel_remove_menu(&registered_menus, m);
1 | Calling 'funnel_remove_menu' | →
141 | removed_menus = g_slist_append(removed_menus, m);
142 |
143 | // Clear and free memory of packet menus
144 | funnel_clear_menu(&registered_packet_menus, free_funnel_packet_menu);
145 | packet_menus_modified = true1;
146 | }
147 |
148 | void funnel_register_all_menus(funnel_registration_cb_t r_cb)
149 | {
150 | for (GSList* l = registered_menus; l; l = l->next)
151 | {
152 | funnel_menu_t* c = (funnel_menu_t*)l->data;
153 | r_cb(c->name,c->group,c->callback,c->callback_data,c->retap);
154 | }
155 | menus_registered = true1;
156 | }
157 |
158 | void funnel_reload_menus(funnel_deregistration_cb_t d_cb,
159 | funnel_registration_cb_t r_cb)
160 | {
161 | GSList* l;
162 | for (l = removed_menus; l; l = l->next)
163 | {
164 | funnel_menu_t* c = (funnel_menu_t*)l->data;
165 | d_cb(c->callback);
166 | }
167 | for (l = added_menus; l; l = l->next)
168 | {
169 | funnel_menu_t* c = (funnel_menu_t*)l->data;
170 | r_cb(c->name,c->group,c->callback,c->callback_data,c->retap);
171 | }
172 |
173 | funnel_clear_menu(&removed_menus, free_funnel_menu);
174 | funnel_clear_menu(&added_menus, free_funnel_menu);
175 | }
176 |
177 | /**
178 | * Entry point for Lua code to register a packet menu
179 | *
180 | * Stores the menu name and callback from the Lua code
181 | * into registered_packet_menus so that the
182 | * Wireshark GUI code can retrieve it with
183 | * funnel_register_all_packet_menus().
184 | */
185 | void funnel_register_packet_menu(const char *name,
186 | const char *required_fields,
187 | funnel_packet_menu_callback callback,
188 | void *callback_data,
189 | bool_Bool retap)
190 | {
191 | funnel_packet_menu_t* m = g_new0(funnel_packet_menu_t, 1)((funnel_packet_menu_t *) g_malloc0_n ((1), sizeof (funnel_packet_menu_t )));
192 | m->name = g_strdup(name)g_strdup_inline (name);
193 | m->required_fields = g_strdup(required_fields)g_strdup_inline (required_fields);
194 | m->callback = callback;
195 | m->callback_data = callback_data;
196 | m->retap = retap;
197 |
198 | registered_packet_menus = g_slist_append(registered_packet_menus, m);
199 |
200 | packet_menus_modified = true1;
201 | }
202 |
203 | static void free_funnel_packet_menu(gpointer data, gpointer user_data _U___attribute__((unused))) {
204 | funnel_packet_menu_t* m = (funnel_packet_menu_t*)data;
205 | g_free(m->name);
206 | g_free(m->required_fields);
207 | if (m->callback_data) {
208 | g_free(m->callback_data);
209 | }
210 | g_free(m);
211 | }
212 |
213 | /**
214 | * Entry point for Wireshark GUI to obtain all registered packet menus
215 | *
216 | * Calls the supplied callback for each packet menu registered with
217 | * funnel_register_packet_menu().
218 | *
219 | * @param r_cb the callback function to call with each registered packet menu
220 | */
221 | void funnel_register_all_packet_menus(funnel_registration_packet_cb_t r_cb)
222 | {
223 | for (GSList* l = registered_packet_menus; l; l = l->next)
224 | {
225 | funnel_packet_menu_t* c = (funnel_packet_menu_t*)l->data;
226 | r_cb(c->name, c->required_fields, c->callback, c->callback_data, c->retap);
227 | }
228 | packet_menus_modified = false0;
229 | }
230 |
231 | /**
232 | * Returns whether the packet menus have been modified since they were last registered
233 | *
234 | * @return true if the packet menus were modified since the last registration
235 | */
236 | bool_Bool funnel_packet_menus_modified(void)
237 | {
238 | return packet_menus_modified;
239 | }
240 |
241 | /**
242 | * Entry point for code to register a console menu
243 | */
244 | void funnel_register_console_menu(const char *name,
245 | funnel_console_eval_cb_t eval_cb,
246 | funnel_console_open_cb_t open_cb,
247 | funnel_console_close_cb_t close_cb,
248 | void *callback_data,
249 | funnel_console_data_free_cb_t free_data)
250 | {
251 | funnel_console_menu_t* m = g_new0(funnel_console_menu_t, 1)((funnel_console_menu_t *) g_malloc0_n ((1), sizeof (funnel_console_menu_t )));
252 | m->name = g_strdup(name)g_strdup_inline (name);
253 | m->eval_cb = eval_cb;
254 | m->open_cb = open_cb;
255 | m->close_cb = close_cb;
256 | m->user_data = callback_data;
257 | m->data_free_cb = free_data;
258 |
259 | registered_console_menus = g_slist_prepend(registered_console_menus, m);
260 | }
261 |
262 | void funnel_register_all_console_menus(funnel_registration_console_cb_t r_cb)
263 | {
264 | GSList *l;
265 | for (l = registered_console_menus; l != NULL((void*)0); l = l->next) {
266 | funnel_console_menu_t *m = l->data;
267 | r_cb(m->name, m->eval_cb, m->open_cb, m->close_cb, m->user_data);
268 | }
269 | }
270 |
271 | static void free_funnel_console_menu(gpointer data, gpointer user_data _U___attribute__((unused)))
272 | {
273 | funnel_console_menu_t* m = data;
274 | g_free(m->name);
275 | if (m->data_free_cb) {
276 | m->data_free_cb(m->user_data);
277 | }
278 | g_free(m);
279 | }
280 |
281 | void funnel_cleanup(void)
282 | {
283 | funnel_clear_menu(&registered_menus, free_funnel_menu);
284 | funnel_clear_menu(&registered_packet_menus, free_funnel_packet_menu);
285 | funnel_clear_menu(&registered_console_menus, free_funnel_console_menu);
286 | }
287 |
288 | /*
289 | * Editor modelines - https://www.wireshark.org/tools/modelines.html
290 | *
291 | * Local variables:
292 | * c-basic-offset: 4
293 | * tab-width: 8
294 | * indent-tabs-mode: nil
295 | * End:
296 | *
297 | * vi: set shiftwidth=4 tabstop=8 expandtab:
298 | * :indentSize=4:tabSize=8:noTabs=true:
299 | */