BarryServer : Git

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

// Related

Nucleus

Barry Fixed resource leak in VFS c4a1ba4 (3 years, 2 months ago)
diff --git a/vfs/inode.c b/vfs/inode.c
index 8197127..903efd1 100644
--- a/vfs/inode.c
+++ b/vfs/inode.c
@@ -134,8 +134,10 @@ inode_lookup(Inode *inode, const char *name)
 
 	/* The file doesn't exist */
 	if (!child) {
-		if (entry)
+		if (entry) {
 			remove(inode->dirEntries, entry);
+			put(entry);
+		}
 		entry = NULL;
 		goto end;
 	}
diff --git a/vfs/open.c b/vfs/open.c
index cac1512..cbc4bac 100644
--- a/vfs/open.c
+++ b/vfs/open.c
@@ -25,16 +25,16 @@ lookup(const char *path, ObjectList *newcustody)
 	char buf[PATH_MAX], *p = buf;
 	strncpy(buf, path, PATH_MAX);
 	Inode *inode;
-	DirEntry *entry;
+	DirEntry *entry = NULL;
 	ObjectList *custody;
 
 	/* Resolve to absolute/relative root */
 	if (*p == '/') {
-		inode = current->fs->root;
+		inode = get(current->fs->root);
 		while (*++p == '/');
 		custody = create_list(&dirEntryType, LIST_NORMAL);
 	} else {
-		inode = current->fs->cwd;
+		inode = get(current->fs->cwd);
 		custody = copy_list(current->fs->cwdPath);
 	}
 
@@ -53,22 +53,21 @@ lookup(const char *path, ObjectList *newcustody)
 			if (inode != current->fs->root) {
 				entry = pop_from_end(custody);
 				if (!entry)
-					inode = current->fs->root;
+					swap_ref(inode, current->fs->root);
 				else
 					put(entry);
 			}
 		} else {
 			entry = inode_lookup(inode, prev);
 			if (!entry) {
-				inode = NULL;
+				swap_ref(inode, NULL);
 				goto end;
 			}
 			add(custody, entry);
 			put(entry);
 		}
-
 		if (entry)
-			inode = entry->inode;
+			swap_ref(inode, entry->inode);
 
 		while (*++curr == '/');
 		prev = curr;
@@ -77,14 +76,14 @@ lookup(const char *path, ObjectList *newcustody)
 	/* Base name */
 	if (!strcmp(prev, ".") || !strcmp(prev, "")) {
 		if (!S_ISDIR(inode->mode)) {
-			inode = NULL;
-			entry = NULL;
+			swap_ref(inode, NULL);
+			swap_ref(entry, NULL);
 		}
 	} else if (!strcmp(prev, "..")) {
 		if (inode != current->fs->root) {
 			entry = pop_from_end(custody);
 			if (!entry)
-				inode = current->fs->root;
+				swap_ref(inode, current->fs->root);
 			else
 				put(entry);
 		}
@@ -98,11 +97,8 @@ lookup(const char *path, ObjectList *newcustody)
 		add(custody, entry);
 		put(entry);
 	}
-	if (entry) {
-		inode = entry->inode;
-		if (inode)
-			get(inode);
-	}
+	if (entry)
+		swap_ref(inode, entry->inode);
 
 	/* Copy path */
 	if (newcustody)