https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100294

            Bug ID: 100294
           Summary: need attribute takes_ownership
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: analyzer
          Assignee: dmalcolm at gcc dot gnu.org
          Reporter: felix-gcc at fefe dot de
  Target Milestone: ---

Now that -fanalyzer is here to track leaking memory, I need a way to tell gcc
that a function takes ownership of a pointer.

You could call it takes_ownership or maybe free.

Here's my setup: I have a function that does I/O batching for you. You have a
batch as a context variable, then you add buffers to it, then you write the
whole batch to a descriptor (or callback). The idea is that the descriptor can
point to a non-blocking socket and the abstraction takes care of repeatedly
writing the next bit in the vector after a partial write.

Anyway, I have a function that adds a buffer to the batch, and I have a
function that adds a buffer to the batch plus the batch takes ownership of the
pointer, i.e. when you are done with the batch and close it, all those pointers
will be freed.

-fanalyze now (rightly) complains that I'm leaking the memory of the pointer I
gave to the function that takes ownership.

I need a way to either say "takes ownership" or maybe, even better, a way to
say how the free will happen, so malloc+free matching in gcc 11 can apply.

Reply via email to