pb_decode memory issues with one of

18 views
Skip to first unread message

Nicole Donnelly

unread,
Mar 12, 2024, 2:22:40 AMMar 12
to nanopb
Hi,

I have a proto used to update registers of a sensors via XMC, I have attached the proto.

When I try to decode the message on the XMC side, it is successful however it then crashes due to memory issues, this only occurs when the pb_decode function returns true. (I am assuming memory is not being freed after the function?)

Note the message I am sending to XMC is:
Reques t{writeRequest{ Reg Config settings}}}
        

below is the function for decoding the message 

void decode_message(uint8_t* message, size_t message_size){

//Create stream that reads from UART buffer
pb_istream_t stream = pb_istream_from_buffer(message, message_size);

//----Check Request
if(pb_decode(&stream, au_com_coolon_mars_wirepas_endpoints_protobufs_Bgt60ltr11aipRequest_fields, &Request)){
        //Success
else{
        //FAIL
}
}

where au_com_coolon_mars_wirepas_endpoints_protobufs_Bgt60ltr11aipRequest  Request = au_com_coolon_mars_wirepas_endpoints_protobufs_Bgt60ltr11aipRequest_init_default;

I have tried enabled PB_ENABLE_MALLOC and it doesn't fix it. Do you have any suggestions? 
motionBGT60LTR11AIP.proto

Petteri Aimonen

unread,
Mar 12, 2024, 2:26:36 AMMar 12
to nan...@googlegroups.com
Hi,

> When I try to decode the message on the XMC side, it is successful however
> it then crashes due to memory issues, this only occurs when the pb_decode
> function returns true. (I am assuming memory is not being freed after the
> function?)

Without PB_ENABLE_MALLOC, there isn't even any memory allocated in the first
place.

The symptoms sound like you might have too little stack space, and getting
a stack overflow that corrupts the return pointer. This can especially happen
if you allocate message buffers on stack.

--
Petteri

Reply all
Reply to author
Forward
0 new messages