majianjia / nnom

A higher-level Neural Network library for microcontrollers.
Apache License 2.0
815 stars 235 forks source link

fix a memory leakage. #187

Closed bfs18 closed 1 year ago

bfs18 commented 1 year ago

in tensor of output layer cause memory leakage since the pointer is linked to the out tensor of previous layer. free the in tensor at output layer creation.

majianjia commented 1 year ago

Could you give more info why do you want to free tensor in here? Thanks

bfs18 commented 1 year ago

Could you give more info why do you want to free tensor in here? Thanks

Hi Jia,

By valgrind test result, allocation of output_s in tensor would cause memory leakage.

Logically, output_s layer uses the create function of input_s, this wold allocate memory for in tensor https://github.com/majianjia/nnom/blob/ef18796988319b28962fdcc17c75003e92cbc264/src/layers/nnom_input.c#L68 then, output_s layer uses default_build, https://github.com/majianjia/nnom/blob/ef18796988319b28962fdcc17c75003e92cbc264/src/layers/nnom_baselayer.c#L67 this line modifies in tensor and the allocated memory is not accessible any more. free the tensor at creation would fix the memory leakage.

majianjia commented 1 year ago

Thanks, it does have the problem. This PR would solve the issue as you explained.

Another proper way is to not use input constructor to build an output layer, which could be implemented later.