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
This commit is contained in:
christos 2006-04-23 16:57:22 +00:00
parent 66784c2d94
commit e41fa8a52e
4 changed files with 42 additions and 25 deletions

View File

@ -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 <sys/cdefs.h>
__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;

View File

@ -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 <sys/cdefs.h>
__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);
}

View File

@ -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 <sys/cdefs.h>
__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);
}

View File

@ -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 <sys/cdefs.h>
__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