[ofa-general] [PATCH] libibverbs: fix memory leak in case of error flow
Dotan Barak
dotanb at dev.mellanox.co.il
Mon Mar 19 03:23:15 PDT 2007
Don't leak memory when madvise fails.
Signed-off-by: Dotan Barak <dotanb at mellanox.co.il>
---
diff --git a/src/memory.c b/src/memory.c
index 2af7021..70ef713 100644
--- a/src/memory.c
+++ b/src/memory.c
@@ -73,6 +73,7 @@ static int too_late;
int ibv_fork_init(void)
{
void *tmp;
+ int ret;
if (mm_root)
return 0;
@@ -87,12 +88,14 @@ int ibv_fork_init(void)
if (posix_memalign(&tmp, page_size, page_size))
return ENOMEM;
- if (madvise(tmp, page_size, MADV_DONTFORK) ||
- madvise(tmp, page_size, MADV_DOFORK))
- return ENOSYS;
+ ret = madvise(tmp, page_size, MADV_DONTFORK) ||
+ madvise(tmp, page_size, MADV_DOFORK);
free(tmp);
+ if (ret)
+ return ENOSYS;
+
mm_root = malloc(sizeof *mm_root);
if (!mm_root)
return ENOMEM;
More information about the general
mailing list