aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cynapses.org>2011-01-03 09:07:02 +0100
committerAndreas Schneider <asn@cynapses.org>2011-01-03 09:07:02 +0100
commitd679d5d7ef0171d77c26cfe2c1c740b330231770 (patch)
treef07db468604f376ac9bc4fe69bd3824b09fcd1d4 /src
parent2464a25de75a1a442b2cef5f7d2f63f84fab8c55 (diff)
downloadlibssh-d679d5d7ef0171d77c26cfe2c1c740b330231770.tar.gz
libssh-d679d5d7ef0171d77c26cfe2c1c740b330231770.tar.xz
libssh-d679d5d7ef0171d77c26cfe2c1c740b330231770.zip
poll: Ensure that the poll handle and ctx is zeroed.
Diffstat (limited to 'src')
-rw-r--r--src/poll.c43
1 files changed, 24 insertions, 19 deletions
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;
}
/**