[svn] gpgme - r1380 - trunk/src

svn author marcus cvs at cvs.gnupg.org
Thu Jun 18 14:38:55 CEST 2009


Author: marcus
Date: 2009-06-18 14:38:55 +0200 (Thu, 18 Jun 2009)
New Revision: 1380

Modified:
   trunk/src/ChangeLog
   trunk/src/context.h
   trunk/src/gpgme.c
   trunk/src/op-support.c
Log:
2009-06-18  Marcus Brinkmann  <marcus at g10code.de>

	* 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.


Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2009-06-17 13:42:52 UTC (rev 1379)
+++ trunk/src/ChangeLog	2009-06-18 12:38:55 UTC (rev 1380)
@@ -1,3 +1,10 @@
+2009-06-18  Marcus Brinkmann  <marcus at g10code.de>
+
+	* 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  <marcus at g10code.de>
 
 	* gpgme.c (gpgme_result_unref): Hot fix to release a lock.

Modified: trunk/src/context.h
===================================================================
--- trunk/src/context.h	2009-06-17 13:42:52 UTC (rev 1379)
+++ trunk/src/context.h	2009-06-18 12:38:55 UTC (rev 1380)
@@ -42,8 +42,14 @@
   } 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;

Modified: trunk/src/gpgme.c
===================================================================
--- trunk/src/gpgme.c	2009-06-17 13:42:52 UTC (rev 1379)
+++ trunk/src/gpgme.c	2009-06-18 12:38:55 UTC (rev 1380)
@@ -189,6 +189,8 @@
 
   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 @@
 
   data = result - sizeof (struct ctx_op_data);
 
+  assert (data->magic == CTX_OP_DATA_MAGIC);
+
   LOCK (result_ref_lock);
   if (--data->references)
     {

Modified: trunk/src/op-support.c
===================================================================
--- trunk/src/op-support.c	2009-06-17 13:42:52 UTC (rev 1379)
+++ trunk/src/op-support.c	2009-06-18 12:38:55 UTC (rev 1380)
@@ -48,6 +48,7 @@
       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;




More information about the Gnupg-commits mailing list