From 51566e9c8598cc890fd4f4a77c44ed549497483f Mon Sep 17 00:00:00 2001 From: christos Date: Sun, 19 Mar 2006 20:02:27 +0000 Subject: [PATCH] Coverity CID 1553: Fix memory leak. While here, fix malloc calls: - don't cast - use sizeof(var) instead of sizeof(type) --- lib/libform/field_types.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/libform/field_types.c b/lib/libform/field_types.c index 20b1df9de521..db7e59ae068b 100644 --- a/lib/libform/field_types.c +++ b/lib/libform/field_types.c @@ -1,4 +1,4 @@ -/* $NetBSD: field_types.c,v 1.6 2003/03/09 00:57:17 lukem Exp $ */ +/* $NetBSD: field_types.c,v 1.7 2006/03/19 20:02:27 christos Exp $ */ /*- * Copyright (c) 1998-1999 Brett Lymn @@ -30,7 +30,7 @@ */ #include -__RCSID("$NetBSD: field_types.c,v 1.6 2003/03/09 00:57:17 lukem Exp $"); +__RCSID("$NetBSD: field_types.c,v 1.7 2006/03/19 20:02:27 christos Exp $"); #include #include @@ -59,8 +59,7 @@ _formi_create_field_args(FIELDTYPE *type, char **type_args, if ((type != NULL) && ((type->flags & _TYPE_HAS_ARGS) == _TYPE_HAS_ARGS)) { if ((type->flags & _TYPE_IS_LINKED) == _TYPE_IS_LINKED) { - l = (formi_type_link *) - malloc(sizeof(formi_type_link)); + l = malloc(sizeof(*l)); if (l != NULL) { _formi_create_field_args(type->link->next, type_args, @@ -93,7 +92,7 @@ _formi_create_fieldtype(void) { FIELDTYPE *new; - if ((new = (FIELDTYPE *) malloc(sizeof(FIELDTYPE))) == NULL) + if ((new = malloc(sizeof(*new))) == NULL) return NULL; new->flags = _TYPE_NO_FLAGS; @@ -261,8 +260,10 @@ link_fieldtype(FIELDTYPE *type1, FIELDTYPE *type2) new->flags = _TYPE_IS_LINKED; new->flags |= ((type1->flags & _TYPE_HAS_ARGS) | (type2->flags & _TYPE_HAS_ARGS)); - if ((new->link = (_FORMI_TYPE_LINK*) malloc(sizeof(_FORMI_TYPE_LINK))) == NULL) + if ((new->link = malloc(sizeof(*new->link))) == NULL) { + free(new); return NULL; + } new->link->prev = type1; new->link->next = type2;