I'm just trying this out of curiosity. I have a struct with a constructor and a copy constructor and trying to initialize the struct using the copy constructor in the main, while at the same time within the main, implementing memory allocation to the pointer to a struct. Copy construct initialization works alright, but when I try to free it before the main return, it causes an assertion error in the heap.
    #include <stdio.h>
    #include <malloc.h>
    typedef struct tagInfo
    {
        int iX;
        int iY;
        tagInfo() {};
        tagInfo(int x, int y)
            : iX(x), iY(y) {};
        ~tagInfo() {};
    }INFO;
    int main (void)
    {
        INFO* pInfo = (INFO*)malloc(sizeof(INFO));
        pInfo = &INFO(10, 10);
        free(pInfo);
        return 0;
    }
How can I safely free the above pointer without causing assertion errors?
 
     
     
     
    