Skip to content

Split memLeak paths with sem.malloc.fail - #2097

Open
sim642 wants to merge 2 commits into
masterfrom
issue-2093
Open

Split memLeak paths with sem.malloc.fail#2097
sim642 wants to merge 2 commits into
masterfrom
issue-2093

Conversation

@sim642

@sim642 sim642 commented Aug 10, 2026

Copy link
Copy Markdown
Member

Closes #2093.

TODO

  • sv-benchmarks.

sim642 added 2 commits August 10, 2026 15:38
This is necessary to pass 76-memleak/33-malloc-fail-no-mem-leak.
@sim642 sim642 added this to the SV-COMP 2027 milestone Aug 10, 2026
@sim642 sim642 added bug sv-comp SV-COMP (analyses, results), witnesses precision labels Aug 10, 2026
@michael-schwarz

Copy link
Copy Markdown
Member

Could you explain why path-sensitivity is the right tool here?

@sim642

sim642 commented Aug 11, 2026

Copy link
Copy Markdown
Member Author

Sure, it wasn't my first idea either.

Initially I thought I'd just replace the handling of free here:

| Free ptr ->
begin match man.ask (Queries.MayPointTo ptr) with
| ad when (not (Queries.AD.is_top ad)) && Queries.AD.cardinal ad = 1 ->
(* Note: Need to always set "ana.malloc.unique_address_count" to a value > 0 *)
begin match Queries.AD.choose ad with
| Queries.AD.Addr.Addr (v,_) when man.ask (Queries.IsAllocVar v) && man.ask (Queries.IsHeapVar v) && not @@ man.ask (Queries.IsMultiple v) ->
ToppedVarInfoSet.remove v man.local
| _ -> man.local
end
| _ -> man.local
end

In particular, to do the natural thing of joining states over all points-to targets. But the sound thing to do in the NullPtr case is to remove nothing, so that wouldn't help in such a case.

And matching 2-element points-to sets which contain such a removable pointer and NullPtr to remove the variable also wouldn't be sound. The NullPtr in the points-to set might've come from somewhere else, not the failing allocation. So NullPtr might still be in there if the allocation succeeded and there's memory that still needs to be cleaned up.

The memLeak analysis is already path-sensitive w.r.t. its whole local state of allocated variables that still need to be freed, so this additional splitting seems to be the right way. Hopefully, the additional paths with NULLs are very short-lived: existing and adapted sv-benchmarks do an abort() close to the failed allocation.

@sim642 sim642 changed the title Split memLeak paths with sem.malloc.fail Split memLeak paths with sem.malloc.fail Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug precision sv-comp SV-COMP (analyses, results), witnesses

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sem.malloc.fail makes memory leak analysis less precise

2 participants