Re: [PATCH] Allocate pnp resources dynamically via krealloc




On Sun, 2008-01-20 at 02:23 +0200, Pekka Enberg wrote:
Hi Thomas,

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.

Thanks.
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/



Relevant Pages

  • Re: [PATCH] Allocate pnp resources dynamically via krealloc
    ... When krealloc() returns NULL, there wasn't enough memory to fit the ... new size but the original memory region remains unchanged. ...
    (Linux-Kernel)
  • Re: [BUG] SLOBs krealloc() seems bust
    ... Which made me look at which slab allocator I had selected, ... krealloc() is in generic core code and is the same for all allocators. ... Is the krealloc used on memory allocated with kmalloc? ... Slob's ksize could use a BUG_ON for the case in which ksizeis used on ...
    (Linux-Kernel)
  • Re: [BUG] SLOBs krealloc() seems bust
    ... Which made me look at which slab allocator I had selected, ... out to be SLOB. ... krealloc() is in generic core code and is the same for all allocators. ... Is the krealloc used on memory allocated with kmalloc? ...
    (Linux-Kernel)
  • Re: Q: too much data too little memory
    ... with a large chunk of data that does not fit into all the ... | physical memory available to a computer, is it better, to run one process ... If your machine has enough physical RAM to actually swap in all of the ...
    (comp.unix.programmer)
  • Re: "Program too big to fit in memory". Urgent please help
    ... 'Program too big to fit into memory' ... I used to keep all the Installers in a folder for future use. ... The files in the `Installers' folder on my hard disk were readble but I forgot to take another backup. ...
    (microsoft.public.windowsxp.general)