svn commit: r212073 - head/lib/libjail
Jamie Gritton
jamie at FreeBSD.org
Tue Aug 31 21:50:09 UTC 2010
Author: jamie
Date: Tue Aug 31 21:50:09 2010
New Revision: 212073
URL: http://svn.freebsd.org/changeset/base/212073
Log:
Don't over-allocate array values in jailparam_export.
Fix a little comment typo.
MFC after: 3 days
Modified:
head/lib/libjail/jail.c
Modified: head/lib/libjail/jail.c
==============================================================================
--- head/lib/libjail/jail.c Tue Aug 31 21:48:45 2010 (r212072)
+++ head/lib/libjail/jail.c Tue Aug 31 21:50:09 2010 (r212073)
@@ -719,6 +719,7 @@ jailparam_get(struct jailparam *jp, unsi
char *
jailparam_export(struct jailparam *jp)
{
+ size_t *valuelens;
char *value, *tvalue, **values;
size_t valuelen;
int i, nval, ival;
@@ -740,6 +741,7 @@ jailparam_export(struct jailparam *jp)
return (value);
}
values = alloca(nval * sizeof(char *));
+ valuelens = alloca(nval * sizeof(size_t));
valuelen = 0;
for (i = 0; i < nval; i++) {
switch (jp->jp_ctltype & CTLTYPE) {
@@ -809,11 +811,12 @@ jailparam_export(struct jailparam *jp)
errno = ENOENT;
return (NULL);
}
- valuelen += strlen(valbuf) + 1;
- values[i] = alloca(valuelen);
+ valuelens[i] = strlen(valbuf) + 1;
+ valuelen += valuelens[i];
+ values[i] = alloca(valuelens[i]);
strcpy(values[i], valbuf);
}
- value = malloc(valuelen + 1);
+ value = malloc(valuelen);
if (value == NULL)
strerror_r(errno, jail_errmsg, JAIL_ERRMSGLEN);
else {
@@ -821,8 +824,8 @@ jailparam_export(struct jailparam *jp)
for (i = 0; i < nval; i++) {
strcpy(tvalue, values[i]);
if (i < nval - 1) {
- tvalue += strlen(values[i]);
- *tvalue++ = ',';
+ tvalue += valuelens[i];
+ tvalue[-1] = ',';
}
}
}
@@ -830,7 +833,7 @@ jailparam_export(struct jailparam *jp)
}
/*
- * Free the contents of a jail parameter list (but not thst list itself).
+ * Free the contents of a jail parameter list (but not the list itself).
*/
void
jailparam_free(struct jailparam *jp, unsigned njp)
More information about the svn-src-head
mailing list