fpco / inline-c

284 stars 51 forks source link

Memory leak in example/test #129

Closed nmichael44 closed 2 years ago

nmichael44 commented 2 years ago

Your example here: https://github.com/fpco/inline-c/blob/master/inline-c-cpp/test/tests.hs

in this code:

  Hspec.it "Template with pointers" $ do
    pt <- [C.block| std::vector<int*>* {
        return new std::vector<int*>();
      } |] :: IO (Ptr (StdVector.CStdVector (Ptr C.CInt)))
    [C.block| void {
        int *a = new int;
        *a = 100;
        $(std::vector<int*>* pt)->push_back(a);
        std::cout << *((*$(std::vector<int*>* pt))[0]) << std::endl;
      } |]

is leaking memory. Both the int and the std::vector<int*> need to be deleted.