From: Anders Blomdell Date: Wed, 22 Aug 2012 07:21:56 +0000 (+0100) Subject: comedi_open has file descriptor leak X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=2b8c2f8087d69be00c33a20d33d80106efa7f8a6;p=comedilib.git comedi_open has file descriptor leak If something fails after a succesful open, cleanup fails to close the file. The code cleanup: if(it) free(it); needs to be replaced with something like: cleanup: if (it) { if (it->fd >= 0) { close(it->fd); } free(it); Regards Anders Blomdell --- diff --git a/lib/comedi.c b/lib/comedi.c index 5877e6a..0d2086f 100644 --- a/lib/comedi.c +++ b/lib/comedi.c @@ -77,8 +77,14 @@ comedi_t* _comedi_open(const char *fn) return it; cleanup: - if(it) + if(it) { + /* As long as get_subdevices is the last action above, + it->subdevices should not need any cleanup, since + get_subdevices should have done the cleanup already */ + if (it->fd >= 0) + close(it->fd); free(it); + } return NULL; }