[LLVMbugs] [Bug 15330] New: Memory leak is produced due to an appropriate "delete operator" is not called for a "new" statement which throws an exception while another template version of "operator delete" is declared

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Feb 22 03:39:47 PST 2013


http://llvm.org/bugs/show_bug.cgi?id=15330

            Bug ID: 15330
           Summary: Memory leak is produced due to an appropriate "delete
                    operator" is not called for a "new" statement which
                    throws an exception while another template version of
                    "operator delete" is declared
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: dicomj23 at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

GCC doesn't produce a memory leak, but it does in clang trunk

$ clang++ --version && cat main.cpp && clang++ main.cpp -o main && ./main
clang version 3.3 (trunk 175738)
Target: i386-pc-linux-gnu
Thread model: posix


#include <iostream>

static bool freed = true;

void * operator new (unsigned int, const bool &) throw() {
  return freed = false, (void *)!0;
}

void operator delete (void *, const bool &) throw() {
  freed = true;
}
#if 1 // This declaration makes a trick: no one delete is called
template <typename T>
void operator delete (void *, const T &) {
  freed = true;
}
#endif

int main() {
  try {
    struct Throwable { Throwable() { throw int(-1); } };
    new (!0) Throwable;
  } catch(...) {
    if (!freed)  { std::cout << "memory leak detected" << std::endl; }
  }
  return 0;
}



memory leak detected

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130222/f2e10e4f/attachment.html>


More information about the llvm-bugs mailing list