From 165d5550eb3668154608da5722a38b550124ecfd Mon Sep 17 00:00:00 2001 From: glebius Date: Thu, 30 Aug 2012 12:18:45 +0000 Subject: [PATCH] In ifc_alloc_unit(): - In the !wildcard case, return ENOSPC instead of confusing EEXIST in case if ifc->ifc_maxunit reached. - Fix unit leak, that I've introduced in previous revision. Submitted by: Daan Vreeken --- sys/net/if_clone.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/sys/net/if_clone.c b/sys/net/if_clone.c index 5720fc4feae..3543e2f71fc 100644 --- a/sys/net/if_clone.c +++ b/sys/net/if_clone.c @@ -443,21 +443,30 @@ ifc_alloc_unit(struct if_clone *ifc, int *unit) wildcard = (*unit < 0); retry: - if (wildcard) { + if (*unit > ifc->ifc_maxunit) + return (ENOSPC); + if (*unit < 0) { *unit = alloc_unr(ifc->ifc_unrhdr); if (*unit == -1) return (ENOSPC); } else { *unit = alloc_unr_specific(ifc->ifc_unrhdr, *unit); - if (*unit == -1) - return (EEXIST); + if (*unit == -1) { + if (wildcard) { + (*unit)++; + goto retry; + } else + return (EEXIST); + } } snprintf(name, IFNAMSIZ, "%s%d", ifc->ifc_name, *unit); if (ifunit(name) != NULL) { - if (wildcard) - goto retry; /* XXXGL: yep, it's a unit leak */ - else + free_unr(ifc->ifc_unrhdr, *unit); + if (wildcard) { + (*unit)++; + goto retry; + } else return (EEXIST); } -- 2.45.2