Home/Support/Support Forum/TCP server, socket and memory
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

TCP server, socket and memory

0 votes
Hello,

Right now I'm developing a simple TCP server inside a Connect ME. I've downloaded the TCP Server example from digi.com

But after I've looked at the code, there are a few things I don't understand. After a client has connected to the server, a new thread is created to listen to that connection. The code is the following:


stackP=malloc(4096);
dyn_thread = malloc(sizeof(TX_THREAD));
dyn_name = malloc(20);

sprintf(dyn_name, "Com_Thread #%d", thread_number++);

retVal = tx_thread_create (dyn_thread, /* control block for root thread*/
dyn_name, /* thread name*/
datapipe, /* entry function*/
clientSocketDescriptor, /* parameter*/
stackP, /* start of stack*/
2048, /* size of stack*/
16, /* priority*/
16, /* preemption threshold */
1, /* time slice threshold*/
TX_AUTO_START); /* start immediately*/


As you can see, the stack of the thread is taken from the heap. But it's never freed.

So, maybe I'm missing something but after some time this Digi will run out of memory. Because the thread doesn't free that memory on destruction.

Thank you!
asked Jun 29, 2007 in NET+OS by alblurrow New to the Community (4 points)
recategorized Dec 18, 2013 by tuxembb

Please log in or register to answer this question.

3 Answers

0 votes
Absolutely! Check out tx_thread_create and tx_thread_delete in the API. It's the applications responsibility to call free() when the thread has been removed to free up the memory.
answered Jun 29, 2007 by charliek Veteran of the Digi Community (408 points)
0 votes
Hi alblurrow

Where can I find that example because I am writing a very similar program and a guideline would be nice to have
answered Dec 7, 2010 by derwee New to the Community (4 points)
0 votes
Hi,
check the programmers guide. You may find it in Start->Programs->Digi->documentation

Jirka
answered Dec 14, 2010 by kubiajir Community Contributor (61 points)
...