[libgee/0.8] Fix releasing NULL pointers during atomic exchange



commit 2b9364ebea1c5a1da9ab42fb52db1835fd58458a
Author: Maciej Piechotka <uzytkownik2 gmail com>
Date:   Sun Dec 2 02:43:23 2012 +0000

    Fix releasing NULL pointers during atomic exchange

 gee/hazardpointer.vala |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
---
diff --git a/gee/hazardpointer.vala b/gee/hazardpointer.vala
index 8e548e1..d725dfc 100644
--- a/gee/hazardpointer.vala
+++ b/gee/hazardpointer.vala
@@ -203,9 +203,11 @@ public class Gee.HazardPointer<G> { // FIXME: Make it a struct
 		bool success = AtomicPointer.compare_and_exchange((void **)aptr, old_rptr, new_rptr);
 		if (success) {
 			DestroyNotify<G> notify = get_destroy_notify<G> ();
-			Context.get_current_context ()->release_ptr (old_ptr, (owned)notify);
+			if (old_ptr != null) {
+				Context.get_current_context ()->release_ptr (old_ptr, (owned)notify);
+			}
 		} else if (new_ptr != null) {
-			delete new_ptr;
+			_new_ptr = (owned)new_ptr;
 		}
 		return success;
 	}
@@ -232,7 +234,9 @@ public class Gee.HazardPointer<G> { // FIXME: Make it a struct
 	public void release (owned DestroyNotify notify) {
 		unowned G item = _node[false];
 		_node.set (null);
-		Context.get_current_context ()->release_ptr (item, (owned)notify);
+		if (item != null) {
+			Context.get_current_context ()->release_ptr (item, (owned)notify);
+		}
 	}
 
 	/**



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]