-
-
Save jessicah/623dde6cdf0c49b5f177 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 2db7907b92b0d86626dfcc09446c182651c81596 Mon Sep 17 00:00:00 2001 | |
From: Jessica Hamilton <jessica.l.hamilton@gmail.com> | |
Date: Sat, 31 May 2014 10:25:42 +1200 | |
Subject: [PATCH] xsi_semaphore: use MemoryDeleter instead of multiple free() | |
--- | |
src/system/kernel/posix/xsi_semaphore.cpp | 8 +++----- | |
1 file changed, 3 insertions(+), 5 deletions(-) | |
diff --git a/src/system/kernel/posix/xsi_semaphore.cpp b/src/system/kernel/posix/xsi_semaphore.cpp | |
index 3e311f3..a82d206 100644 | |
--- a/src/system/kernel/posix/xsi_semaphore.cpp | |
+++ b/src/system/kernel/posix/xsi_semaphore.cpp | |
@@ -22,6 +22,7 @@ | |
#include <util/AutoLock.h> | |
#include <util/DoublyLinkedList.h> | |
#include <util/OpenHashTable.h> | |
+#include <AutoDeleter.h> | |
//#define TRACE_XSI_SEM | |
@@ -1088,11 +1089,11 @@ _user_xsi_semop(int semaphoreID, struct sembuf *ops, size_t numOps) | |
TRACE_ERROR(("xsi_semop: failed to allocate sembuf struct\n")); | |
return B_NO_MEMORY; | |
} | |
+ MemoryDeleter operationsDeleter(operations); | |
if (user_memcpy(operations, ops, | |
(sizeof(struct sembuf) * numOps)) < B_OK) { | |
TRACE_ERROR(("xsi_semop: user_memcpy failed\n")); | |
- free(operations); | |
return B_BAD_ADDRESS; | |
} | |
@@ -1158,10 +1159,8 @@ _user_xsi_semop(int semaphoreID, struct sembuf *ops, size_t numOps) | |
if (operation != 0) | |
semaphore->Revert(operation); | |
} | |
- if (result != 0) { | |
- free(operations); | |
+ if (result != 0) | |
return result; | |
- } | |
// We have to wait: first enqueue the thread | |
// in the appropriate set waiting list, then | |
@@ -1248,6 +1247,5 @@ _user_xsi_semop(int semaphoreID, struct sembuf *ops, size_t numOps) | |
semaphore->SetPid(getpid()); | |
} | |
} | |
- free(operations); | |
return result; | |
} | |
-- | |
1.9.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment