rscada / libmbus

Meter-bus library and utility programs
http://www.rscada.se/libmbus
BSD 3-Clause "New" or "Revised" License
224 stars 138 forks source link

prevent multiple calls to disconnect for serial and tcp #137

Closed Apollon77 closed 6 years ago

Apollon77 commented 6 years ago

as discussed in one of the node-mbus issues here is my change to prevent multiple "disconnect" calls to make problems by checking it.

lategoodbye commented 6 years ago

Does this prevent the segmentation faults?

Apollon77 commented 6 years ago

We tracked the topic down to a problem in my own code where it happened that the mbus_disconnect method was called twice and then the segfault happened at the second call of "close(handle->fd);" So yes this change makes sure that "close" is only called once for a filedescriptor at all.

It simply make sure "bad user code" do not break anything