FreeRTOS + FAT memory leak

qbaj wrote on Tuesday, November 26, 2019:

Hi,
I found memory leak in FreeRTOS + FAT, every create task, open/close file and than delete task generate 268 B leak.
In ff_fopen we use prvABSPath and pxFindCWD with ffconfigMALLOC to malloc some space (268 B) for pvThreadLocalStoragePointers.
In prvDeleteTCB there isn’t ffconfigFREE or vPortFree for pvThreadLocalStoragePointers.

Update:
We use FreeRTOS+FAT Labs Build 160919a.

heinbali01 wrote on Tuesday, November 26, 2019:

Thanks for reporting this, but someone was earlier:

https://sourceforge.net/p/freertos/discussion/382005/thread/eb917b6b41

and it had a solution.

I recently posted an informal release of FreeRTOS+FAT in this post.

qbaj wrote on Tuesday, November 26, 2019:

Hi,
thanks for quick response!

But I think, better way to do this, it will be in prvDeleteTCB:

		#if ( configNUM_THREAD_LOCAL_STORAGE_POINTERS != 0 )
		{
			for( UBaseType_t x = 0; x < ( UBaseType_t ) configNUM_THREAD_LOCAL_STORAGE_POINTERS; x++ )
			{               
				if(pxTCB->pvThreadLocalStoragePointers[ x ] != NULL)
				{
					vPortFree(pxTCB->pvThreadLocalStoragePointers[ x ]);
				}
				else
				{
					mtCOVERAGE_TEST_MARKER() ;
				}
			}
		}
		#endif /* configNUM_THREAD_LOCAL_STORAGE_POINTERS */

but when we use stdioERRNO_THREAD_LOCAL_OFFSET=ffconfigCWD_THREAD_LOCAL_INDEX+0 or stdioFF_ERROR_THREAD_LOCAL_OFFSET=ffconfigCWD_THREAD_LOCAL_INDEX+2, there is int value not pointer in vTaskSetThreadLocalStoragePointer and it should be change too.

What do you think about it?

rtel wrote on Tuesday, November 26, 2019:

Very soon the +FAT code will be in a Labs directory of the main download, so under normal source control, which will make these fixes easier to control.

heinbali01 wrote on Friday, November 29, 2019:

I think that it would not be correct to change prvDeleteTCB() for this purpose.
The kernel does not make any assumption about the thread-local-storage-pointers. Maybe it is just a copy of a pointer, and maybe it is an integer value like errno, cast to a pointer.

Could you point which file and where the location is for the solution? Can’t access the sourceforge link now. Thank you.

This thread is quite old, at that time all software was distributed from freertos.org and from sourceforge.net

Since a couple of years, these are the official repositories:

amazon-freertos
FreeRTOS kernel
FreeRTOS+TCP
FreeRTOS+FAT

If you have any questions, feel free to create a new post.