From e41fa8a52ed261a4733ecfd0c02a7a0c953d8878 Mon Sep 17 00:00:00 2001 From: christos Date: Sun, 23 Apr 2006 16:57:22 +0000 Subject: [PATCH] Complete the FREE -> free transition and add more NULL checks for malloc returns. Although these cannot happen because M_WAITOK, the rest of the code does them already, so this is good for consistency. From Mindaugas --- sys/altq/altq_blue.c | 19 +++++++++++++++++-- sys/altq/altq_cbq.c | 12 ++++++------ sys/altq/altq_hfsc.c | 10 ++++++---- sys/altq/altq_red.c | 26 +++++++++++++------------- 4 files changed, 42 insertions(+), 25 deletions(-) diff --git a/sys/altq/altq_blue.c b/sys/altq/altq_blue.c index 92c63e135f13..d9eb54bffeba 100644 --- a/sys/altq/altq_blue.c +++ b/sys/altq/altq_blue.c @@ -1,4 +1,4 @@ -/* $NetBSD: altq_blue.c,v 1.13 2006/04/23 06:46:39 christos Exp $ */ +/* $NetBSD: altq_blue.c,v 1.14 2006/04/23 16:57:22 christos Exp $ */ /* $KAME: altq_blue.c,v 1.8 2002/01/07 11:25:40 kjc Exp $ */ /* @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: altq_blue.c,v 1.13 2006/04/23 06:46:39 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: altq_blue.c,v 1.14 2006/04/23 16:57:22 christos Exp $"); #if defined(__FreeBSD__) || defined(__NetBSD__) #include "opt_altq.h" @@ -212,12 +212,27 @@ blueioctl(dev, cmd, addr, flag, l) /* allocate and initialize blue_state_t */ rqp = malloc(sizeof(blue_queue_t), M_DEVBUF, M_WAITOK|M_ZERO); + if (rqp == NULL) { + error = ENOMEM; + break; + } rqp->rq_q = malloc(sizeof(class_queue_t), M_DEVBUF, M_WAITOK|M_ZERO); + if (rqp->rq_q == NULL) { + free(rqp, M_DEVBUF); + error = ENOMEM; + break; + } rqp->rq_blue = malloc(sizeof(blue_t), M_DEVBUF, M_WAITOK|M_ZERO); + if (rqp->rq_blue == NULL) { + free(rqp->rq_q, M_DEVBUF); + free(rqp, M_DEVBUF); + error = ENOMEM; + break; + } rqp->rq_ifq = &ifp->if_snd; qtail(rqp->rq_q) = NULL; diff --git a/sys/altq/altq_cbq.c b/sys/altq/altq_cbq.c index 693b4076db2f..4787189762cb 100644 --- a/sys/altq/altq_cbq.c +++ b/sys/altq/altq_cbq.c @@ -1,4 +1,4 @@ -/* $NetBSD: altq_cbq.c,v 1.13 2006/04/23 06:46:40 christos Exp $ */ +/* $NetBSD: altq_cbq.c,v 1.14 2006/04/23 16:57:22 christos Exp $ */ /* $KAME: altq_cbq.c,v 1.11 2002/10/04 14:24:09 kjc Exp $ */ /* @@ -32,7 +32,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: altq_cbq.c,v 1.13 2006/04/23 06:46:40 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: altq_cbq.c,v 1.14 2006/04/23 16:57:22 christos Exp $"); #if defined(__FreeBSD__) || defined(__NetBSD__) #include "opt_altq.h" @@ -637,8 +637,8 @@ cbq_ifattach(ifacep) cbq_enqueue, cbq_dequeue, cbq_request, &new_cbqp->cbq_classifier, acc_classify); if (error) { - FREE(new_cbqp->cbq_class_tbl, M_DEVBUF); - FREE(new_cbqp, M_DEVBUF); + free(new_cbqp->cbq_class_tbl, M_DEVBUF); + free(new_cbqp, M_DEVBUF); return (error); } @@ -689,8 +689,8 @@ cbq_ifdetach(ifacep) } /* deallocate cbq_state_t */ - FREE(cbqp->cbq_class_tbl, M_DEVBUF); - FREE(cbqp, M_DEVBUF); + free(cbqp->cbq_class_tbl, M_DEVBUF); + free(cbqp, M_DEVBUF); return (0); } diff --git a/sys/altq/altq_hfsc.c b/sys/altq/altq_hfsc.c index 7d16943fbacd..32ec0cb6ee34 100644 --- a/sys/altq/altq_hfsc.c +++ b/sys/altq/altq_hfsc.c @@ -1,4 +1,4 @@ -/* $NetBSD: altq_hfsc.c,v 1.13 2006/04/23 06:46:40 christos Exp $ */ +/* $NetBSD: altq_hfsc.c,v 1.14 2006/04/23 16:57:22 christos Exp $ */ /* $KAME: altq_hfsc.c,v 1.9 2001/10/26 04:56:11 kjc Exp $ */ /* @@ -41,7 +41,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: altq_hfsc.c,v 1.13 2006/04/23 06:46:40 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: altq_hfsc.c,v 1.14 2006/04/23 16:57:22 christos Exp $"); #if defined(__FreeBSD__) || defined(__NetBSD__) #include "opt_altq.h" @@ -935,7 +935,8 @@ ellist_alloc() ellist_t *head; head = malloc(sizeof(ellist_t), M_DEVBUF, M_WAITOK); - TAILQ_INIT(head); + if (head != NULL) + TAILQ_INIT(head); return (head); } @@ -1046,7 +1047,8 @@ actlist_alloc() actlist_t *head; head = malloc(sizeof(actlist_t), M_DEVBUF, M_WAITOK); - TAILQ_INIT(head); + if (head != NULL) + TAILQ_INIT(head); return (head); } diff --git a/sys/altq/altq_red.c b/sys/altq/altq_red.c index 436474a54602..ac78c4931794 100644 --- a/sys/altq/altq_red.c +++ b/sys/altq/altq_red.c @@ -1,4 +1,4 @@ -/* $NetBSD: altq_red.c,v 1.14 2006/04/23 06:46:40 christos Exp $ */ +/* $NetBSD: altq_red.c,v 1.15 2006/04/23 16:57:22 christos Exp $ */ /* $KAME: altq_red.c,v 1.9 2002/01/07 11:25:40 kjc Exp $ */ /* @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: altq_red.c,v 1.14 2006/04/23 06:46:40 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: altq_red.c,v 1.15 2006/04/23 16:57:22 christos Exp $"); #if defined(__FreeBSD__) || defined(__NetBSD__) #include "opt_altq.h" @@ -321,8 +321,8 @@ redioctl(dev, cmd, addr, flag, l) rqp->rq_red = red_alloc(0, 0, 0, 0, 0, 0); if (rqp->rq_red == NULL) { - FREE(rqp->rq_q, M_DEVBUF); - FREE(rqp, M_DEVBUF); + free(rqp->rq_q, M_DEVBUF); + free(rqp, M_DEVBUF); error = ENOMEM; break; } @@ -341,8 +341,8 @@ redioctl(dev, cmd, addr, flag, l) NULL, NULL); if (error) { red_destroy(rqp->rq_red); - FREE(rqp->rq_q, M_DEVBUF); - FREE(rqp, M_DEVBUF); + free(rqp->rq_q, M_DEVBUF); + free(rqp, M_DEVBUF); break; } @@ -499,8 +499,8 @@ red_detach(rqp) } red_destroy(rqp->rq_red); - FREE(rqp->rq_q, M_DEVBUF); - FREE(rqp, M_DEVBUF); + free(rqp->rq_q, M_DEVBUF); + free(rqp, M_DEVBUF); return (error); } @@ -608,7 +608,7 @@ red_destroy(rp) fv_destroy(rp->red_flowvalve); #endif wtab_destroy(rp->red_wtab); - FREE(rp, M_DEVBUF); + free(rp, M_DEVBUF); } void @@ -1036,7 +1036,7 @@ wtab_destroy(w) break; } - FREE(w, M_DEVBUF); + free(w, M_DEVBUF); return (0); } @@ -1310,9 +1310,9 @@ fv_alloc(rp) static void fv_destroy(fv) struct flowvalve *fv; { - FREE(fv->fv_p2ftab, M_DEVBUF); - FREE(fv->fv_fves, M_DEVBUF); - FREE(fv, M_DEVBUF); + free(fv->fv_p2ftab, M_DEVBUF); + free(fv->fv_fves, M_DEVBUF); + free(fv, M_DEVBUF); } static inline int