iio staging: fix potential resource leak in generic_buffer
authorPeter Meerwald <pmeerw@pmeerw.net>
Mon, 25 Jun 2012 21:13:24 +0000 (23:13 +0200)
committerJonathan Cameron <jic23@kernel.org>
Sat, 30 Jun 2012 09:12:21 +0000 (10:12 +0100)
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/staging/iio/Documentation/iio_utils.h

index 6f3a392297ec07d711e0c75a51cc62112acb3e97..ab788594b202994a18398a66dc1a7508baf82301 100644 (file)
@@ -157,7 +157,8 @@ inline int iioutils_get_type(unsigned *is_signed,
                                     &padint, shift);
                        if (ret < 0) {
                                printf("failed to pass scan type description\n");
-                               return ret;
+                               ret = -errno;
+                               goto error_close_sysfsfp;
                        }
                        *be = (endianchar == 'b');
                        *bytes = padint / 8;
@@ -173,7 +174,11 @@ inline int iioutils_get_type(unsigned *is_signed,
                        free(filename);
 
                        filename = 0;
+                       sysfsfp = 0;
                }
+error_close_sysfsfp:
+       if (sysfsfp)
+               fclose(sysfsfp);
 error_free_filename:
        if (filename)
                free(filename);