Move formerly global variables in Adafruit_DHT driver into readDHT function#72
Move formerly global variables in Adafruit_DHT driver into readDHT function#72DanielCasner wants to merge 1 commit intoadafruit:masterfrom
Conversation
…nction so that when people use this program as a template and try to call readDHT multiple times, they don't have terrible buffer overrun errors.
|
I've been experiencing crashes on my DHT equipped pi for a while now, basically, the more often I read, the sooner it will crash. Could this be related ? |
|
Seems very likely. This patch fixes a memory overflow I found when modifying the code for my own use. The Adafruit library version only does one read per invocation of the program but it's possible (depending on how the kernel on the RaspberryPi cleans up memory from old processes) that it could cause a crash in the stand alone program as well if it's called often. Sadly I haven't had any response to my pull request. |
|
I'm mistaken, I'm using the python version (which relies on c code also) but the c code seems different than the pure C version. In any case the Python version seems to crash after a while also... |
|
Thanks for sending the pull request and apologies for someone not getting to it sooner. I'll close this pull since the fix for #80 should stop the immediate issue with crashing because of the buffer overflow. I agree though as an illustrative example it's probably best to pull the debug info out--I want to check with a few folks to see if there's any strong argument for keeping the debug info first though. |
This program is intended to be used as an example and as a basis for people to write new programs. Without this fix, calling readDHT more than once in a program will eventually lead to a buffer overrun error.
In general global variables are dangerous and should especially be avoided in example code.