TSendUserEvent() in C

I’m having a bit of trouble getting a C program to send an event using TSendUserEvent(). I’m getting a protection fault from within the call, so clearly I’ve not set up the call properly, but am at a loss to explain what I’ve done wrong.

The code extract is as follows:

void ctiCloseNotReadyStatistic(char *statName)

{

TEvent	event;

TKVList	*user_data	= TKVListCreate();



event.Event  = EventUserEvent;

event.Server = g_cti_tserver;     // global TServer g_cti_tserver



TKVListAddString(user_data, statName, "");

event.UserData = user_data;



TSendUserEvent(g_cti_tserver, g_this_extension, &event);



TKVListFree(user_data);

}

Any ideas?

Cheers,

Martin

It appears that the problem is in the freeing of the user_data structure. I guess it’s some sort of timing problem, and removing TKVListFree() removes the problem.

However, this would mean that the memory would never be freed up. Solution, anyone?

Cheers,

Martin

I would clear the memory (with zeroes) occupied by the event structure before setting the fields in that variable.

In my opinion the “TSendUserEvent” function can be trying to use values from the uninitialised memory.

Regards,

Leszek

Leszek,

That’s better!

Thank you,

Martin

I had same Issue, it was solved memory.
memset (&event, 0, sizeof (event));

Thank you! :slight_smile: