You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
List.filter_map (functionGVar (v, _, _) |GVarDecl (v, _) -> Some v |_ ->None) !Cilfacade.current_file.globals
@@ -131,11 +140,21 @@ struct
131
140
reachable_from_fields @ acc_struct
132
141
) []
133
142
134
-
letwarn_for_multi_threadedctx=
135
-
ifnot (ctx.ask (Queries.MustBeSingleThreaded { since_start =true })) then (
143
+
letwarn_for_multi_threaded_due_to_abortctx=
144
+
let malloc_called = was_malloc_called ctx in
145
+
ifnot (must_be_single_threaded ctx ~since_start:true) && malloc_called then (
146
+
set_mem_safety_flag InvalidMemTrack;
147
+
set_mem_safety_flag InvalidMemcleanup;
148
+
M.warn ~category:(Behavior (UndefinedMemoryLeak)) ~tags:[CWE401] "Program aborted while running in multi-threaded mode. A memory leak might occur"
149
+
)
150
+
151
+
(* If [is_return] is set to [true], then a thread return occurred, else a thread exit *)
152
+
letwarn_for_thread_return_or_exitctxis_return=
153
+
ifnot (ToppedVarInfoSet.is_empty ctx.local) then (
136
154
set_mem_safety_flag InvalidMemTrack;
137
155
set_mem_safety_flag InvalidMemcleanup;
138
-
M.warn ~category:(Behavior (UndefinedMemoryLeak)) ~tags:[CWE401] "Program isn't running in single-threaded mode. A memory leak might occur due to multi-threading"
156
+
let current_thread = ctx.ask (Queries.CurrentThreadId) in
157
+
M.warn ~category:(Behavior (UndefinedMemoryLeak)) ~tags:[CWE401] "Memory may be leaked at thread %s for thread %a" (if is_return then"return"else"exit") ThreadIdDomain.ThreadLifted.pretty current_thread
M.warn ~category:(Behavior (UndefinedMemoryLeak)) ~tags:[CWE401] "Possible memory leak: Memory was allocated in a multithreaded program, but not all threads are joined."
(* Warn about multi-threaded programs as soon as we encounter a dynamic memory allocation function *)
178
-
warn_for_multi_threaded ctx;
208
+
(ctx.sideg ()true;
179
209
beginmatch ctx.ask (Queries.AllocVar {on_stack =false}) with
180
-
|`Liftedvar -> D.add var state
210
+
|`Liftedvar ->
211
+
ToppedVarInfoSet.add var state
181
212
|_ -> state
182
-
end
213
+
end)
183
214
|Freeptr ->
184
215
beginmatch ctx.ask (Queries.MayPointTo ptr) with
185
-
|adwhennot (Queries.AD.is_top ad) &&Queries.AD.cardinal ad =1 ->
216
+
|adwhen(not (Queries.AD.is_top ad)) &&Queries.AD.cardinal ad =1 ->
186
217
(* Note: Need to always set "ana.malloc.unique_address_count" to a value > 0 *)
187
218
beginmatchQueries.AD.choose ad with
188
-
|Queries.AD.Addr.Addr (v,_) when ctx.ask (Queries.IsAllocVar v) && ctx.ask (Queries.IsHeapVar v) &¬@@ ctx.ask (Queries.IsMultiple v) -> D.remove v state (* Unique pointed to heap vars *)
0 commit comments