* [2.6 patch] drivers/media/dvb/bt8xx/dst_ca.c: fix 2 memory leaks
@ 2006-03-11 15:11 Adrian Bunk
2006-03-11 15:53 ` Manu Abraham
0 siblings, 1 reply; 5+ messages in thread
From: Adrian Bunk @ 2006-03-11 15:11 UTC (permalink / raw)
To: mchehab; +Cc: v4l-dvb-maintainer, linux-kernel
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 <bunk@stusta.de>
---
drivers/media/dvb/bt8xx/dst_ca.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
--- linux-2.6.16-rc5-mm3-full/drivers/media/dvb/bt8xx/dst_ca.c.old 2006-03-11 14:36:59.000000000 +0100
+++ linux-2.6.16-rc5-mm3-full/drivers/media/dvb/bt8xx/dst_ca.c 2006-03-11 15:28:26.000000000 +0100
@@ -473,18 +473,17 @@ static int dst_ca_ioctl(struct inode *in
void __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:
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [2.6 patch] drivers/media/dvb/bt8xx/dst_ca.c: fix 2 memory leaks
2006-03-11 15:11 [2.6 patch] drivers/media/dvb/bt8xx/dst_ca.c: fix 2 memory leaks Adrian Bunk
@ 2006-03-11 15:53 ` Manu Abraham
2006-03-11 16:12 ` Adrian Bunk
0 siblings, 1 reply; 5+ messages in thread
From: Manu Abraham @ 2006-03-11 15:53 UTC (permalink / raw)
To: Adrian Bunk; +Cc: mchehab, v4l-dvb-maintainer, linux-kernel
Adrian Bunk wrote:
> 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 <bunk@stusta.de>
>
> ---
>
> drivers/media/dvb/bt8xx/dst_ca.c | 19 +++++++++----------
> 1 file changed, 9 insertions(+), 10 deletions(-)
>
> --- linux-2.6.16-rc5-mm3-full/drivers/media/dvb/bt8xx/dst_ca.c.old 2006-03-11 14:36:59.000000000 +0100
> +++ linux-2.6.16-rc5-mm3-full/drivers/media/dvb/bt8xx/dst_ca.c 2006-03-11 15:28:26.000000000 +0100
> @@ -473,18 +473,17 @@ static int dst_ca_ioctl(struct inode *in
> void __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:
>
> -
>
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [2.6 patch] drivers/media/dvb/bt8xx/dst_ca.c: fix 2 memory leaks
2006-03-11 15:53 ` Manu Abraham
@ 2006-03-11 16:12 ` Adrian Bunk
2006-03-11 18:44 ` Adrian Bunk
0 siblings, 1 reply; 5+ messages in thread
From: Adrian Bunk @ 2006-03-11 16:12 UTC (permalink / raw)
To: Manu Abraham; +Cc: mchehab, v4l-dvb-maintainer, linux-kernel
On Sat, Mar 11, 2006 at 07:53:34PM +0400, Manu Abraham wrote:
>
> 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.
> Thanks,
> Manu
cu
Adrian
--
"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 Seed
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [2.6 patch] drivers/media/dvb/bt8xx/dst_ca.c: fix 2 memory leaks
2006-03-11 18:44 ` Adrian Bunk
@ 2006-03-11 18:33 ` Manu Abraham
0 siblings, 0 replies; 5+ messages in thread
From: Manu Abraham @ 2006-03-11 18:33 UTC (permalink / raw)
To: Adrian Bunk; +Cc: mchehab, v4l-dvb-maintainer, linux-kernel
Adrian Bunk wrote:
> On Sat, Mar 11, 2006 at 05:12:13PM +0100, Adrian Bunk wrote:
>
>> On Sat, Mar 11, 2006 at 07:53:34PM +0400, Manu Abraham wrote:
>>
>>> 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.
> cu
> Adrian
>
>
Thanks,
Manu
> 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 <bunk@stusta.de>
>
> ---
>
> drivers/media/dvb/bt8xx/dst_ca.c | 19 +++++++++----------
> 1 file changed, 9 insertions(+), 10 deletions(-)
>
> --- linux-2.6.16-rc5-mm3-full/drivers/media/dvb/bt8xx/dst_ca.c.old 2006-03-11 14:36:59.000000000 +0100
> +++ linux-2.6.16-rc5-mm3-full/drivers/media/dvb/bt8xx/dst_ca.c 2006-03-11 15:28:26.000000000 +0100
> @@ -473,18 +473,17 @@ static int dst_ca_ioctl(struct inode *in
> void __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:
>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [2.6 patch] drivers/media/dvb/bt8xx/dst_ca.c: fix 2 memory leaks
2006-03-11 16:12 ` Adrian Bunk
@ 2006-03-11 18:44 ` Adrian Bunk
2006-03-11 18:33 ` Manu Abraham
0 siblings, 1 reply; 5+ messages in thread
From: Adrian Bunk @ 2006-03-11 18:44 UTC (permalink / raw)
To: Manu Abraham; +Cc: mchehab, v4l-dvb-maintainer, linux-kernel
On Sat, Mar 11, 2006 at 05:12:13PM +0100, Adrian Bunk wrote:
> On Sat, Mar 11, 2006 at 07:53:34PM +0400, Manu Abraham wrote:
> >
> > 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.
Signed-off-by: Adrian Bunk <bunk@stusta.de>
---
drivers/media/dvb/bt8xx/dst_ca.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
--- linux-2.6.16-rc5-mm3-full/drivers/media/dvb/bt8xx/dst_ca.c.old 2006-03-11 14:36:59.000000000 +0100
+++ linux-2.6.16-rc5-mm3-full/drivers/media/dvb/bt8xx/dst_ca.c 2006-03-11 15:28:26.000000000 +0100
@@ -473,18 +473,17 @@ static int dst_ca_ioctl(struct inode *in
void __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:
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-03-11 18:49 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-11 15:11 [2.6 patch] drivers/media/dvb/bt8xx/dst_ca.c: fix 2 memory leaks Adrian Bunk
2006-03-11 15:53 ` Manu Abraham
2006-03-11 16:12 ` Adrian Bunk
2006-03-11 18:44 ` Adrian Bunk
2006-03-11 18:33 ` Manu Abraham
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox