Skip to contentSkip to conversation

cifs: Fix a small memory leak in directory creation code.

PATCH New Jesper Juhl 1 participant 1 message Sep 16, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cifs: Fix a small memory leak in directory creation code.

There is a small memory leak in fs/cifs/inode.c::cifs_mkdir(). Storage for 'pInfo' is allocated with kzalloc(), but if the call to CIFSPOSIXCreate(...) happens to return 0 and pInfo->Type == -1, then we'll jump to the 'mkdir_get_info' label without freeing the storage allocated for 'pInfo'.
This patch adds a kfree() call to free the storage just before jumping to the label, thus getting rid of the leak.

---

 inode.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/cifs/inode.c renamed from fs/cifs/inode.c~ +3 -1
@@ -929,8 +929,10 @@ int cifs_mkdir(struct inode *inode, stru
 			d_drop(direntry);
 		} else {
 			int obj_type;
-			if (pInfo->Type == -1) /* no return info - go query */
+			if (pInfo->Type == -1) { /* no return info - go query */
+				kfree(pInfo);
 				goto mkdir_get_info;
+			}
 /*BB check (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID ) to see if need
 	to set uid/gid */
 			inc_nlink(inode);