[PATCH 2/6] rtc: ds1307: Fix a memory leak

Andrey Smirnov andrew.smirnov at gmail.com
Wed Jan 6 22:17:31 PST 2016


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.smirnov at 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



More information about the barebox mailing list