On Wed, Dec 28, 2016 at 03:52:09PM -0800, John Scipione wrote:
Make sure to incriment the node's ref_count before calling
vnode_path_to_vnode() which always decriments the nodes
diff --git a/src/tools/fs_shell/vfs.cpp b/src/tools/fs_shell/vfs.cpp
index 5137ddd..cb7e654 100644
--- a/src/tools/fs_shell/vfs.cpp
+++ b/src/tools/fs_shell/vfs.cpp
@@ -1054,7 +1054,14 @@ entry_ref_to_vnode(fssh_mount_id mountID,
fssh_vnode_id directoryID, const char
if (status < 0)
return status;
- return vnode_path_to_vnode(directory, clonedName, false, 0, _vnode, NULL);
+ inc_vnode_ref_count(directory);
+ // incriment directory ref_count before calling vnode_path_to_vnode()
+ status = vnode_path_to_vnode(directory, clonedName, false, 0, _vnode, NULL);
+ // vnode_path_to_vnode() decriments directory ref_count
+ put_vnode(directory);
+ // decriment directory ref_count again, freeing it but not _vnode
- if (isDir)
+ if (isDir) {
+ inc_vnode_ref_count(dirNode);
error = vnode_path_to_vnode(dirNode, leaf, false, 0, &dirNode, NULL);
- if (error != FSSH_B_OK) {
- TRACE(("vfs_normalize_path(): failed to get dir vnode for \".\" or
\"..\": %s\n",
- strerror(error)));
- return error;
+ // vnode_path_to_vnode() decriments dirNode ref_count
// get the directory path
error = dir_vnode_to_path(dirNode, buffer, bufferSize);
- put_vnode(dirNode);
+ if (dirNode != NULL) {
+ // we don't need the vnode anymore
+ put_vnode(dirNode);
+ }
if (error < FSSH_B_OK) {
TRACE(("vfs_normalize_path(): failed to get dir path: %s\n",
strerror(error)));
return error;
@@ -2749,8 +2762,10 @@ vfs_entry_ref_to_path(fssh_dev_t device,
fssh_ino_t inode, const char *leaf,
// get the directory path
status = dir_vnode_to_path(vnode, path, pathLength);
- put_vnode(vnode);
+ if (vnode != NULL) {
// we don't need the vnode anymore
+ put_vnode(vnode);
+ }
if (status < FSSH_B_OK)
return status;