Re: [PATCH] Trivial patch against mempool

From: Balbir Singh (balbir_soni@hotmail.com)
Date: Fri Feb 22 2002 - 16:59:16 EST


You are absoultely correct. The correct patch is

--- mempool.c.org Fri Feb 22 12:00:58 2002
+++ mempool.c Fri Feb 22 15:01:02 2002
@@ -34,6 +34,9 @@
        mempool_t *pool;
        int i;

+ if (!alloc_fn || !free_fn)
+ return NULL;
+
        pool = kmalloc(sizeof(*pool), GFP_KERNEL);
        if (!pool)
                return NULL;

Balbir Singh.

>From: Marcus Alanen <marcus@infa.abo.fi>
>To: balbir_soni@hotmail.com, linux-kernel@vger.kernel.org
>Subject: Re: [PATCH] Trivial patch against mempool
>Date: Fri, 22 Feb 2002 23:40:43 +0200
>
> >Check if the alloc_fn and free_fn are not NULL. The caller generally
> >ensures that alloc_fn and free_fn are valid. It would not harm
> >to check. This makes the checking in mempool_create() more complete.
> >
> >
> >--- mempool.c.org Fri Feb 22 12:00:58 2002
> >+++ mempool.c Fri Feb 22 12:01:13 2002
> >@@ -35,7 +35,7 @@
> > int i;
> >
> > pool = kmalloc(sizeof(*pool), GFP_KERNEL);
> >- if (!pool)
> >+ if (!pool || !alloc_fn || !free_fn)
> > return NULL;
> > memset(pool, 0, sizeof(*pool));
> >
>
>A successful allocation with alloc_fn or free_fn equal to NULL
>would return NULL, without freeing pool. => This check would
>leak memory? Wouldn't it be better to check for !alloc_fn || !free_fn
>before the kmalloc()
>
>
>--
>Marcus Alanen
>maalanen@abo.fi

_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com

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



This archive was generated by hypermail 2b29 : Sat Feb 23 2002 - 21:00:46 EST