[SeaBIOS] [PATCH 08/10] malloc: Add warning if free() called on invalid memory
Kevin O'Connor
kevin at koconnor.net
Fri Oct 9 19:53:36 CEST 2015
Signed-off-by: Kevin O'Connor <kevin at koconnor.net>
---
src/malloc.c | 10 ++++++++++
src/malloc.h | 4 +---
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/src/malloc.c b/src/malloc.c
index c41a0cb..f5c2ed4 100644
--- a/src/malloc.c
+++ b/src/malloc.c
@@ -276,6 +276,16 @@ _free(void *data)
return 0;
}
+void
+free(void *data)
+{
+ if (!data)
+ return;
+ int ret = _free(data);
+ if (ret)
+ warn_internalerror();
+}
+
// Find the amount of free space in a given zone.
u32
malloc_getspace(struct zone_s *zone)
diff --git a/src/malloc.h b/src/malloc.h
index 2bcb5bf..b765bc4 100644
--- a/src/malloc.h
+++ b/src/malloc.h
@@ -17,6 +17,7 @@ void malloc_init(void);
void malloc_prepboot(void);
void *_malloc(struct zone_s *zone, u32 size, u32 align);
int _free(void *data);
+void free(void *data);
u32 malloc_getspace(struct zone_s *zone);
void malloc_sethandle(void *data, u32 handle);
void *malloc_findhandle(u32 handle);
@@ -64,8 +65,5 @@ static inline void *memalign_tmp(u32 align, u32 size) {
return ret;
return memalign_tmplow(align, size);
}
-static inline void free(void *data) {
- _free(data);
-}
#endif // malloc.h
--
2.4.3
More information about the SeaBIOS
mailing list