Make all *_impl provide ctx_new and ctx_free functions
This commit is contained in:
parent
fa489d2b4b
commit
e9bcc64e62
6 changed files with 54 additions and 32 deletions
18
cipher.c
18
cipher.c
|
@ -82,18 +82,16 @@ struct lc_cipher_ctx *
|
|||
lc_cipher_ctx_new(const struct lc_cipher_impl *impl)
|
||||
{
|
||||
struct lc_cipher_ctx *ctx;
|
||||
void *arg;
|
||||
|
||||
ctx = malloc(sizeof(*ctx));
|
||||
if (ctx == NULL)
|
||||
return NULL;
|
||||
if (impl->argsz > 0) {
|
||||
arg = malloc(impl->argsz);
|
||||
if (arg == NULL) {
|
||||
if (impl->ctx_new != NULL) {
|
||||
ctx->arg = impl->ctx_new(NULL);
|
||||
if (ctx->arg == NULL) {
|
||||
free(ctx);
|
||||
return NULL;
|
||||
}
|
||||
ctx->arg = arg;
|
||||
} else
|
||||
ctx->arg = NULL;
|
||||
ctx->impl = impl;
|
||||
|
@ -104,7 +102,11 @@ lc_cipher_ctx_new(const struct lc_cipher_impl *impl)
|
|||
void
|
||||
lc_cipher_ctx_free(struct lc_cipher_ctx *ctx)
|
||||
{
|
||||
if (ctx != NULL)
|
||||
free(ctx->arg);
|
||||
free(ctx);
|
||||
if (ctx != NULL && ctx->impl != NULL && ctx->impl->ctx_free != NULL)
|
||||
ctx->impl->ctx_free(ctx);
|
||||
else {
|
||||
if (ctx != NULL)
|
||||
free(ctx->arg);
|
||||
free(ctx);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue