From 3ab899f41cda31ab763da9e73e95981dcf3d5b7f Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Thu, 18 Jun 2009 12:38:55 +0000 Subject: [PATCH] 2009-06-18 Marcus Brinkmann * context.h (CTX_OP_DATA_MAGIC): New macro. (struct ctx_op_data): New member MAGIC. * op-support.c (_gpgme_op_data_lookup): Initialize magic. * gpgme.c (gpgme_result_unref, gpgme_result_ref): Check magic. --- src/ChangeLog | 7 +++++++ src/context.h | 6 ++++++ src/gpgme.c | 4 ++++ src/op-support.c | 1 + 4 files changed, 18 insertions(+) diff --git a/src/ChangeLog b/src/ChangeLog index d7b4592..95b5f2d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2009-06-18 Marcus Brinkmann + + * context.h (CTX_OP_DATA_MAGIC): New macro. + (struct ctx_op_data): New member MAGIC. + * op-support.c (_gpgme_op_data_lookup): Initialize magic. + * gpgme.c (gpgme_result_unref, gpgme_result_ref): Check magic. + 2009-06-16 Marcus Brinkmann * gpgme.c (gpgme_result_unref): Hot fix to release a lock. diff --git a/src/context.h b/src/context.h index 63af1d1..e98e7be 100644 --- a/src/context.h +++ b/src/context.h @@ -42,8 +42,14 @@ typedef enum } ctx_op_data_id_t; +/* "gpgmeres" in ASCII. */ +#define CTX_OP_DATA_MAGIC 0x736572656d677067ULL struct ctx_op_data { + /* A magic word just to make sure people don't deallocate something + that ain't a result structure. */ + unsigned long long magic; + /* The next element in the linked list, or NULL if this is the last element. Used by op data structures linked into a context. */ struct ctx_op_data *next; diff --git a/src/gpgme.c b/src/gpgme.c index 3283b34..56caf59 100644 --- a/src/gpgme.c +++ b/src/gpgme.c @@ -189,6 +189,8 @@ gpgme_result_ref (void *result) data = result - sizeof (struct ctx_op_data); + assert (data->magic == CTX_OP_DATA_MAGIC); + LOCK (result_ref_lock); data->references++; UNLOCK (result_ref_lock); @@ -205,6 +207,8 @@ gpgme_result_unref (void *result) data = result - sizeof (struct ctx_op_data); + assert (data->magic == CTX_OP_DATA_MAGIC); + LOCK (result_ref_lock); if (--data->references) { diff --git a/src/op-support.c b/src/op-support.c index 19b2420..c3ba778 100644 --- a/src/op-support.c +++ b/src/op-support.c @@ -48,6 +48,7 @@ _gpgme_op_data_lookup (gpgme_ctx_t ctx, ctx_op_data_id_t type, void **hook, data = calloc (1, sizeof (struct ctx_op_data) + size); if (!data) return gpg_error_from_errno (errno); + data->magic = CTX_OP_DATA_MAGIC; data->next = ctx->op_data; data->type = type; data->cleanup = cleanup; -- 2.26.2