Hi all,

Coverity is pointing out that we are doing pointer-NULL checks on
things that cannot be NULL in decrypt_internal():
 out:
-       if (src)
-               mbuf_free(src);
-       if (ctx)
-               pgp_free(ctx);
+       Assert(ctx != NULL && src != NULL && dst != NULL);
+       mbuf_free(src);
+       pgp_free(ctx);

        if (err)
        {
                px_set_debug_handler(NULL);
-               if (dst)
-                       mbuf_free(dst);
+               mbuf_free(dst);

src, dst and ctx are created respectively from mbuf_create_from_data,
mbuf_create and pgp_init which never return NULL and they are palloc'd
all the time. I think that we could simplify things with the patch
attached, note that I added an assertion for correctness but I don't
really think that it is much necessary.
Regards,
-- 
Michael
diff --git a/contrib/pgcrypto/pgp-pgsql.c b/contrib/pgcrypto/pgp-pgsql.c
index 1a0e710..af1a990 100644
--- a/contrib/pgcrypto/pgp-pgsql.c
+++ b/contrib/pgcrypto/pgp-pgsql.c
@@ -594,16 +594,14 @@ decrypt_internal(int is_pubenc, int need_text, text *data,
 	got_unicode = pgp_get_unicode_mode(ctx);
 
 out:
-	if (src)
-		mbuf_free(src);
-	if (ctx)
-		pgp_free(ctx);
+	Assert(ctx != NULL && src != NULL && dst != NULL);
+	mbuf_free(src);
+	pgp_free(ctx);
 
 	if (err)
 	{
 		px_set_debug_handler(NULL);
-		if (dst)
-			mbuf_free(dst);
+		mbuf_free(dst);
 		ereport(ERROR,
 				(errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION),
 				 errmsg("%s", px_strerror(err))));
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to