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
This commit is contained in:
Anders Blomdell 2012-08-22 08:21:56 +01:00 committed by Ian Abbott
parent 50ad010b31
commit 2b8c2f8087

View file

@ -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;
}