diff options
author | Andrea Grandi <andrea.grandi@intel.com> | 2017-02-03 05:46:17 +0000 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2017-02-13 15:29:43 +0000 |
commit | f89dd6738a0ec2b6cfb05a3cc5fa38843dc27d2f (patch) | |
tree | 2c384b786b18925e62be3369518c4028fe77de49 /crypto/async | |
parent | f44e63644d29e5908be52b7896d5031a5cf460eb (diff) | |
download | openssl-f89dd6738a0ec2b6cfb05a3cc5fa38843dc27d2f.zip openssl-f89dd6738a0ec2b6cfb05a3cc5fa38843dc27d2f.tar.gz openssl-f89dd6738a0ec2b6cfb05a3cc5fa38843dc27d2f.tar.bz2 |
Remove fd from the list when the engine clears the wait context before pause
This fixes the num of fds added/removed returned by ASYNC_WAIT_CTX_get_changed_fds
Previously, the numbers were not consistent with the fds actually written in
the buffers since the fds that have been both added and removed are explicitly
ignored in the loop.
Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/2581)
Diffstat (limited to 'crypto/async')
-rw-r--r-- | crypto/async/async_wait.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/crypto/async/async_wait.c b/crypto/async/async_wait.c index e5ecaeb..50c150e 100644 --- a/crypto/async/async_wait.c +++ b/crypto/async/async_wait.c @@ -148,6 +148,33 @@ int ASYNC_WAIT_CTX_clear_fd(ASYNC_WAIT_CTX *ctx, const void *key) continue; } if (curr->key == key) { + /* If fd has just been added, remove it from the list */ + if (curr->add == 1) { + if (ctx->fds == curr) { + ctx->fds = curr->next; + } + else { + struct fd_lookup_st *prev = ctx->fds; + while (prev->next != curr && prev->next != NULL) { + prev = prev->next; + } + if (prev->next == NULL) { + return 1; + } + prev->next = curr->next; + } + + /* + * The fd has just been added so it can't be used externally + * and it is safe to call the cleanup function here + */ + if (curr->cleanup != NULL) + curr->cleanup(ctx, curr->key, curr->fd, curr->custom_data); + OPENSSL_free(curr); + ctx->numadd--; + return 1; + } + /* * Mark it as deleted. We don't call cleanup if explicitly asked * to clear an fd. We assume the caller is going to do that (if |