Hello guys, I have qusetion, I have following structure:
Code:
typedef struct
{
GtkWidget* PoziomaLinijka; <--GTK
GtkWidget* PionowaLinijka; <--GTK
GtkWidget* Label1; <--GTK
GtkWidget* Label2; <--GTK
gint x,y; <--GTK
} StrukturaDrawing;
And now I dynamicly allocate memory for it:
Code:
StrukturaDrawing* Wsk;
Wsk = (StrukturaDrawing*)malloc(sizeof(StrukturaDrawing));
if (!Wsk)
{
std::cout << "Error" << std::endl;
}
It works great, it allocates it. Now I use GTK callbacks to do stuff with it, which works great but when I want to free memory of it:
Callback to function: Wyjscie:
Code:
g_signal_connect(G_OBJECT(Okno), "destroy", G_CALLBACK(Wyjscie), Wsk);
Code:
void Wyjscie(GtkWindow* window, GdkEvent* event, StrukturaDrawing* data)
{
gtk_main_quit();
free(data);
data = NULL;
}
I get:
First-chance exception at 0x7c96df51 in Ekseprymetnowanie.exe: 0xC0000005: Access violation reading location 0xfffffff9.
But if I write data = NULL and then free(data) which is nonsense, right? I get no warnings, also if I comment out freeing memory I get no error but then I will get memory leaks.
Thanks in advance guys.