Currently if the kmalloc in exports_open fails,
the seq_file isn't seq_released.
We now do the kmalloc first, and make sure to kfree
if seq_open fails.
static int exports_open(struct inode *inode, struct file *file)
{
int res;
+ char *namebuf = kmalloc(PAGE_SIZE, GFP_KERNEL);
+ if (namebuf == NULL)
+ return -ENOMEM;
+
res = seq_open(file, &nfs_exports_op);
- if (!res) {
- char *namebuf = kmalloc(PAGE_SIZE, GFP_KERNEL);
- if (namebuf == NULL)
- res = -ENOMEM;
- else
- ((struct seq_file *)file->private_data)->private = namebuf;
- }
+ if (res)
+ kfree(namebuf);
+ else
+ ((struct seq_file *)file->private_data)->private = namebuf;
+
return res;
}
static int exports_release(struct inode *inode, struct file *file)