Several failure paths would result in control being transfered to
'exit' label, so instead of just returning error codes in those cases
we also need to free the memory allocated for 'ds1307'

Signed-off-by: Andrey Smirnov <andrew.smir...@gmail.com>
---
 drivers/rtc/rtc-ds1307.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 2b46ae5..e2d561b 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -17,6 +17,7 @@
 #include <init.h>
 #include <driver.h>
 #include <xfuncs.h>
+#include <malloc.h>
 #include <errno.h>
 #include <i2c/i2c.h>
 #include <rtc.h>
@@ -422,6 +423,8 @@ read_rtc:
        err = rtc_register(&ds1307->rtc);

 exit:
+       if (err)
+               free(ds1307);
        return err;
 }

--
2.5.0

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

Reply via email to