diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c
index e4b52783819db9eff1ccbfb99eddb66bc9595d64..992b74f9c9414a476834819ee84df1e983a2af95 100644
--- a/fs/ubifs/debug.c
+++ b/fs/ubifs/debug.c
@@ -1123,6 +1123,7 @@ int dbg_check_dir(struct ubifs_info *c, const struct inode *dir)
 			err = PTR_ERR(dent);
 			if (err == -ENOENT)
 				break;
+			kfree(pdent);
 			return err;
 		}