Index: sys/kern/kern_environment.c
===================================================================
--- sys/kern/kern_environment.c
+++ sys/kern/kern_environment.c
@@ -673,16 +673,23 @@
 	uint8_t shift;
 	int64_t value;
 	int64_t old;
-	char *buf;
+	const char *buf;
 	char *end;
-	char *ptr;
+	const char *ptr;
 	int n;
 	int rc;
 
-	if ((buf = getenv_string_buffer(name)) == NULL)
-		return (0);
+	if (dynamic_kenv) {
+		mtx_lock(&kenv_lock);
+		buf = _getenv_dynamic(name, NULL);
+	} else
+		buf = _getenv_static(name);
 
 	rc = 0;			  /* assume failure */
+
+	if (buf == NULL)
+		goto error;
+
 	/* get maximum number of elements */
 	size /= type_size;
 
@@ -798,7 +805,7 @@
 		rc = 1;	/* success */
 error:
 	if (dynamic_kenv)
-		uma_zfree(kenv_zone, buf);
+		mtx_unlock(&kenv_lock);
 	return (rc);
 }
 
@@ -898,18 +905,26 @@
 int
 getenv_quad(const char *name, quad_t *data)
 {
-	char	*value, *vtp;
-	quad_t	iv;
+	const char	*value;
+	char		suffix, *vtp;
+	quad_t		iv;
 
-	value = getenv_string_buffer(name);
-	if (value == NULL)
-		return (0);
+	if (dynamic_kenv) {
+		mtx_lock(&kenv_lock);
+		value = _getenv_dynamic(name, NULL);
+	} else
+		value = _getenv_static(name);
+	if (value == NULL) {
+		goto error;
+	}
 	iv = strtoq(value, &vtp, 0);
 	if (vtp == value || (vtp[0] != '\0' && vtp[1] != '\0')) {
-		freeenv(value);
-		return (0);
+		goto error;
 	}
-	switch (vtp[0]) {
+	suffix = vtp[0];
+	if (dynamic_kenv)
+		mtx_unlock(&kenv_lock);
+	switch (suffix) {
 	case 't': case 'T':
 		iv *= 1024;
 		/* FALLTHROUGH */
@@ -924,12 +939,14 @@
 	case '\0':
 		break;
 	default:
-		freeenv(value);
 		return (0);
 	}
-	freeenv(value);
 	*data = iv;
 	return (1);
+error:
+	if (dynamic_kenv)
+		mtx_unlock(&kenv_lock);
+	return (0);
 }
 
 /*