Commit 3cd0920cde6a726b9965b60184f9d5a54358304d

Authored by David Howells
1 parent 54e2c2c1a9

PKCS#7: Provide a single place to do signed info block freeing

The code to free a signed info block is repeated several times, so move the
code to do it into a function of its own.  This gives us a place to add clean
ups for stuff that gets added to pkcs7_signed_info.

Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>

Showing 1 changed file with 15 additions and 9 deletions Side-by-side Diff

crypto/asymmetric_keys/pkcs7_parser.c
... ... @@ -31,6 +31,18 @@
31 31 unsigned sinfo_index;
32 32 };
33 33  
  34 +/*
  35 + * Free a signed information block.
  36 + */
  37 +static void pkcs7_free_signed_info(struct pkcs7_signed_info *sinfo)
  38 +{
  39 + if (sinfo) {
  40 + mpi_free(sinfo->sig.mpi[0]);
  41 + kfree(sinfo->sig.digest);
  42 + kfree(sinfo);
  43 + }
  44 +}
  45 +
34 46 /**
35 47 * pkcs7_free_message - Free a PKCS#7 message
36 48 * @pkcs7: The PKCS#7 message to free
... ... @@ -54,9 +66,7 @@
54 66 while (pkcs7->signed_infos) {
55 67 sinfo = pkcs7->signed_infos;
56 68 pkcs7->signed_infos = sinfo->next;
57   - mpi_free(sinfo->sig.mpi[0]);
58   - kfree(sinfo->sig.digest);
59   - kfree(sinfo);
  69 + pkcs7_free_signed_info(sinfo);
60 70 }
61 71 kfree(pkcs7);
62 72 }
63 73  
... ... @@ -100,16 +110,12 @@
100 110 ctx->certs = cert->next;
101 111 x509_free_certificate(cert);
102 112 }
103   - mpi_free(ctx->sinfo->sig.mpi[0]);
104   - kfree(ctx->sinfo->sig.digest);
105   - kfree(ctx->sinfo);
  113 + pkcs7_free_signed_info(ctx->sinfo);
106 114 kfree(ctx);
107 115 return msg;
108 116  
109 117 error_decode:
110   - mpi_free(ctx->sinfo->sig.mpi[0]);
111   - kfree(ctx->sinfo->sig.digest);
112   - kfree(ctx->sinfo);
  118 + pkcs7_free_signed_info(ctx->sinfo);
113 119 error_no_sinfo:
114 120 kfree(ctx);
115 121 error_no_ctx: