From d679d5d7ef0171d77c26cfe2c1c740b330231770 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Mon, 3 Jan 2011 09:07:02 +0100 Subject: poll: Ensure that the poll handle and ctx is zeroed. --- src/poll.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'src/poll.c') diff --git a/src/poll.c b/src/poll.c index 0ca0524a..4cea93fe 100644 --- a/src/poll.c +++ b/src/poll.c @@ -306,18 +306,24 @@ int ssh_poll(ssh_pollfd_t *fds, nfds_t nfds, int timeout) { ssh_poll_handle ssh_poll_new(socket_t fd, short events, ssh_poll_callback cb, void *userdata) { - ssh_poll_handle p; + ssh_poll_handle p; + + p = malloc(sizeof(struct ssh_poll_handle_struct)); + if (p == NULL) { + return NULL; + } + ZERO_STRUCTP(p); - p = malloc(sizeof(struct ssh_poll_handle_struct)); - if (p != NULL) { - p->ctx = NULL; p->x.fd = fd; p->events = events; - p->cb = cb; - p->cb_data = userdata; - } + if (cb != NULL) { + p->cb = cb; + } + if (userdata != NULL) { + p->cb_data = userdata; + } - return p; + return p; } @@ -450,22 +456,21 @@ void ssh_poll_set_callback(ssh_poll_handle p, ssh_poll_callback cb, void *userda * library's default value. */ ssh_poll_ctx ssh_poll_ctx_new(size_t chunk_size) { - ssh_poll_ctx ctx; + ssh_poll_ctx ctx; - ctx = malloc(sizeof(struct ssh_poll_ctx_struct)); - if (ctx != NULL) { - if (!chunk_size) { - chunk_size = SSH_POLL_CTX_CHUNK; + ctx = malloc(sizeof(struct ssh_poll_ctx_struct)); + if (ctx == NULL) { + return NULL; + } + ZERO_STRUCTP(ctx); + + if (chunk_size == 0) { + chunk_size = SSH_POLL_CTX_CHUNK; } ctx->chunk_size = chunk_size; - ctx->pollptrs = NULL; - ctx->pollfds = NULL; - ctx->polls_allocated = 0; - ctx->polls_used = 0; - } - return ctx; + return ctx; } /** -- cgit v1.2.1