[PATCH v2] Mark constant MPIs as non-leaked

Peter Wu peter at lekensteyn.nl
Thu Mar 24 14:04:27 CET 2016


* mpi/mpiutil.c: Mark "constant" MPIs as explicitly leaked.
--

Requires libgpg-error 1.22 (unreleased) for the macros, but since it is
a minor debugging aid, do not bump the minimum required version.

Signed-off-by: Peter Wu <peter at lekensteyn.nl>
---
 v2: mark as non-leaked when the const flag is set, not just on the free
     path.  This avoids a warning on constants from _gcry_mpi_init.
---
 mpi/mpiutil.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/mpi/mpiutil.c b/mpi/mpiutil.c
index 99402b8..142c74e 100644
--- a/mpi/mpiutil.c
+++ b/mpi/mpiutil.c
@@ -61,7 +61,7 @@ _gcry_mpi_init (void)
         default: log_bug ("invalid mpi_const selector %d\n", idx);
         }
       constants[idx] = mpi_alloc_set_ui (value);
-      constants[idx]->flags = (16|32);
+      _gcry_mpi_set_flag(constants[idx], GCRYMPI_FLAG_CONST);
     }
 
   return 0;
@@ -665,7 +665,12 @@ _gcry_mpi_set_flag (gcry_mpi_t a, enum gcry_mpi_flag flag)
   switch (flag)
     {
     case GCRYMPI_FLAG_SECURE:     mpi_set_secure(a); break;
-    case GCRYMPI_FLAG_CONST:      a->flags |= (16|32); break;
+    case GCRYMPI_FLAG_CONST:
+      a->flags |= (16|32);
+#if GPGRT_VERSION_NUMBER >= 0x011600  /* 1.22 */
+      gpgrt_annotate_leaked_object(a);
+#endif
+      break;
     case GCRYMPI_FLAG_IMMUTABLE:  a->flags |= 16; break;
 
     case GCRYMPI_FLAG_USER1:
-- 
2.7.4




More information about the Gcrypt-devel mailing list