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

            Bug ID: 90906
           Summary: diagnose returning pointers to freed memory
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

GCC doesn't diagnose returning a freed pointer as in the function below:

  void* f (void *p)
  {
    __builtin_free (p);
    // ...
    return p;
  }

It could, by performing an analysis similar to -Wreturn-local-addr.  The
detection would make it possible to find among other things bugs in C++ code
due to returning pointers into local containers, such as:

  #include <vector>

  int* f ()
  {
    std::vector<int> v (3, 5);
    return v.data ();
  }

Reply via email to