Genesys CTI User Forum

Genesys CTI User Forum => Genesys CTI Technical Discussion => Topic started by: Martin Hanley on January 01, 1970, 12:00:00 AM

Title: TSendUserEvent() in C
Post by: Martin Hanley on January 01, 1970, 12:00:00 AM
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
Title: TSendUserEvent() in C
Post by: Martin Hanley on January 01, 1970, 12:00:00 AM
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
Title: TSendUserEvent() in C
Post by: LeszekM on January 01, 1970, 12:00:00 AM
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
Title: TSendUserEvent() in C
Post by: Martin Hanley on January 01, 1970, 12:00:00 AM
Leszek,

That's better!

Thank you,
Martin
Title: Re: TSendUserEvent() in C
Post by: Rodrigo on July 18, 2009, 01:45:33 AM
I had same Issue, it was solved memory.
memset (&event, 0, sizeof (event));

Thank you! :)