BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / commit / c4a1ba4bf904af4c5944b30c698180d41df41911 / object

// Related

Nucleus

Barry Fixed resource leak in VFS c4a1ba4 (3 years, 2 months ago)
diff --git a/object/list.c b/object/list.c
index 01f6aef..6745f28 100644
--- a/object/list.c
+++ b/object/list.c
@@ -7,9 +7,9 @@
  */
 
 #include <stdarg.h>
+#include <nucleus/kernel.h>
 #include <nucleus/object.h>
 #include <nucleus/memory.h>
-#include <nucleus/panic.h>
 
 /* Structure for a List Entry */
 struct ListEntry {
@@ -144,7 +144,8 @@ remove(ObjectList *list, void *addr)
 		entry->next->prev = entry->prev;
 
 	/* Release resources */
-	put(obj);
+	if (__builtin_expect(!!(obj->usage), 1))
+		put(obj);
 	list->entries--;
 	kfree(entry);
 	release(&list->lock);
diff --git a/object/manager.c b/object/manager.c
index a274408..7e6da04 100644
--- a/object/manager.c
+++ b/object/manager.c
@@ -6,14 +6,22 @@
  * controls their instantiation and deletion.
  */
 
-#include <nucleus/object.h>
+#include <nucleus/kernel.h>
 #include <nucleus/memory.h>
-#include <nucleus/panic.h>
+#include <nucleus/object.h>
 
 void init_lock(Spinlock *lock);
 void acquire(Spinlock *lock);
 void release(Spinlock *lock);
 
+/* Check the magic of an object */
+int
+check(void *addr)
+{
+	Object *obj = addr;
+	return (obj && obj->magic == OBJECT_MAGIC);
+}
+
 /* Obtain a reference to an object */
 void *
 get(void *addr)
@@ -37,6 +45,7 @@ put(void *addr)
 	if (obj->type->delete)
 		obj->type->delete(obj);
 	remove(obj->type->objects, obj);
+	obj->magic = 0;
 	if (obj->type->free)
 		obj->type->free(obj);
 	else