Re: [PATCH] Allocate pnp resources dynamically via krealloc
- From: Thomas Renninger <trenn@xxxxxxx>
- Date: Sun, 20 Jan 2008 12:04:26 +0100
On Sun, 2008-01-20 at 02:23 +0200, Pekka Enberg wrote:
Hi Thomas,Thanks.
On Jan 19, 2008 10:00 PM, Thomas Renninger <trenn@xxxxxxx> wrote:
+static int pnp_alloc_port(struct pnp_resource_table *res)
+{
[snip]
+ res->port_resource = krealloc(res->port_resource,
+ (sizeof(struct resource) * res->allocated_ports)
+ + (sizeof(struct resource) * PNP_ALLOC_PORT), GFP_KERNEL);
+
+ if (!res->port_resource)
+ return -ENOMEM;
When krealloc() returns NULL, there wasn't enough memory to fit the
new size but the original memory region remains unchanged. Therefore
you must not unconditionally overwrite the res->port_resource with the
return value of krealloc(); otherwise you might leak memory.
While looking at this I found something else..., I think I sent an old
version.
Please hold off, I will double check and resend soon.
Thomas
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
- References:
- [PATCH] Allocate pnp resources dynamically via krealloc
- From: Thomas Renninger
- Re: [PATCH] Allocate pnp resources dynamically via krealloc
- From: Pekka Enberg
- [PATCH] Allocate pnp resources dynamically via krealloc
- Prev by Date: Re: linux device ordering at boot time
- Next by Date: Re: [i2c] [PATCH 19 3/5] Clean up error returns
- Previous by thread: Re: [PATCH] Allocate pnp resources dynamically via krealloc
- Next by thread: Re: [PATCH] Allocate pnp resources dynamically via krealloc - working version
- Index(es):
Relevant Pages
|