Skip to content

Commit

Permalink
Fix memtrack for multi-threaded case
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-schwarz committed Nov 19, 2023
1 parent e7d6302 commit e6cee27
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/analyses/memLeak.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct
(* If [is_return] is set to [true], then a thread return occurred, else a thread exit *)
let warn_for_thread_return_or_exit ctx is_return =
if not (ToppedVarInfoSet.is_empty ctx.local) then (
set_mem_safety_flag InvalidMemTrack;
set_mem_safety_flag InvalidMemcleanup;
let current_thread = ctx.ask (Queries.CurrentThreadId) in
M.warn ~category:(Behavior (Undefined MemoryLeak)) ~tags:[CWE 401] "Memory may be leaked at thread %s for thread %a" (if is_return then "return" else "exit") ThreadIdDomain.ThreadLifted.pretty current_thread
Expand All @@ -53,8 +54,9 @@ struct

(* TRANSFER FUNCTIONS *)
let return ctx (exp:exp option) (f:fundec) : D.t =
(* Check for a valid-memcleanup violation in a multi-threaded setting *)
if (ctx.ask (Queries.MayBeThreadReturn)) then (
(* Check for a valid-memcleanup and memtrack violation in a multi-threaded setting *)
(* The check for multi-threadedness is to ensure that valid-memtrack and valid-memclenaup are treated separately for single-threaded programs *)
if (ctx.ask (Queries.MayBeThreadReturn) && not (ctx.ask (Queries.MustBeSingleThreaded { since_start = true }))) then (
warn_for_thread_return_or_exit ctx true
);
(* Returning from "main" is one possible program exit => need to check for memory leaks *)
Expand Down

0 comments on commit e6cee27

Please sign in to comment.