From 9bb329f4e548b45dd1a045a1130fa138b0aebfb9 Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Sat, 26 Mar 2005 21:07:35 +0000 Subject: [PATCH] fix a "modify after free" bug which is practically impossible to experience. Found by: Coverity (id #540 #541) --- sys/geom/geom_subr.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sys/geom/geom_subr.c b/sys/geom/geom_subr.c index dc2c8ad4701..4af0d4a129f 100644 --- a/sys/geom/geom_subr.c +++ b/sys/geom/geom_subr.c @@ -82,10 +82,11 @@ g_load_class(void *arg, int flag) hh = arg; mp = hh->mp; - if (hh->post) + hh->error = 0; + if (hh->post) { g_free(hh); - else - hh->error = 0; + hh = NULL; + } g_trace(G_T_TOPOLOGY, "g_load_class(%s)", mp->name); KASSERT(mp->name != NULL && *mp->name != '\0', ("GEOM class has no name")); @@ -93,12 +94,14 @@ g_load_class(void *arg, int flag) if (mp2 == mp) { printf("The GEOM class %s is already loaded.\n", mp2->name); - hh->error = EEXIST; + if (hh != NULL) + hh->error = EEXIST; return; } else if (strcmp(mp2->name, mp->name) == 0) { printf("A GEOM class %s is already loaded.\n", mp2->name); - hh->error = EEXIST; + if (hh != NULL) + hh->error = EEXIST; return; } }