klemmchr / rpi_ws281x.Net

A .NET Standard wrapper for the rpi_ws281x library
BSD 2-Clause "Simplified" License
7 stars 1 forks source link

free(): double free detected in tcache 2 #1

Open RamblingGeekUK opened 4 years ago

RamblingGeekUK commented 4 years ago

when I run the sample code, the HAT lights - the wrong colour and crashes with this error... PI3 .net core 3.1

klemmchr commented 4 years ago

Could you make a small repro?

RamblingGeekUK commented 4 years ago

Thanks for the quick reply. 😁

here is a repo of the code: https://github.com/RamblingGeekUK/led 😀

I'm using the prebuild binary copied to /usr/local/lib and when I run the code I get the following output

image

this is the HAT I'm using : https://www.waveshare.com/wiki/RGB_LED_HAT

klemmchr commented 4 years ago

Ok, didn't expect you're using the sample 1:1 I would assume the bug lies around here as there is no point in code where _leds is set to null which could potentially result in a double free of the native handle. However, the dispose pattern is implemented very bad in general. There is no differentiation between native stuff and managed objects. Also the finalizer is missing. Sadly I'm currently busy moving to a new flat so I don't have time to fix it properly. My current advice would be to avoid disposing the strip. Also, disposing is not needed when the program terminates afterwards.

RamblingGeekUK commented 4 years ago

Thanks for taking the time to look into this, very much appreciated. That's stopped it crashing, and the LED's come on, all be it not the colour set.

Yeah sorry, I was just trying to get things working using the sample before moving onwards. 😁

Good luck with the move and be safe -thanks again.