lkml.org 
[lkml]   [2000]   [Aug]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] aironet4500_cs.c kmalloc checking
Em Tue, Aug 08, 2000 at 02:39:08PM -0500, Bill Wendling escreveu:
> Also sprach Arnaldo Carvalho de Melo:
> } /* Create the PC card device object. */
> } link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
> } - memset(link, 0, sizeof(struct dev_link_t));
> } + if (!link)
> } + return NULL;
> } +
> } link->dev = kmalloc(sizeof(struct dev_node_t), GFP_KERNEL);
> } +
> } + if (!link->dev) {
> } + kfree(link);
> } + return NULL;
> } + }
> } +
> } + memset(link, 0, sizeof(struct dev_link_t));
> } memset(link->dev, 0, sizeof(struct dev_node_t));
> }
> Are you sure this is correct? You are zeroing out the link structure

well spotted, yes, its wrong, thanks for pointing it out.

> (which includes the kmalloc'ed link->dev pointer) and then trying to zero
> out the link->dev pointer. It's a memory leak and NULL pointer reference.
> How about this instead:
>
> link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
>
> if (!link)
> return NULL;
>
> memset(link, 0, sizeof(struct dev_link_t));
> link->dev = kmalloc(sizeof(struct dev_node_t), GFP_KERNEL);
>
> if (!link->dev) {
> kfree(link);
> return NULL;
> }
>
> memset(link->dev, 0, sizeof(struct dev_node_t));
>
> } // dev = init_etherdev(0, sizeof(struct awc_private) );
> ^^ C++ style comments...blech! :)

better, yes, and the comments were not mine, blargh, but I try not to touch
that much, just trying to fix the problems, this is up to the maintainer to
use whatever kind of comments, or el penguino can ask him to change to /**/.

the idea was to just do the menset if the link->dev allocation was successful,
like I did in other drivers in this patch, but yes, coding at 3pm and without
a good amount of caffeine is not safe ;)

- Arnaldo

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:58    [W:0.062 / U:0.040 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site