probably leaking less memory
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@1634 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -193,17 +193,21 @@ vasnprintf (char **ret, size_t max_sz, const char *format, va_list args)
|
|||||||
|
|
||||||
st = xyzprintf (&state, format, args);
|
st = xyzprintf (&state, format, args);
|
||||||
if (st) {
|
if (st) {
|
||||||
|
free (state.str);
|
||||||
*ret = NULL;
|
*ret = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
*state.s = '\0';
|
*state.s = '\0';
|
||||||
len = state.s - state.str;
|
len = state.s - state.str;
|
||||||
state.str = realloc (state.str, len+1);
|
tmp = realloc (state.str, len+1);
|
||||||
if (state.str == NULL) {
|
if (state.str == NULL) {
|
||||||
|
free (state.str);
|
||||||
*ret = NULL;
|
*ret = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
*ret = state.str;
|
*ret = tmp;
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -256,14 +260,16 @@ as_reserve (struct state *state, size_t n)
|
|||||||
{
|
{
|
||||||
while (state->s + n > state->theend) {
|
while (state->s + n > state->theend) {
|
||||||
int off = state->s - state->str;
|
int off = state->s - state->str;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
if (state->max_sz && state->sz >= state->max_sz)
|
if (state->max_sz && state->sz >= state->max_sz)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
state->sz = min(state->max_sz, state->sz*2);
|
state->sz = min(state->max_sz, state->sz*2);
|
||||||
state->str = realloc (state->str, state->sz);
|
tmp = realloc (state->str, state->sz);
|
||||||
if (state->str == NULL)
|
if (tmp == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
|
state->str = tmp;
|
||||||
state->s = state->str + off;
|
state->s = state->str + off;
|
||||||
state->theend = state->str + state->sz - 1;
|
state->theend = state->str + state->sz - 1;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user