Deletion of a Message Queue failed

Hi,
In a function which is called in Thread A I’m creating a message queue. Then I’m posting a message (data and the pointer to this queue) into a queue of Thread B. After sending this message I’m waiting on the queue I created first for an answer from Thread B. After I received this message I don’t use the message queue anymore and I would like to delete it but it doesn’t work! I get an TX_QUEUE_ERROR (Invalid message queue pointer). Does anyone have an idea why I’m not able to delete this message queue?

Part of the code:
TX_QUEUE gui_q;
t_message msg;
int s = 0;
void *mem_q = NULL;

//create queue, allocate memory
mem_q = malloc (Q_SIZE);
if (mem_q == NULL)
{
printf ("unable to allocate queue memory
");
} //if

s = tx_queue_create ( &gui_q, //the queue
“gui_q”, //the name
Q_MSG, //message size
mem_q, //p to mem
Q_SIZE); //mem size
if (s != TX_SUCCESS)
{
printf ("unable to create queue
");
} //if

msg.data.srcQueue = &gui_q;
msg.data.data = input;
msg.message = M_REQUEST;

//sending to queue
s = tx_queue_send (&otherQueue, &msg, TX_NO_WAIT);

if (s == TX_SUCCESS)
{
//waiting for answer
s = tx_queue_receive (&gui_q, &msg, TX_WAIT_FOREVER);

if (s != TX_SUCCESS)
{
printf ("- error receiving message from queue!
");
} //if

//Valid response
else if (msg.message == M_RESPONSE)
{
//delete queue
s = tx_queue_delete (&gui_q);
if (s != TX_SUCCESS)
{
printf ("- unable to delete queue! retVal: %d
“, s);
} //if
else
{
printf (”+ queue deleted successfully
");
} //else (if)

//free queue memory
free (mem_q);

} //else if
} //if

Thanks,

Michael