JPEG_Encoder_DELETE
Deletes its internal data structures in the wrong order.
This can easily be reproduced with the JPEG_Enc_FileIO_BF609-CCES example project.
Import the project into your workspace.
include heap_debug.h in the main file
after adi_initComponents add
adi_heap_debug_disable( _HEAP_HPL_GEN );
adi_heap_debug_enable( _HEAP_STDERR_DIAG );
adi_heap_debug_set_ignore( _HEAP_ERROR_WRONG_HEAP );
open up the project options and select Link against heap debugging libraries.
On running the application ( on a Finboard in my case ) you should get the following error in the console
Output file: ../../../../../../Media/JPEG_Encoder/valley_300_380.yuv420_1_25_1_0.jpg
Writing output frames...
Calling JPEG_Encoder_DELETE()...
JPEG Encoding complete
A fatal error or exception has occurred.
Description: Attempted misaligned data memory or data cache access (Exception with EXCAUSE=0x24).
General Type: UnhandledException
Specific Type: DataMisalignedAccessViolation
General Code: 0x9
Specific Code: 0x24
Error Value: 0x00000000
Error PC: 0xffa02ee6
I've traced this error to the JPEG_Encoder_DELETE thus
_JPEG_Encoder_DELETE:
LINK 0x10 ;
[ SP + 0xc ] = P5 ;
P5 = R0 ;
R0 = [ P5 + 0x8 ] ;
CALL JPEG_MemAlloc_ADDRESS ;
R1 = [ P5 + 0xc ] ;
//this deletes 12(R1) alloc'd buffers the last of which is the structure refered by [P5]
CALL J_aAASXXXXXXXXXXXX ;
R0 = [ P5 + 0x8 ] ;
CALL JPEG_MemAlloc_DELETE ;
// [P5] is pointing to a deleted memory block with heap debug its contents are now 0xBD filled
P1 = [ P5 ] ;
R0 = [ P1 + 140 ] ;
// Misaligned data error caused in this call due to deleted data
CALL JPEG_McuBuffer_DELETE ;
P1 = [ P5 ] ;
R0 = [ P1 + 144 ] ;
CALL JPEG_BitsBuffer_DELETE ;
P1 = [ P5 ] ;
R0 = [ P1 + 160 ] ;
CALL J_aAAVXXXXXXXXXXXXXXXXXXX ;
P1 = [ P5 ] ;
R0 = [ P1 + 164 ] ;
CALL J_aAAVXXXXXXXXXXXXXXXXXXX ;
P1 = [ P5 ] ;
R0 = [ P1 + 168 ] ;
CALL J_aAAVXXXXXXXXXXXXXXXXXXX ;
R0 = [ P5 + 0x4 ] ;
CALL JPEG_MemAlloc_DELETE ;
P0 = [ FP + 0x4 ] ;
P5 = [ SP + 0xc ] ;
UNLINK ;
JUMP ( P0 ) ;
This shows that a malloc'd structure if being used after it has been free'd. I've implemented the 3 heap system and thus only the Jpeg library is using the L1Heap ( which is where the structure is allocated ) so i can protect against thread safety of the JPEG lib with a mutex, but is anyone simply uses the defaul heap, or a heap that is shared with another thread this could cause heap corruption.
Currently I haven't been able to produce a work arround other than not use heap_debug_libraries.
Has anyone got a workaround that will allow me to still use the heap_debug?