DEVELOPMENT EDITION · 769442725406
Diagnostics Reference
On this page

B6005: memory might leak

Catalog status: active. Default severity: error. Stable name: memory-leak. Family: Ownership and finalization.

Verada proves that a program frees every object it allocates, given the contracts of the library and of imported code. An object that owns access values (see ownership) must own nothing, that is, every access value in it must be null or moved out, wherever it:

The prover found a path on which an owned object would be lost.

Example (Vada)

   procedure Clear (L : in out List) is
      Rest : List;
   begin
      if L /= null then
         Rest := L.Next;
         Free (L);
      end if;
   end Clear;   --  Rest still owns the rest of the list

Example (Varc)

    fn clear(l: inout List) {
        var rest: List;
        if l != null {
            rest = l.next;
            free(&l);
        }
    }   // rest still owns the rest of the list

A build without proof has no run-time check for leaks: only the proof shows there are none (see modes).

What to do (Vada)

Free what the object owns, or move it to an owner that outlives it (an out parameter, a result, a component of a longer-lived object): here, Clear (Rest); after Free (L);.

What to do (Varc)

Free what the object owns, or move it to an owner that outlives it (an out parameter, a result, a component of a longer-lived object): here, clear(&rest); after free(&l);.

Regression source and further reading

Complete regression example: source, command arguments and expected results. The fixture deliberately reproduces this diagnostic.

See ownership and finalization, the code index, and diagnostic interpretation for modes, replay, fix-its and JSON.