### Bug Summary

File: | builds/wireshark/wireshark/ui/cli/tap-flow.c
Warning: | line 100, column 16 Potential leak of memory pointed to by 'flow_info'

### 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 tap-flow.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 -pic-is-pie -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 -D G_DISABLE_DEPRECATED -D G_DISABLE_SINGLE_INCLUDES -D WS_DEBUG -D WS_DEBUG_UTF_8 -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 -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/2026-01-31-100341-3623-1 -x c /builds/wireshark/wireshark/ui/cli/tap-flow.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 | /* tap-flow.c
2 | *
3 | * Wireshark - Network traffic analyzer
4 | * By Gerald Combs <gerald@wireshark.org>
5 | * Copyright 1998 Gerald Combs
6 | *
7 | * SPDX-License-Identifier: GPL-2.0-or-later
8 | */
9 |
10 | /* This module provides udp and tcp follow stream capabilities to tshark.
11 | * It is only used by tshark and not wireshark.
12 | */
13 |
14 | #include "config.h"
15 |
16 | #include <stdio.h>
17 | #include <stdlib.h>
18 |
19 | #include <epan/sequence_analysis.h>
20 | #include <epan/stat_tap_ui.h>
21 | #include <epan/tap.h>
22 | #include <wsutil/cmdarg_err.h>
23 |
24 | void register_tap_listener_flow(void);
25 |
26 | #define STR_FLOW"flow," "flow,"
27 | #define STR_STANDARD",standard" ",standard"
28 | #define STR_NETWORK",network" ",network"
29 |
30 | static void
31 | flow_draw(void *arg)
32 | {
33 | seq_analysis_info_t* flow_info = (seq_analysis_info_t*)arg;
34 |
35 | sequence_analysis_get_nodes(flow_info);
36 |
37 | sequence_analysis_dump_to_file(stdoutstdout, flow_info, 0);
38 | }
39 |
40 | static void
41 | flow_finish(void *arg)
42 | {
43 | seq_analysis_info_t* flow_info = (seq_analysis_info_t*)arg;
44 | //clean up the data
45 | sequence_analysis_list_free(flow_info);
46 | sequence_analysis_info_free(flow_info);
47 | }
48 |
49 | static void
50 | flow_reset(void *arg)
51 | {
52 | seq_analysis_info_t* flow_info = (seq_analysis_info_t*)arg;
53 | sequence_analysis_list_free(flow_info);
54 | }
55 |
56 | static bool_Bool flow_arg_strncmp(const char **opt_argp, const char *strp)
57 | {
58 | size_t len = strlen(strp);
59 |
60 | if (strncmp(*opt_argp, strp, len) == 0)
61 | {
62 | *opt_argp += len;
63 | return true1;
64 | }
65 | return false0;
66 | }
67 |
68 | static bool_Bool
69 | flow_arg_mode(const char **opt_argp, seq_analysis_info_t *flow_info)
70 | {
71 | if (flow_arg_strncmp(opt_argp, STR_STANDARD",standard"))
72 | {
73 | flow_info->any_addr = 1;
74 | }
75 | else if (flow_arg_strncmp(opt_argp, STR_NETWORK",network"))
76 | {
77 | flow_info->any_addr = 0;
78 | }
79 | else
80 | {
81 | cmdarg_err("Invalid address type.");
82 | return false0;
83 | }
84 |
85 | return true1;
86 | }
87 |
88 | static bool_Bool
89 | flow_init(const char *opt_argp, void *userdata)
90 | {
91 | seq_analysis_info_t *flow_info = g_new0(seq_analysis_info_t, 1)((seq_analysis_info_t *) g_malloc0_n ((1), sizeof (seq_analysis_info_t )));
1 | Memory is allocated | →
92 | GString *errp;
93 | register_analysis_t* analysis = (register_analysis_t*)userdata;
94 | const char *filter=NULL((void*)0);
95 |
96 | opt_argp += strlen(STR_FLOW"flow,");
97 | opt_argp += strlen(sequence_analysis_get_name(analysis));
98 |
99 | if (!flow_arg_mode(&opt_argp, flow_info))
2 | ← | Taking true branch | →
100 | return false0;
3 | ← | Potential leak of memory pointed to by 'flow_info'
101 |
102 | if (*opt_argp == ',') {
103 | filter = opt_argp + 1;
104 | }
105 |
106 | sequence_analysis_list_free(flow_info);
107 |
108 | errp = register_tap_listener(sequence_analysis_get_tap_listener_name(analysis), flow_info, filter, sequence_analysis_get_tap_flags(analysis),
109 | flow_reset, sequence_analysis_get_packet_func(analysis), flow_draw, flow_finish);
110 |
111 | if (errp != NULL((void*)0))
112 | {
113 | sequence_analysis_list_free(flow_info);
114 | sequence_analysis_info_free(flow_info);
115 | cmdarg_err("Couldn't register %s tap: %s",
116 | sequence_analysis_get_tap_listener_name(analysis), errp->str);
117 | g_string_free(errp, TRUE)(__builtin_constant_p ((!(0))) ? (((!(0))) ? (g_string_free) ( (errp), ((!(0)))) : g_string_free_and_steal (errp)) : (g_string_free ) ((errp), ((!(0)))));
118 | return false0;
119 | }
120 |
121 | return true1;
122 | }
123 |
124 | static bool_Bool
125 | flow_register(const void *key _U___attribute__((unused)), void *value, void *userdata _U___attribute__((unused)))
126 | {
127 | register_analysis_t* analysis = (register_analysis_t*)value;
128 | stat_tap_ui flow_ui;
129 | GString *cmd_str = g_string_new(STR_FLOW"flow,");
130 | char *cli_string;
131 |
132 | g_string_append(cmd_str, sequence_analysis_get_name(analysis))(__builtin_constant_p (sequence_analysis_get_name(analysis)) ? __extension__ ({ const char * const __val = (sequence_analysis_get_name (analysis)); g_string_append_len_inline (cmd_str, __val, (__val != ((void*)0)) ? (gssize) strlen (((__val) + !(__val))) : (gssize ) -1); }) : g_string_append_len_inline (cmd_str, sequence_analysis_get_name (analysis), (gssize) -1));
133 | cli_string = g_string_free(cmd_str, FALSE)(__builtin_constant_p ((0)) ? (((0)) ? (g_string_free) ((cmd_str ), ((0))) : g_string_free_and_steal (cmd_str)) : (g_string_free ) ((cmd_str), ((0))));
134 |
135 | flow_ui.group = REGISTER_STAT_GROUP_GENERIC;
136 | flow_ui.title = NULL((void*)0); /* construct this from the protocol info? */
137 | flow_ui.cli_string = cli_string;
138 | flow_ui.tap_init_cb = flow_init;
139 | flow_ui.nparams = 0;
140 | flow_ui.params = NULL((void*)0);
141 | register_stat_tap_ui(&flow_ui, analysis);
142 | g_free(cli_string);
143 | return false0;
144 | }
145 |
146 | void
147 | register_tap_listener_flow(void)
148 | {
149 | sequence_analysis_table_iterate_tables(flow_register, NULL((void*)0));
150 | }
151 |
152 | /*
153 | * Editor modelines - https://www.wireshark.org/tools/modelines.html
154 | *
155 | * Local Variables:
156 | * c-basic-offset: 4
157 | * tab-width: 8
158 | * indent-tabs-mode: nil
159 | * End:
160 | *
161 | * ex: set shiftwidth=2 tabstop=8 expandtab:
162 | * :indentSize=2:tabSize=8:noTabs=true:
163 | */