drivers/media/dvb/bt8xx/dst_ca.c: fix 2 memory leaks
PATCH 1/1 drivers/media/dvb/bt8xx/dst_ca.c: fix 2 memory leaks
The Coverity checker spotted that thre was a memory leak if the second or third kmalloc() failed.
Besides this, I've also consolidated the three error handlings into one.
---
drivers/media/dvb/bt8xx/dst_ca.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/media/dvb/bt8xx/dst_ca.c renamed from drivers/media/dvb/bt8xx/dst_ca.c.old +9 -10
@@ -473,18 +473,17 @@ static int dst_ca_ioctl(struct inode *invoid __user *arg = (void __user *)ioctl_arg;int result =0 ; -if ((p_ca_message = (struct ca_msg *)kmalloc (sizeof (struct ca_msg ),GFP_KERNEL )) ==NULL ) { -dprintk (verbose,DST_CA_ERROR ,1 ," Memory allocation failure" ); -return -ENOMEM ; - } -if ((p_ca_slot_info = (struct ca_slot_info *)kmalloc (sizeof (struct ca_slot_info ),GFP_KERNEL )) ==NULL ) { -dprintk (verbose,DST_CA_ERROR ,1 ," Memory allocation failure" ); -return -ENOMEM ; - } -if ((p_ca_caps = (struct ca_caps *)kmalloc (sizeof (struct ca_caps ),GFP_KERNEL )) ==NULL ) { + p_ca_message = (struct ca_msg *)kmalloc (sizeof (struct ca_msg ),GFP_KERNEL ); + p_ca_slot_info = (struct ca_slot_info *)kmalloc (sizeof (struct ca_slot_info ),GFP_KERNEL ); + p_ca_caps = (struct ca_caps *)kmalloc (sizeof (struct ca_caps ),GFP_KERNEL ); + + +if (!p_ca_message || !p_ca_slot_info || !p_ca_caps) {dprintk (verbose,DST_CA_ERROR ,1 ," Memory allocation failure" ); -return -ENOMEM ; + result = -ENOMEM ; + goto free_mem_and_exit; } +/* We have now only the standard ioctl's, the driver is upposed to handle internals. */ switch (cmd) {case CA_SEND_MSG :
Quoted 35 lines · Adrian Bunk
The Coverity checker spotted that thre was a memory leak if the second or third
kmalloc()failed.Besides this, I've also consolidated the three error handlings into one.
Signed-off-by Adrian Bunk <[email protected]>---
drivers/media/dvb/bt8xx/dst_ca.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)drivers/media/dvb/bt8xx/dst_ca.c renamed from drivers/media/dvb/bt8xx/dst_ca.c.old +6
-9@@ -473,18 +473,17 @@ static int dst_ca_ioctl(struct inode *invoid __user *arg = (void __user *)ioctl_arg;int result =0 ; -if ((p_ca_message = (struct ca_msg *)kmalloc (sizeof (struct ca_msg ),GFP_KERNEL )) ==NULL ) { -dprintk (verbose,DST_CA_ERROR ,1 ," Memory allocation failure" ); -return -ENOMEM ; - } -if ((p_ca_slot_info = (struct ca_slot_info *)kmalloc (sizeof (struct ca_slot_info ),GFP_KERNEL )) ==NULL ) { -dprintk (verbose,DST_CA_ERROR ,1 ," Memory allocation failure" ); -return -ENOMEM ; - } -if ((p_ca_caps = (struct ca_caps *)kmalloc (sizeof (struct ca_caps ),GFP_KERNEL )) ==NULL ) { + p_ca_message = (struct ca_msg *)kmalloc (sizeof (struct ca_msg ),GFP_KERNEL ); + p_ca_slot_info = (struct ca_slot_info *)kmalloc (sizeof (struct ca_slot_info ),GFP_KERNEL ); + p_ca_caps = (struct ca_caps *)kmalloc (sizeof (struct ca_caps ),GFP_KERNEL ); + + +if (!p_ca_message || !p_ca_slot_info || !p_ca_caps) {dprintk (verbose,DST_CA_ERROR ,1 ," Memory allocation failure" );
drivers/media/dvb/bt8xx/dst_ca.c static int dst_ca_ioctl(struct inode *in
Quoted 10 lines
drivers/media/dvb/bt8xx/dst_ca.c renamed from drivers/media/dvb/bt8xx/dst_ca.c.old +3
-2-return -ENOMEM ; + result = -ENOMEM ; + goto free_mem_and_exit; } +/* We have now only the standard ioctl's, the driver is upposed to handle internals. */ switch (cmd) {case CA_SEND_MSG : -
Yeah, it is better indeed. Would you mind if i schedule this for a little while later, since i have a couple of other fixes/additions as well ?
Thanks,
Manu
Quoted 3 lines · Manu Abraham
Yeah, it is better indeed. Would you mind if i schedule this for a little while later, since i have a couple of other fixes/additions as well ?
There's no need to hurry since the whole problem is only a small memory leak in a very unlikely case.
Quoted 2 lines
Thanks,
Manu
cu
Adrian
Signature · 4 lines
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon SeedPATCH 1/1 drivers/media/dvb/bt8xx/dst_ca.c: fix 2 memory leaks
Quoted 7 lines · Adrian Bunk
Quoted 3 lines · Manu Abraham
Yeah, it is better indeed. Would you mind if i schedule this for a little while later, since i have a couple of other fixes/additions as well ?
There's no need to hurry since the whole problem is only a small memory leak in a very unlikely case.
But when you'll apply it, please used the improved version below (based on a suggestion by Ingo Oeser).
cu
Adrian
<-- snip -->
The Coverity checker spotted that thre was a memory leak if the second or third kmalloc() failed.
Besides this, I've also consolidated the three error handlings into one and removed the unneeded casts.
---
drivers/media/dvb/bt8xx/dst_ca.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/media/dvb/bt8xx/dst_ca.c renamed from drivers/media/dvb/bt8xx/dst_ca.c.old +9 -10
@@ -473,18 +473,17 @@ static int dst_ca_ioctl(struct inode *invoid __user *arg = (void __user *)ioctl_arg;int result =0 ; -if ((p_ca_message = (struct ca_msg *)kmalloc (sizeof (struct ca_msg ),GFP_KERNEL )) ==NULL ) { -dprintk (verbose,DST_CA_ERROR ,1 ," Memory allocation failure" ); -return -ENOMEM ; - } -if ((p_ca_slot_info = (struct ca_slot_info *)kmalloc (sizeof (struct ca_slot_info ),GFP_KERNEL )) ==NULL ) { -dprintk (verbose,DST_CA_ERROR ,1 ," Memory allocation failure" ); -return -ENOMEM ; - } -if ((p_ca_caps = (struct ca_caps *)kmalloc (sizeof (struct ca_caps ),GFP_KERNEL )) ==NULL ) { + p_ca_message =kmalloc (sizeof (struct ca_msg ),GFP_KERNEL ); + p_ca_slot_info =kmalloc (sizeof (struct ca_slot_info ),GFP_KERNEL ); + p_ca_caps =kmalloc (sizeof (struct ca_caps ),GFP_KERNEL ); + + +if (!p_ca_message || !p_ca_slot_info || !p_ca_caps) {dprintk (verbose,DST_CA_ERROR ,1 ," Memory allocation failure" ); -return -ENOMEM ; + result = -ENOMEM ; + goto free_mem_and_exit; } +/* We have now only the standard ioctl's, the driver is upposed to handle internals. */ switch (cmd) {case CA_SEND_MSG :
Quoted 12 lines · Adrian Bunk
Quoted 6 lines · Adrian Bunk
Quoted 2 lines · Manu Abraham
Yeah, it is better indeed. Would you mind if i schedule this for a little while later, since i have a couple of other fixes/additions as well ?
There's no need to hurry since the whole problem is only a small memory leak in a very unlikely case.
But when you'll apply it, please used the improved version below (based on a suggestion by Ingo Oeser).
Ok, i will apply the same thing.
Quoted 4 lines
cu
Adrian
Thanks,
Manu
Quoted 46 lines
The Coverity checker spotted that thre was a memory leak if the second or third
kmalloc()failed.Besides this, I've also consolidated the three error handlings into one and removed the unneeded casts.
Signed-off-by Adrian Bunk <[email protected]>---
drivers/media/dvb/bt8xx/dst_ca.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)drivers/media/dvb/bt8xx/dst_ca.c renamed from drivers/media/dvb/bt8xx/dst_ca.c.old +9
-10@@ -473,18 +473,17 @@ static int dst_ca_ioctl(struct inode *invoid __user *arg = (void __user *)ioctl_arg;int result =0 ; -if ((p_ca_message = (struct ca_msg *)kmalloc (sizeof (struct ca_msg ),GFP_KERNEL )) ==NULL ) { -dprintk (verbose,DST_CA_ERROR ,1 ," Memory allocation failure" ); -return -ENOMEM ; - } -if ((p_ca_slot_info = (struct ca_slot_info *)kmalloc (sizeof (struct ca_slot_info ),GFP_KERNEL )) ==NULL ) { -dprintk (verbose,DST_CA_ERROR ,1 ," Memory allocation failure" ); -return -ENOMEM ; - } -if ((p_ca_caps = (struct ca_caps *)kmalloc (sizeof (struct ca_caps ),GFP_KERNEL )) ==NULL ) { + p_ca_message =kmalloc (sizeof (struct ca_msg ),GFP_KERNEL ); + p_ca_slot_info =kmalloc (sizeof (struct ca_slot_info ),GFP_KERNEL ); + p_ca_caps =kmalloc (sizeof (struct ca_caps ),GFP_KERNEL ); + + +if (!p_ca_message || !p_ca_slot_info || !p_ca_caps) {dprintk (verbose,DST_CA_ERROR ,1 ," Memory allocation failure" ); -return -ENOMEM ; + result = -ENOMEM ; + goto free_mem_and_exit; } +/* We have now only the standard ioctl's, the driver is upposed to handle internals. */ switch (cmd) {case CA_SEND_MSG :