Split digest parameter freeing into a separate helper function
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 2 Nov 2011 08:26:34 +0000 (10:26 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Fri, 4 Nov 2011 09:50:08 +0000 (11:50 +0200)
- The data is all the same except for rsa/dsa specific bits,
  to me this calls for a function. We might want to export
  pgpCleanDigParams() or such later on but for now keep it static.
  No functional changes.

rpmio/rpmpgp.c

index 838b2f6..cb1b598 100644 (file)
@@ -1104,32 +1104,30 @@ pgpDig pgpNewDig(void)
     return dig;
 }
 
-void pgpCleanDig(pgpDig dig)
+static void pgpCleanDigParams(pgpDigParams digp)
 {
-    if (dig != NULL) {
-       int i;
-       dig->signature.userid = _free(dig->signature.userid);
-       dig->pubkey.userid = _free(dig->pubkey.userid);
-       dig->signature.hash = _free(dig->signature.hash);
-       dig->pubkey.hash = _free(dig->pubkey.hash);
-       /* FIX: double indirection */
-       for (i = 0; i < 4; i++) {
-           dig->signature.params[i] = _free(dig->signature.params[i]);
-           dig->pubkey.params[i] = _free(dig->pubkey.params[i]);
-       }
-
-       memset(&dig->signature, 0, sizeof(dig->signature));
-       memset(&dig->pubkey, 0, sizeof(dig->pubkey));
-
-       if (dig->pubkey.data != NULL) {
-           SECKEY_DestroyPublicKey(dig->pubkey.data);
-           dig->pubkey.data = NULL;
+    if (digp) {
+       free(digp->userid);
+       free(digp->hash);
+       for (int i = 0; i < 4; i++) 
+           free(digp->params[i]);
+
+       if (digp->data != NULL) {
+           if (digp->tag == PGPTAG_SIGNATURE) {
+               SECITEM_ZfreeItem(digp->data, PR_TRUE);
+           } else {
+               SECKEY_DestroyPublicKey(digp->data);
+           }
        }
+       memset(digp, 0, sizeof(*digp));
+    }
+}
 
-       if (dig->signature.data != NULL) {
-           SECITEM_ZfreeItem(dig->signature.data, PR_TRUE);
-           dig->signature.data = NULL;
-       }
+void pgpCleanDig(pgpDig dig)
+{
+    if (dig != NULL) {
+       pgpCleanDigParams(&dig->signature);
+       pgpCleanDigParams(&dig->pubkey);
     }
     return;
 }