mirror of
https://github.com/X11Libre/xserver.git
synced 2026-03-24 05:54:08 +00:00
dix: rpcbuf: flag for auto-clear in error case
when the err_clear flag is set, the buffer memory will automatically be free()ed when allocation failed. This allows simplificatoin of caller's error pathes: the caller doesn't need to to call x_rpcbuf_clear() anymore and eg. can directly return out. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
21
dix/rpcbuf.c
21
dix/rpcbuf.c
@@ -16,10 +16,8 @@ Bool x_rpcbuf_makeroom(struct x_rpcbuf *rpcbuf, size_t needed)
|
||||
|
||||
/* not allocated yet ? */
|
||||
if (!rpcbuf->buffer) {
|
||||
if (!(rpcbuf->buffer = calloc(1, XLIBRE_RPCBUF_CHUNK_SIZE))) {
|
||||
rpcbuf->error = TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
if (!(rpcbuf->buffer = calloc(1, XLIBRE_RPCBUF_CHUNK_SIZE)))
|
||||
goto err;
|
||||
rpcbuf->size = XLIBRE_RPCBUF_CHUNK_SIZE;
|
||||
rpcbuf->wpos = 0;
|
||||
}
|
||||
@@ -32,15 +30,22 @@ Bool x_rpcbuf_makeroom(struct x_rpcbuf *rpcbuf, size_t needed)
|
||||
* XLIBRE_RPCBUF_CHUNK_SIZE;
|
||||
|
||||
char *newbuf = realloc(rpcbuf->buffer, newsize);
|
||||
if (!newbuf) {
|
||||
rpcbuf->error = TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
if (!newbuf)
|
||||
goto err;
|
||||
|
||||
memset(newbuf + rpcbuf->size, 0, newsize - rpcbuf->size);
|
||||
rpcbuf->buffer = newbuf;
|
||||
rpcbuf->size = newsize;
|
||||
|
||||
return TRUE;
|
||||
|
||||
err:
|
||||
rpcbuf->error = TRUE;
|
||||
if (rpcbuf->err_clear) {
|
||||
free(rpcbuf->buffer);
|
||||
rpcbuf->buffer = NULL;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void x_rpcbuf_clear(struct x_rpcbuf *rpcbuf)
|
||||
|
||||
Reference in New Issue
Block a user