summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto
diff options
context:
space:
mode:
authorbeck <>2014-04-17 13:37:50 +0000
committerbeck <>2014-04-17 13:37:50 +0000
commitbddb7c686e3d1aeb156722adc64b6c35ae720f87 (patch)
tree7595a93a27385c367802aa17ecf20f96551cf14d /src/lib/libcrypto
parentecec66222d758996a4ff2671ca5026d9ede5ef76 (diff)
downloadopenbsd-bddb7c686e3d1aeb156722adc64b6c35ae720f87.tar.gz
openbsd-bddb7c686e3d1aeb156722adc64b6c35ae720f87.tar.bz2
openbsd-bddb7c686e3d1aeb156722adc64b6c35ae720f87.zip
Change library to use intrinsic memory allocation functions instead of
OPENSSL_foo wrappers. This changes: OPENSSL_malloc->malloc OPENSSL_free->free OPENSSL_relloc->realloc OPENSSL_freeFunc->free
Diffstat (limited to 'src/lib/libcrypto')
-rw-r--r--src/lib/libcrypto/aes/aes_wrap.c8
-rw-r--r--src/lib/libcrypto/asn1/a_bitstr.c6
-rw-r--r--src/lib/libcrypto/asn1/a_bytes.c14
-rw-r--r--src/lib/libcrypto/asn1/a_digest.c2
-rw-r--r--src/lib/libcrypto/asn1/a_dup.c6
-rw-r--r--src/lib/libcrypto/asn1/a_enum.c6
-rw-r--r--src/lib/libcrypto/asn1/a_gentm.c4
-rw-r--r--src/lib/libcrypto/asn1/a_i2d_fp.c6
-rw-r--r--src/lib/libcrypto/asn1/a_int.c18
-rw-r--r--src/lib/libcrypto/asn1/a_mbstr.c4
-rw-r--r--src/lib/libcrypto/asn1/a_object.c26
-rw-r--r--src/lib/libcrypto/asn1/a_sign.c8
-rw-r--r--src/lib/libcrypto/asn1/a_strex.c4
-rw-r--r--src/lib/libcrypto/asn1/a_strnid.c4
-rw-r--r--src/lib/libcrypto/asn1/a_utctm.c4
-rw-r--r--src/lib/libcrypto/asn1/a_verify.c2
-rw-r--r--src/lib/libcrypto/asn1/ameth_lib.c8
-rw-r--r--src/lib/libcrypto/asn1/asn1_gen.c8
-rw-r--r--src/lib/libcrypto/asn1/asn1_lib.c12
-rw-r--r--src/lib/libcrypto/asn1/asn1_mac.h2
-rw-r--r--src/lib/libcrypto/asn1/asn_mime.c18
-rw-r--r--src/lib/libcrypto/asn1/asn_moid.c2
-rw-r--r--src/lib/libcrypto/asn1/asn_pack.c2
-rw-r--r--src/lib/libcrypto/asn1/bio_asn1.c8
-rw-r--r--src/lib/libcrypto/asn1/bio_ndef.c12
-rw-r--r--src/lib/libcrypto/asn1/f_enum.c6
-rw-r--r--src/lib/libcrypto/asn1/f_int.c4
-rw-r--r--src/lib/libcrypto/asn1/f_string.c6
-rw-r--r--src/lib/libcrypto/asn1/n_pkey.c4
-rw-r--r--src/lib/libcrypto/asn1/p5_pbev2.c2
-rw-r--r--src/lib/libcrypto/asn1/t_crl.c2
-rw-r--r--src/lib/libcrypto/asn1/t_x509.c12
-rw-r--r--src/lib/libcrypto/asn1/tasn_dec.c4
-rw-r--r--src/lib/libcrypto/asn1/tasn_enc.c10
-rw-r--r--src/lib/libcrypto/asn1/tasn_fre.c6
-rw-r--r--src/lib/libcrypto/asn1/tasn_new.c6
-rw-r--r--src/lib/libcrypto/asn1/tasn_prn.c6
-rw-r--r--src/lib/libcrypto/asn1/tasn_utl.c6
-rw-r--r--src/lib/libcrypto/asn1/x_crl.c4
-rw-r--r--src/lib/libcrypto/asn1/x_info.c6
-rw-r--r--src/lib/libcrypto/asn1/x_name.c12
-rw-r--r--src/lib/libcrypto/asn1/x_pkey.c4
-rw-r--r--src/lib/libcrypto/asn1/x_pubkey.c2
-rw-r--r--src/lib/libcrypto/asn1/x_x509.c4
-rw-r--r--src/lib/libcrypto/bio/b_print.c6
-rw-r--r--src/lib/libcrypto/bio/b_sock.c8
-rw-r--r--src/lib/libcrypto/bio/bf_buff.c32
-rw-r--r--src/lib/libcrypto/bio/bf_lbuf.c14
-rw-r--r--src/lib/libcrypto/bio/bf_nbio.c4
-rw-r--r--src/lib/libcrypto/bio/bio_lib.c6
-rw-r--r--src/lib/libcrypto/bio/bss_acpt.c10
-rw-r--r--src/lib/libcrypto/bio/bss_bio.c12
-rw-r--r--src/lib/libcrypto/bio/bss_conn.c18
-rw-r--r--src/lib/libcrypto/bio/bss_dgram.c22
-rw-r--r--src/lib/libcrypto/bio/bss_log.c4
-rw-r--r--src/lib/libcrypto/bn/bn_blind.c4
-rw-r--r--src/lib/libcrypto/bn/bn_ctx.c14
-rw-r--r--src/lib/libcrypto/bn/bn_exp.c4
-rw-r--r--src/lib/libcrypto/bn/bn_gf2m.c20
-rw-r--r--src/lib/libcrypto/bn/bn_lib.c16
-rw-r--r--src/lib/libcrypto/bn/bn_mont.c4
-rw-r--r--src/lib/libcrypto/bn/bn_print.c14
-rw-r--r--src/lib/libcrypto/bn/bn_rand.c4
-rw-r--r--src/lib/libcrypto/bn/bn_recp.c4
-rw-r--r--src/lib/libcrypto/buffer/buf_str.c4
-rw-r--r--src/lib/libcrypto/buffer/buffer.c12
-rw-r--r--src/lib/libcrypto/cmac/cm_pmeth.c2
-rw-r--r--src/lib/libcrypto/cmac/cmac.c4
-rw-r--r--src/lib/libcrypto/cms/cms_asn1.c4
-rw-r--r--src/lib/libcrypto/cms/cms_enc.c10
-rw-r--r--src/lib/libcrypto/cms/cms_env.c20
-rw-r--r--src/lib/libcrypto/cms/cms_ess.c2
-rw-r--r--src/lib/libcrypto/cms/cms_pwri.c10
-rw-r--r--src/lib/libcrypto/cms/cms_sd.c14
-rw-r--r--src/lib/libcrypto/comp/c_zlib.c26
-rw-r--r--src/lib/libcrypto/comp/comp_lib.c6
-rw-r--r--src/lib/libcrypto/conf/conf_api.c24
-rw-r--r--src/lib/libcrypto/conf/conf_def.c32
-rw-r--r--src/lib/libcrypto/conf/conf_mod.c26
-rw-r--r--src/lib/libcrypto/cryptlib.c10
-rw-r--r--src/lib/libcrypto/des/enc_read.c6
-rw-r--r--src/lib/libcrypto/des/enc_writ.c2
-rw-r--r--src/lib/libcrypto/dh/dh_ameth.c8
-rw-r--r--src/lib/libcrypto/dh/dh_lib.c12
-rw-r--r--src/lib/libcrypto/dh/dh_pmeth.c4
-rw-r--r--src/lib/libcrypto/dsa/dsa_ameth.c12
-rw-r--r--src/lib/libcrypto/dsa/dsa_asn1.c2
-rw-r--r--src/lib/libcrypto/dsa/dsa_lib.c10
-rw-r--r--src/lib/libcrypto/dsa/dsa_pmeth.c4
-rw-r--r--src/lib/libcrypto/dsa/dsa_sign.c4
-rw-r--r--src/lib/libcrypto/dso/dso.h10
-rw-r--r--src/lib/libcrypto/dso/dso_dlfcn.c10
-rw-r--r--src/lib/libcrypto/dso/dso_lib.c18
-rw-r--r--src/lib/libcrypto/ec/ec_ameth.c12
-rw-r--r--src/lib/libcrypto/ec/ec_asn1.c26
-rw-r--r--src/lib/libcrypto/ec/ec_key.c4
-rw-r--r--src/lib/libcrypto/ec/ec_lib.c40
-rw-r--r--src/lib/libcrypto/ec/ec_mult.c50
-rw-r--r--src/lib/libcrypto/ec/ec_pmeth.c4
-rw-r--r--src/lib/libcrypto/ec/ec_print.c28
-rw-r--r--src/lib/libcrypto/ec/eck_prn.c4
-rw-r--r--src/lib/libcrypto/ec/ecp_nistp224.c18
-rw-r--r--src/lib/libcrypto/ec/ecp_nistp256.c18
-rw-r--r--src/lib/libcrypto/ec/ecp_nistp521.c18
-rw-r--r--src/lib/libcrypto/ec/ecp_smpl.c4
-rw-r--r--src/lib/libcrypto/ecdh/ech_lib.c8
-rw-r--r--src/lib/libcrypto/ecdh/ech_ossl.c4
-rw-r--r--src/lib/libcrypto/ecdsa/ecs_lib.c8
-rw-r--r--src/lib/libcrypto/engine/eng_dyn.c22
-rw-r--r--src/lib/libcrypto/engine/eng_lib.c8
-rw-r--r--src/lib/libcrypto/engine/eng_rsax.c4
-rw-r--r--src/lib/libcrypto/engine/eng_table.c6
-rw-r--r--src/lib/libcrypto/err/err.c14
-rw-r--r--src/lib/libcrypto/evp/bio_b64.c4
-rw-r--r--src/lib/libcrypto/evp/bio_enc.c4
-rw-r--r--src/lib/libcrypto/evp/bio_ok.c4
-rw-r--r--src/lib/libcrypto/evp/digest.c12
-rw-r--r--src/lib/libcrypto/evp/e_aes.c6
-rw-r--r--src/lib/libcrypto/evp/evp_enc.c10
-rw-r--r--src/lib/libcrypto/evp/evp_pbe.c4
-rw-r--r--src/lib/libcrypto/evp/p_lib.c4
-rw-r--r--src/lib/libcrypto/evp/p_open.c4
-rw-r--r--src/lib/libcrypto/evp/pmeth_lib.c10
-rw-r--r--src/lib/libcrypto/ex_data.c24
-rw-r--r--src/lib/libcrypto/hmac/hm_ameth.c2
-rw-r--r--src/lib/libcrypto/hmac/hm_pmeth.c8
-rw-r--r--src/lib/libcrypto/lhash/lh_test.c2
-rw-r--r--src/lib/libcrypto/lhash/lhash.c20
-rw-r--r--src/lib/libcrypto/modes/gcm128.c4
-rw-r--r--src/lib/libcrypto/objects/o_names.c14
-rw-r--r--src/lib/libcrypto/objects/obj_dat.c26
-rw-r--r--src/lib/libcrypto/objects/obj_lib.c14
-rw-r--r--src/lib/libcrypto/objects/obj_xref.c6
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_ext.c12
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_ht.c8
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_lib.c10
-rw-r--r--src/lib/libcrypto/pem/pem_info.c12
-rw-r--r--src/lib/libcrypto/pem/pem_lib.c28
-rw-r--r--src/lib/libcrypto/pem/pem_oth.c2
-rw-r--r--src/lib/libcrypto/pem/pem_pkey.c8
-rw-r--r--src/lib/libcrypto/pem/pem_seal.c8
-rw-r--r--src/lib/libcrypto/pem/pem_sign.c4
-rw-r--r--src/lib/libcrypto/pem/pvkfmt.c24
-rw-r--r--src/lib/libcrypto/pkcs12/p12_decr.c14
-rw-r--r--src/lib/libcrypto/pkcs12/p12_key.c18
-rw-r--r--src/lib/libcrypto/pkcs12/p12_kiss.c2
-rw-r--r--src/lib/libcrypto/pkcs12/p12_mutl.c2
-rw-r--r--src/lib/libcrypto/pkcs12/p12_utl.c4
-rw-r--r--src/lib/libcrypto/pkcs7/bio_ber.c4
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_doit.c32
-rw-r--r--src/lib/libcrypto/pqueue/pqueue.c8
-rw-r--r--src/lib/libcrypto/rsa/rsa_ameth.c6
-rw-r--r--src/lib/libcrypto/rsa/rsa_eay.c16
-rw-r--r--src/lib/libcrypto/rsa/rsa_lib.c12
-rw-r--r--src/lib/libcrypto/rsa/rsa_oaep.c10
-rw-r--r--src/lib/libcrypto/rsa/rsa_pmeth.c8
-rw-r--r--src/lib/libcrypto/rsa/rsa_pss.c8
-rw-r--r--src/lib/libcrypto/rsa/rsa_saos.c8
-rw-r--r--src/lib/libcrypto/rsa/rsa_sign.c8
-rw-r--r--src/lib/libcrypto/srp/srp_lib.c12
-rw-r--r--src/lib/libcrypto/srp/srp_vfy.c40
-rw-r--r--src/lib/libcrypto/stack/stack.c14
-rw-r--r--src/lib/libcrypto/store/str_lib.c24
-rw-r--r--src/lib/libcrypto/store/str_mem.c4
-rw-r--r--src/lib/libcrypto/store/str_meth.c6
-rw-r--r--src/lib/libcrypto/ts/ts_lib.c2
-rw-r--r--src/lib/libcrypto/ts/ts_rsp_sign.c10
-rw-r--r--src/lib/libcrypto/ts/ts_rsp_verify.c10
-rw-r--r--src/lib/libcrypto/ts/ts_verify_ctx.c8
-rw-r--r--src/lib/libcrypto/txt_db/txt_db.c28
-rw-r--r--src/lib/libcrypto/ui/ui.h2
-rw-r--r--src/lib/libcrypto/ui/ui_lib.c32
-rw-r--r--src/lib/libcrypto/ui/ui_locl.h2
-rw-r--r--src/lib/libcrypto/x509/by_dir.c18
-rw-r--r--src/lib/libcrypto/x509/x509_cmp.c2
-rw-r--r--src/lib/libcrypto/x509/x509_lu.c22
-rw-r--r--src/lib/libcrypto/x509/x509_obj.c4
-rw-r--r--src/lib/libcrypto/x509/x509_req.c2
-rw-r--r--src/lib/libcrypto/x509/x509_trs.c10
-rw-r--r--src/lib/libcrypto/x509/x509_vfy.c6
-rw-r--r--src/lib/libcrypto/x509/x509_vpm.c6
-rw-r--r--src/lib/libcrypto/x509/x509spki.c12
-rw-r--r--src/lib/libcrypto/x509v3/pcy_cache.c4
-rw-r--r--src/lib/libcrypto/x509v3/pcy_data.c6
-rw-r--r--src/lib/libcrypto/x509v3/pcy_node.c4
-rw-r--r--src/lib/libcrypto/x509v3/pcy_tree.c18
-rw-r--r--src/lib/libcrypto/x509v3/v3_addr.c6
-rw-r--r--src/lib/libcrypto/x509v3/v3_akey.c4
-rw-r--r--src/lib/libcrypto/x509v3/v3_alt.c4
-rw-r--r--src/lib/libcrypto/x509v3/v3_asid.c10
-rw-r--r--src/lib/libcrypto/x509v3/v3_conf.c4
-rw-r--r--src/lib/libcrypto/x509v3/v3_cpols.c2
-rw-r--r--src/lib/libcrypto/x509v3/v3_ia5.c2
-rw-r--r--src/lib/libcrypto/x509v3/v3_info.c10
-rw-r--r--src/lib/libcrypto/x509v3/v3_lib.c4
-rw-r--r--src/lib/libcrypto/x509v3/v3_pci.c10
-rw-r--r--src/lib/libcrypto/x509v3/v3_prn.c2
-rw-r--r--src/lib/libcrypto/x509v3/v3_purp.c14
-rw-r--r--src/lib/libcrypto/x509v3/v3_sxnet.c2
-rw-r--r--src/lib/libcrypto/x509v3/v3_utl.c40
200 files changed, 1004 insertions, 1004 deletions
diff --git a/src/lib/libcrypto/aes/aes_wrap.c b/src/lib/libcrypto/aes/aes_wrap.c
index 198b0be333..668978425a 100644
--- a/src/lib/libcrypto/aes/aes_wrap.c
+++ b/src/lib/libcrypto/aes/aes_wrap.c
@@ -141,8 +141,8 @@ AES_wrap_unwrap_test(const unsigned char *kek, int keybits,
141 unsigned char *otmp = NULL, *ptmp = NULL; 141 unsigned char *otmp = NULL, *ptmp = NULL;
142 int r, ret = 0; 142 int r, ret = 0;
143 AES_KEY wctx; 143 AES_KEY wctx;
144 otmp = OPENSSL_malloc(keylen + 8); 144 otmp = malloc(keylen + 8);
145 ptmp = OPENSSL_malloc(keylen); 145 ptmp = malloc(keylen);
146 if (!otmp || !ptmp) 146 if (!otmp || !ptmp)
147 return 0; 147 return 0;
148 if (AES_set_encrypt_key(kek, keybits, &wctx)) 148 if (AES_set_encrypt_key(kek, keybits, &wctx))
@@ -165,9 +165,9 @@ AES_wrap_unwrap_test(const unsigned char *kek, int keybits,
165 165
166err: 166err:
167 if (otmp) 167 if (otmp)
168 OPENSSL_free(otmp); 168 free(otmp);
169 if (ptmp) 169 if (ptmp)
170 OPENSSL_free(ptmp); 170 free(ptmp);
171 171
172 return ret; 172 return ret;
173} 173}
diff --git a/src/lib/libcrypto/asn1/a_bitstr.c b/src/lib/libcrypto/asn1/a_bitstr.c
index 34179960b8..e2b65bf2ac 100644
--- a/src/lib/libcrypto/asn1/a_bitstr.c
+++ b/src/lib/libcrypto/asn1/a_bitstr.c
@@ -144,7 +144,7 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
144 144
145 if (len-- > 1) /* using one because of the bits left byte */ 145 if (len-- > 1) /* using one because of the bits left byte */
146 { 146 {
147 s=(unsigned char *)OPENSSL_malloc((int)len); 147 s=(unsigned char *)malloc((int)len);
148 if (s == NULL) 148 if (s == NULL)
149 { 149 {
150 i=ERR_R_MALLOC_FAILURE; 150 i=ERR_R_MALLOC_FAILURE;
@@ -158,7 +158,7 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
158 s=NULL; 158 s=NULL;
159 159
160 ret->length=(int)len; 160 ret->length=(int)len;
161 if (ret->data != NULL) OPENSSL_free(ret->data); 161 if (ret->data != NULL) free(ret->data);
162 ret->data=s; 162 ret->data=s;
163 ret->type=V_ASN1_BIT_STRING; 163 ret->type=V_ASN1_BIT_STRING;
164 if (a != NULL) (*a)=ret; 164 if (a != NULL) (*a)=ret;
@@ -192,7 +192,7 @@ int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
192 { 192 {
193 if (!value) return(1); /* Don't need to set */ 193 if (!value) return(1); /* Don't need to set */
194 if (a->data == NULL) 194 if (a->data == NULL)
195 c=(unsigned char *)OPENSSL_malloc(w+1); 195 c=(unsigned char *)malloc(w+1);
196 else 196 else
197 c=(unsigned char *)OPENSSL_realloc_clean(a->data, 197 c=(unsigned char *)OPENSSL_realloc_clean(a->data,
198 a->length, 198 a->length,
diff --git a/src/lib/libcrypto/asn1/a_bytes.c b/src/lib/libcrypto/asn1/a_bytes.c
index 92d630cdba..8431d89edf 100644
--- a/src/lib/libcrypto/asn1/a_bytes.c
+++ b/src/lib/libcrypto/asn1/a_bytes.c
@@ -101,7 +101,7 @@ ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a, const unsigned char **pp,
101 101
102 if (len != 0) 102 if (len != 0)
103 { 103 {
104 s=(unsigned char *)OPENSSL_malloc((int)len+1); 104 s=(unsigned char *)malloc((int)len+1);
105 if (s == NULL) 105 if (s == NULL)
106 { 106 {
107 i=ERR_R_MALLOC_FAILURE; 107 i=ERR_R_MALLOC_FAILURE;
@@ -114,7 +114,7 @@ ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a, const unsigned char **pp,
114 else 114 else
115 s=NULL; 115 s=NULL;
116 116
117 if (ret->data != NULL) OPENSSL_free(ret->data); 117 if (ret->data != NULL) free(ret->data);
118 ret->length=(int)len; 118 ret->length=(int)len;
119 ret->data=s; 119 ret->data=s;
120 ret->type=tag; 120 ret->type=tag;
@@ -209,8 +209,8 @@ ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, const unsigned char **pp,
209 { 209 {
210 if ((ret->length < len) || (ret->data == NULL)) 210 if ((ret->length < len) || (ret->data == NULL))
211 { 211 {
212 if (ret->data != NULL) OPENSSL_free(ret->data); 212 if (ret->data != NULL) free(ret->data);
213 s=(unsigned char *)OPENSSL_malloc((int)len + 1); 213 s=(unsigned char *)malloc((int)len + 1);
214 if (s == NULL) 214 if (s == NULL)
215 { 215 {
216 i=ERR_R_MALLOC_FAILURE; 216 i=ERR_R_MALLOC_FAILURE;
@@ -226,7 +226,7 @@ ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, const unsigned char **pp,
226 else 226 else
227 { 227 {
228 s=NULL; 228 s=NULL;
229 if (ret->data != NULL) OPENSSL_free(ret->data); 229 if (ret->data != NULL) free(ret->data);
230 } 230 }
231 231
232 ret->length=(int)len; 232 ret->length=(int)len;
@@ -301,14 +301,14 @@ static int asn1_collate_primitive(ASN1_STRING *a, ASN1_const_CTX *c)
301 if (!asn1_const_Finish(c)) goto err; 301 if (!asn1_const_Finish(c)) goto err;
302 302
303 a->length=num; 303 a->length=num;
304 if (a->data != NULL) OPENSSL_free(a->data); 304 if (a->data != NULL) free(a->data);
305 a->data=(unsigned char *)b.data; 305 a->data=(unsigned char *)b.data;
306 if (os != NULL) ASN1_STRING_free(os); 306 if (os != NULL) ASN1_STRING_free(os);
307 return(1); 307 return(1);
308err: 308err:
309 ASN1err(ASN1_F_ASN1_COLLATE_PRIMITIVE,c->error); 309 ASN1err(ASN1_F_ASN1_COLLATE_PRIMITIVE,c->error);
310 if (os != NULL) ASN1_STRING_free(os); 310 if (os != NULL) ASN1_STRING_free(os);
311 if (b.data != NULL) OPENSSL_free(b.data); 311 if (b.data != NULL) free(b.data);
312 return(0); 312 return(0);
313 } 313 }
314 314
diff --git a/src/lib/libcrypto/asn1/a_digest.c b/src/lib/libcrypto/asn1/a_digest.c
index 8a4b24a06b..0d463d409b 100644
--- a/src/lib/libcrypto/asn1/a_digest.c
+++ b/src/lib/libcrypto/asn1/a_digest.c
@@ -81,6 +81,6 @@ int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn,
81 81
82 if (!EVP_Digest(str, i, md, len, type, NULL)) 82 if (!EVP_Digest(str, i, md, len, type, NULL))
83 return 0; 83 return 0;
84 OPENSSL_free(str); 84 free(str);
85 return(1); 85 return(1);
86 } 86 }
diff --git a/src/lib/libcrypto/asn1/a_dup.c b/src/lib/libcrypto/asn1/a_dup.c
index d98992548a..e825b9c2d4 100644
--- a/src/lib/libcrypto/asn1/a_dup.c
+++ b/src/lib/libcrypto/asn1/a_dup.c
@@ -72,14 +72,14 @@ void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x)
72 if (x == NULL) return(NULL); 72 if (x == NULL) return(NULL);
73 73
74 i=i2d(x,NULL); 74 i=i2d(x,NULL);
75 b=OPENSSL_malloc(i+10); 75 b=malloc(i+10);
76 if (b == NULL) 76 if (b == NULL)
77 { ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); } 77 { ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); }
78 p= b; 78 p= b;
79 i=i2d(x,&p); 79 i=i2d(x,&p);
80 p2= b; 80 p2= b;
81 ret=d2i(NULL,&p2,i); 81 ret=d2i(NULL,&p2,i);
82 OPENSSL_free(b); 82 free(b);
83 return(ret); 83 return(ret);
84 } 84 }
85 85
@@ -104,6 +104,6 @@ void *ASN1_item_dup(const ASN1_ITEM *it, void *x)
104 { ASN1err(ASN1_F_ASN1_ITEM_DUP,ERR_R_MALLOC_FAILURE); return(NULL); } 104 { ASN1err(ASN1_F_ASN1_ITEM_DUP,ERR_R_MALLOC_FAILURE); return(NULL); }
105 p= b; 105 p= b;
106 ret=ASN1_item_d2i(NULL,&p,i, it); 106 ret=ASN1_item_d2i(NULL,&p,i, it);
107 OPENSSL_free(b); 107 free(b);
108 return(ret); 108 return(ret);
109 } 109 }
diff --git a/src/lib/libcrypto/asn1/a_enum.c b/src/lib/libcrypto/asn1/a_enum.c
index fe9aa13b9c..c1154dde0a 100644
--- a/src/lib/libcrypto/asn1/a_enum.c
+++ b/src/lib/libcrypto/asn1/a_enum.c
@@ -77,8 +77,8 @@ int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
77 if (a->length < (int)(sizeof(long)+1)) 77 if (a->length < (int)(sizeof(long)+1))
78 { 78 {
79 if (a->data != NULL) 79 if (a->data != NULL)
80 OPENSSL_free(a->data); 80 free(a->data);
81 if ((a->data=(unsigned char *)OPENSSL_malloc(sizeof(long)+1)) != NULL) 81 if ((a->data=(unsigned char *)malloc(sizeof(long)+1)) != NULL)
82 memset((char *)a->data,0,sizeof(long)+1); 82 memset((char *)a->data,0,sizeof(long)+1);
83 } 83 }
84 if (a->data == NULL) 84 if (a->data == NULL)
@@ -155,7 +155,7 @@ ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
155 len=((j == 0)?0:((j/8)+1)); 155 len=((j == 0)?0:((j/8)+1));
156 if (ret->length < len+4) 156 if (ret->length < len+4)
157 { 157 {
158 unsigned char *new_data=OPENSSL_realloc(ret->data, len+4); 158 unsigned char *new_data=realloc(ret->data, len+4);
159 if (!new_data) 159 if (!new_data)
160 { 160 {
161 ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE); 161 ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE);
diff --git a/src/lib/libcrypto/asn1/a_gentm.c b/src/lib/libcrypto/asn1/a_gentm.c
index 4f312ee6c9..86666e7a20 100644
--- a/src/lib/libcrypto/asn1/a_gentm.c
+++ b/src/lib/libcrypto/asn1/a_gentm.c
@@ -225,7 +225,7 @@ ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
225 p=(char *)s->data; 225 p=(char *)s->data;
226 if ((p == NULL) || ((size_t)s->length < len)) 226 if ((p == NULL) || ((size_t)s->length < len))
227 { 227 {
228 p=OPENSSL_malloc(len); 228 p=malloc(len);
229 if (p == NULL) 229 if (p == NULL)
230 { 230 {
231 ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ, 231 ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ,
@@ -233,7 +233,7 @@ ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
233 return(NULL); 233 return(NULL);
234 } 234 }
235 if (s->data != NULL) 235 if (s->data != NULL)
236 OPENSSL_free(s->data); 236 free(s->data);
237 s->data=(unsigned char *)p; 237 s->data=(unsigned char *)p;
238 } 238 }
239 239
diff --git a/src/lib/libcrypto/asn1/a_i2d_fp.c b/src/lib/libcrypto/asn1/a_i2d_fp.c
index a3ad76d356..484bcd66eb 100644
--- a/src/lib/libcrypto/asn1/a_i2d_fp.c
+++ b/src/lib/libcrypto/asn1/a_i2d_fp.c
@@ -88,7 +88,7 @@ int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x)
88 int i,j=0,n,ret=1; 88 int i,j=0,n,ret=1;
89 89
90 n=i2d(x,NULL); 90 n=i2d(x,NULL);
91 b=(char *)OPENSSL_malloc(n); 91 b=(char *)malloc(n);
92 if (b == NULL) 92 if (b == NULL)
93 { 93 {
94 ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE); 94 ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE);
@@ -110,7 +110,7 @@ int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x)
110 j+=i; 110 j+=i;
111 n-=i; 111 n-=i;
112 } 112 }
113 OPENSSL_free(b); 113 free(b);
114 return(ret); 114 return(ret);
115 } 115 }
116 116
@@ -158,6 +158,6 @@ int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x)
158 j+=i; 158 j+=i;
159 n-=i; 159 n-=i;
160 } 160 }
161 OPENSSL_free(b); 161 free(b);
162 return(ret); 162 return(ret);
163 } 163 }
diff --git a/src/lib/libcrypto/asn1/a_int.c b/src/lib/libcrypto/asn1/a_int.c
index 297c45a9ff..6c38ace8f9 100644
--- a/src/lib/libcrypto/asn1/a_int.c
+++ b/src/lib/libcrypto/asn1/a_int.c
@@ -194,9 +194,9 @@ ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp,
194 p= *pp; 194 p= *pp;
195 pend = p + len; 195 pend = p + len;
196 196
197 /* We must OPENSSL_malloc stuff, even for 0 bytes otherwise it 197 /* We must malloc stuff, even for 0 bytes otherwise it
198 * signifies a missing NULL parameter. */ 198 * signifies a missing NULL parameter. */
199 s=(unsigned char *)OPENSSL_malloc((int)len+1); 199 s=(unsigned char *)malloc((int)len+1);
200 if (s == NULL) 200 if (s == NULL)
201 { 201 {
202 i=ERR_R_MALLOC_FAILURE; 202 i=ERR_R_MALLOC_FAILURE;
@@ -249,7 +249,7 @@ ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp,
249 memcpy(s,p,(int)len); 249 memcpy(s,p,(int)len);
250 } 250 }
251 251
252 if (ret->data != NULL) OPENSSL_free(ret->data); 252 if (ret->data != NULL) free(ret->data);
253 ret->data=s; 253 ret->data=s;
254 ret->length=(int)len; 254 ret->length=(int)len;
255 if (a != NULL) (*a)=ret; 255 if (a != NULL) (*a)=ret;
@@ -300,9 +300,9 @@ ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp,
300 goto err; 300 goto err;
301 } 301 }
302 302
303 /* We must OPENSSL_malloc stuff, even for 0 bytes otherwise it 303 /* We must malloc stuff, even for 0 bytes otherwise it
304 * signifies a missing NULL parameter. */ 304 * signifies a missing NULL parameter. */
305 s=(unsigned char *)OPENSSL_malloc((int)len+1); 305 s=(unsigned char *)malloc((int)len+1);
306 if (s == NULL) 306 if (s == NULL)
307 { 307 {
308 i=ERR_R_MALLOC_FAILURE; 308 i=ERR_R_MALLOC_FAILURE;
@@ -319,7 +319,7 @@ ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp,
319 p+=len; 319 p+=len;
320 } 320 }
321 321
322 if (ret->data != NULL) OPENSSL_free(ret->data); 322 if (ret->data != NULL) free(ret->data);
323 ret->data=s; 323 ret->data=s;
324 ret->length=(int)len; 324 ret->length=(int)len;
325 if (a != NULL) (*a)=ret; 325 if (a != NULL) (*a)=ret;
@@ -343,8 +343,8 @@ int ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
343 if (a->length < (int)(sizeof(long)+1)) 343 if (a->length < (int)(sizeof(long)+1))
344 { 344 {
345 if (a->data != NULL) 345 if (a->data != NULL)
346 OPENSSL_free(a->data); 346 free(a->data);
347 if ((a->data=(unsigned char *)OPENSSL_malloc(sizeof(long)+1)) != NULL) 347 if ((a->data=(unsigned char *)malloc(sizeof(long)+1)) != NULL)
348 memset((char *)a->data,0,sizeof(long)+1); 348 memset((char *)a->data,0,sizeof(long)+1);
349 } 349 }
350 if (a->data == NULL) 350 if (a->data == NULL)
@@ -422,7 +422,7 @@ ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai)
422 len=((j == 0)?0:((j/8)+1)); 422 len=((j == 0)?0:((j/8)+1));
423 if (ret->length < len+4) 423 if (ret->length < len+4)
424 { 424 {
425 unsigned char *new_data=OPENSSL_realloc(ret->data, len+4); 425 unsigned char *new_data=realloc(ret->data, len+4);
426 if (!new_data) 426 if (!new_data)
427 { 427 {
428 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); 428 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
diff --git a/src/lib/libcrypto/asn1/a_mbstr.c b/src/lib/libcrypto/asn1/a_mbstr.c
index dc953c8325..f6d8da8b3c 100644
--- a/src/lib/libcrypto/asn1/a_mbstr.c
+++ b/src/lib/libcrypto/asn1/a_mbstr.c
@@ -185,7 +185,7 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
185 dest = *out; 185 dest = *out;
186 if(dest->data) { 186 if(dest->data) {
187 dest->length = 0; 187 dest->length = 0;
188 OPENSSL_free(dest->data); 188 free(dest->data);
189 dest->data = NULL; 189 dest->data = NULL;
190 } 190 }
191 dest->type = str_type; 191 dest->type = str_type;
@@ -231,7 +231,7 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
231 cpyfunc = cpy_utf8; 231 cpyfunc = cpy_utf8;
232 break; 232 break;
233 } 233 }
234 if(!(p = OPENSSL_malloc(outlen + 1))) { 234 if(!(p = malloc(outlen + 1))) {
235 if(free_out) ASN1_STRING_free(dest); 235 if(free_out) ASN1_STRING_free(dest);
236 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,ERR_R_MALLOC_FAILURE); 236 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,ERR_R_MALLOC_FAILURE);
237 return -1; 237 return -1;
diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c
index 3978c9150d..c30f32442d 100644
--- a/src/lib/libcrypto/asn1/a_object.c
+++ b/src/lib/libcrypto/asn1/a_object.c
@@ -180,9 +180,9 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
180 if (blsize > tmpsize) 180 if (blsize > tmpsize)
181 { 181 {
182 if (tmp != ftmp) 182 if (tmp != ftmp)
183 OPENSSL_free(tmp); 183 free(tmp);
184 tmpsize = blsize + 32; 184 tmpsize = blsize + 32;
185 tmp = OPENSSL_malloc(tmpsize); 185 tmp = malloc(tmpsize);
186 if (!tmp) 186 if (!tmp)
187 goto err; 187 goto err;
188 } 188 }
@@ -215,13 +215,13 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
215 len+=i; 215 len+=i;
216 } 216 }
217 if (tmp != ftmp) 217 if (tmp != ftmp)
218 OPENSSL_free(tmp); 218 free(tmp);
219 if (bl) 219 if (bl)
220 BN_free(bl); 220 BN_free(bl);
221 return(len); 221 return(len);
222err: 222err:
223 if (tmp != ftmp) 223 if (tmp != ftmp)
224 OPENSSL_free(tmp); 224 free(tmp);
225 if (bl) 225 if (bl)
226 BN_free(bl); 226 BN_free(bl);
227 return(0); 227 return(0);
@@ -242,7 +242,7 @@ int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a)
242 i=i2t_ASN1_OBJECT(buf,sizeof buf,a); 242 i=i2t_ASN1_OBJECT(buf,sizeof buf,a);
243 if (i > (int)(sizeof(buf) - 1)) 243 if (i > (int)(sizeof(buf) - 1))
244 { 244 {
245 p = OPENSSL_malloc(i + 1); 245 p = malloc(i + 1);
246 if (!p) 246 if (!p)
247 return -1; 247 return -1;
248 i2t_ASN1_OBJECT(p,i + 1,a); 248 i2t_ASN1_OBJECT(p,i + 1,a);
@@ -251,7 +251,7 @@ int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a)
251 return BIO_write(bp, "<INVALID>", 9); 251 return BIO_write(bp, "<INVALID>", 9);
252 BIO_write(bp,p,i); 252 BIO_write(bp,p,i);
253 if (p != buf) 253 if (p != buf)
254 OPENSSL_free(p); 254 free(p);
255 return(i); 255 return(i);
256 } 256 }
257 257
@@ -319,8 +319,8 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
319 if ((data == NULL) || (ret->length < len)) 319 if ((data == NULL) || (ret->length < len))
320 { 320 {
321 ret->length=0; 321 ret->length=0;
322 if (data != NULL) OPENSSL_free(data); 322 if (data != NULL) free(data);
323 data=(unsigned char *)OPENSSL_malloc(len ? (int)len : 1); 323 data=(unsigned char *)malloc(len ? (int)len : 1);
324 if (data == NULL) 324 if (data == NULL)
325 { i=ERR_R_MALLOC_FAILURE; goto err; } 325 { i=ERR_R_MALLOC_FAILURE; goto err; }
326 ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA; 326 ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA;
@@ -348,7 +348,7 @@ ASN1_OBJECT *ASN1_OBJECT_new(void)
348 { 348 {
349 ASN1_OBJECT *ret; 349 ASN1_OBJECT *ret;
350 350
351 ret=(ASN1_OBJECT *)OPENSSL_malloc(sizeof(ASN1_OBJECT)); 351 ret=(ASN1_OBJECT *)malloc(sizeof(ASN1_OBJECT));
352 if (ret == NULL) 352 if (ret == NULL)
353 { 353 {
354 ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE); 354 ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE);
@@ -369,19 +369,19 @@ void ASN1_OBJECT_free(ASN1_OBJECT *a)
369 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) 369 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS)
370 { 370 {
371#ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */ 371#ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */
372 if (a->sn != NULL) OPENSSL_free((void *)a->sn); 372 if (a->sn != NULL) free((void *)a->sn);
373 if (a->ln != NULL) OPENSSL_free((void *)a->ln); 373 if (a->ln != NULL) free((void *)a->ln);
374#endif 374#endif
375 a->sn=a->ln=NULL; 375 a->sn=a->ln=NULL;
376 } 376 }
377 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) 377 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA)
378 { 378 {
379 if (a->data != NULL) OPENSSL_free((void *)a->data); 379 if (a->data != NULL) free((void *)a->data);
380 a->data=NULL; 380 a->data=NULL;
381 a->length=0; 381 a->length=0;
382 } 382 }
383 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC) 383 if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC)
384 OPENSSL_free(a); 384 free(a);
385 } 385 }
386 386
387ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len, 387ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len,
diff --git a/src/lib/libcrypto/asn1/a_sign.c b/src/lib/libcrypto/asn1/a_sign.c
index 01b6292b65..0433b49a64 100644
--- a/src/lib/libcrypto/asn1/a_sign.c
+++ b/src/lib/libcrypto/asn1/a_sign.c
@@ -211,7 +211,7 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it,
211 211
212 inl=ASN1_item_i2d(asn,&buf_in, it); 212 inl=ASN1_item_i2d(asn,&buf_in, it);
213 outll=outl=EVP_PKEY_size(pkey); 213 outll=outl=EVP_PKEY_size(pkey);
214 buf_out=OPENSSL_malloc((unsigned int)outl); 214 buf_out=malloc((unsigned int)outl);
215 if ((buf_in == NULL) || (buf_out == NULL)) 215 if ((buf_in == NULL) || (buf_out == NULL))
216 { 216 {
217 outl=0; 217 outl=0;
@@ -226,7 +226,7 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it,
226 ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,ERR_R_EVP_LIB); 226 ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX,ERR_R_EVP_LIB);
227 goto err; 227 goto err;
228 } 228 }
229 if (signature->data != NULL) OPENSSL_free(signature->data); 229 if (signature->data != NULL) free(signature->data);
230 signature->data=buf_out; 230 signature->data=buf_out;
231 buf_out=NULL; 231 buf_out=NULL;
232 signature->length=outl; 232 signature->length=outl;
@@ -238,8 +238,8 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it,
238err: 238err:
239 EVP_MD_CTX_cleanup(ctx); 239 EVP_MD_CTX_cleanup(ctx);
240 if (buf_in != NULL) 240 if (buf_in != NULL)
241 { OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); OPENSSL_free(buf_in); } 241 { OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); free(buf_in); }
242 if (buf_out != NULL) 242 if (buf_out != NULL)
243 { OPENSSL_cleanse((char *)buf_out,outll); OPENSSL_free(buf_out); } 243 { OPENSSL_cleanse((char *)buf_out,outll); free(buf_out); }
244 return(outl); 244 return(outl);
245 } 245 }
diff --git a/src/lib/libcrypto/asn1/a_strex.c b/src/lib/libcrypto/asn1/a_strex.c
index d1a587ccc1..713b3cb028 100644
--- a/src/lib/libcrypto/asn1/a_strex.c
+++ b/src/lib/libcrypto/asn1/a_strex.c
@@ -278,12 +278,12 @@ static int do_dump(unsigned long lflags, char_io *io_ch, void *arg, ASN1_STRING
278 t.type = str->type; 278 t.type = str->type;
279 t.value.ptr = (char *)str; 279 t.value.ptr = (char *)str;
280 der_len = i2d_ASN1_TYPE(&t, NULL); 280 der_len = i2d_ASN1_TYPE(&t, NULL);
281 der_buf = OPENSSL_malloc(der_len); 281 der_buf = malloc(der_len);
282 if(!der_buf) return -1; 282 if(!der_buf) return -1;
283 p = der_buf; 283 p = der_buf;
284 i2d_ASN1_TYPE(&t, &p); 284 i2d_ASN1_TYPE(&t, &p);
285 outlen = do_hex_dump(io_ch, arg, der_buf, der_len); 285 outlen = do_hex_dump(io_ch, arg, der_buf, der_len);
286 OPENSSL_free(der_buf); 286 free(der_buf);
287 if(outlen < 0) return -1; 287 if(outlen < 0) return -1;
288 return outlen + 1; 288 return outlen + 1;
289} 289}
diff --git a/src/lib/libcrypto/asn1/a_strnid.c b/src/lib/libcrypto/asn1/a_strnid.c
index 2fc48c1551..74bc7b316c 100644
--- a/src/lib/libcrypto/asn1/a_strnid.c
+++ b/src/lib/libcrypto/asn1/a_strnid.c
@@ -222,7 +222,7 @@ int ASN1_STRING_TABLE_add(int nid,
222 return 0; 222 return 0;
223 } 223 }
224 if(!(tmp = ASN1_STRING_TABLE_get(nid))) { 224 if(!(tmp = ASN1_STRING_TABLE_get(nid))) {
225 tmp = OPENSSL_malloc(sizeof(ASN1_STRING_TABLE)); 225 tmp = malloc(sizeof(ASN1_STRING_TABLE));
226 if(!tmp) { 226 if(!tmp) {
227 ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, 227 ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD,
228 ERR_R_MALLOC_FAILURE); 228 ERR_R_MALLOC_FAILURE);
@@ -250,7 +250,7 @@ void ASN1_STRING_TABLE_cleanup(void)
250 250
251static void st_free(ASN1_STRING_TABLE *tbl) 251static void st_free(ASN1_STRING_TABLE *tbl)
252{ 252{
253 if(tbl->flags & STABLE_FLAGS_MALLOC) OPENSSL_free(tbl); 253 if(tbl->flags & STABLE_FLAGS_MALLOC) free(tbl);
254} 254}
255 255
256 256
diff --git a/src/lib/libcrypto/asn1/a_utctm.c b/src/lib/libcrypto/asn1/a_utctm.c
index f2e7de16af..0e7aca90a7 100644
--- a/src/lib/libcrypto/asn1/a_utctm.c
+++ b/src/lib/libcrypto/asn1/a_utctm.c
@@ -203,14 +203,14 @@ ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
203 p=(char *)s->data; 203 p=(char *)s->data;
204 if ((p == NULL) || ((size_t)s->length < len)) 204 if ((p == NULL) || ((size_t)s->length < len))
205 { 205 {
206 p=OPENSSL_malloc(len); 206 p=malloc(len);
207 if (p == NULL) 207 if (p == NULL)
208 { 208 {
209 ASN1err(ASN1_F_ASN1_UTCTIME_ADJ,ERR_R_MALLOC_FAILURE); 209 ASN1err(ASN1_F_ASN1_UTCTIME_ADJ,ERR_R_MALLOC_FAILURE);
210 return(NULL); 210 return(NULL);
211 } 211 }
212 if (s->data != NULL) 212 if (s->data != NULL)
213 OPENSSL_free(s->data); 213 free(s->data);
214 s->data=(unsigned char *)p; 214 s->data=(unsigned char *)p;
215 } 215 }
216 216
diff --git a/src/lib/libcrypto/asn1/a_verify.c b/src/lib/libcrypto/asn1/a_verify.c
index 5eb47d768c..8eca970be3 100644
--- a/src/lib/libcrypto/asn1/a_verify.c
+++ b/src/lib/libcrypto/asn1/a_verify.c
@@ -154,7 +154,7 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a,
154 } 154 }
155 155
156 OPENSSL_cleanse(buf_in,(unsigned int)inl); 156 OPENSSL_cleanse(buf_in,(unsigned int)inl);
157 OPENSSL_free(buf_in); 157 free(buf_in);
158 158
159 if (EVP_DigestVerifyFinal(&ctx,signature->data, 159 if (EVP_DigestVerifyFinal(&ctx,signature->data,
160 (size_t)signature->length) <= 0) 160 (size_t)signature->length) <= 0)
diff --git a/src/lib/libcrypto/asn1/ameth_lib.c b/src/lib/libcrypto/asn1/ameth_lib.c
index a19e058fca..228392f1e6 100644
--- a/src/lib/libcrypto/asn1/ameth_lib.c
+++ b/src/lib/libcrypto/asn1/ameth_lib.c
@@ -289,7 +289,7 @@ EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id, int flags,
289 const char *pem_str, const char *info) 289 const char *pem_str, const char *info)
290 { 290 {
291 EVP_PKEY_ASN1_METHOD *ameth; 291 EVP_PKEY_ASN1_METHOD *ameth;
292 ameth = OPENSSL_malloc(sizeof(EVP_PKEY_ASN1_METHOD)); 292 ameth = malloc(sizeof(EVP_PKEY_ASN1_METHOD));
293 if (!ameth) 293 if (!ameth)
294 return NULL; 294 return NULL;
295 295
@@ -393,10 +393,10 @@ void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth)
393 if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC)) 393 if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC))
394 { 394 {
395 if (ameth->pem_str) 395 if (ameth->pem_str)
396 OPENSSL_free(ameth->pem_str); 396 free(ameth->pem_str);
397 if (ameth->info) 397 if (ameth->info)
398 OPENSSL_free(ameth->info); 398 free(ameth->info);
399 OPENSSL_free(ameth); 399 free(ameth);
400 } 400 }
401 } 401 }
402 402
diff --git a/src/lib/libcrypto/asn1/asn1_gen.c b/src/lib/libcrypto/asn1/asn1_gen.c
index 81a7a38895..8194beeb30 100644
--- a/src/lib/libcrypto/asn1/asn1_gen.c
+++ b/src/lib/libcrypto/asn1/asn1_gen.c
@@ -226,7 +226,7 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf)
226 226
227 /* Allocate buffer for new encoding */ 227 /* Allocate buffer for new encoding */
228 228
229 new_der = OPENSSL_malloc(len); 229 new_der = malloc(len);
230 if (!new_der) 230 if (!new_der)
231 goto err; 231 goto err;
232 232
@@ -266,9 +266,9 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf)
266 266
267 err: 267 err:
268 if (orig_der) 268 if (orig_der)
269 OPENSSL_free(orig_der); 269 free(orig_der);
270 if (new_der) 270 if (new_der)
271 OPENSSL_free(new_der); 271 free(new_der);
272 272
273 return ret; 273 return ret;
274 274
@@ -499,7 +499,7 @@ static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf)
499 bad: 499 bad:
500 500
501 if (der) 501 if (der)
502 OPENSSL_free(der); 502 free(der);
503 503
504 if (sk) 504 if (sk)
505 sk_ASN1_TYPE_pop_free(sk, ASN1_TYPE_free); 505 sk_ASN1_TYPE_pop_free(sk, ASN1_TYPE_free);
diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c
index 4d1d6af18d..7b06b6fdc8 100644
--- a/src/lib/libcrypto/asn1/asn1_lib.c
+++ b/src/lib/libcrypto/asn1/asn1_lib.c
@@ -383,9 +383,9 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
383 { 383 {
384 c=str->data; 384 c=str->data;
385 if (c == NULL) 385 if (c == NULL)
386 str->data=OPENSSL_malloc(len+1); 386 str->data=malloc(len+1);
387 else 387 else
388 str->data=OPENSSL_realloc(c,len+1); 388 str->data=realloc(c,len+1);
389 389
390 if (str->data == NULL) 390 if (str->data == NULL)
391 { 391 {
@@ -407,7 +407,7 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
407void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len) 407void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len)
408 { 408 {
409 if (str->data) 409 if (str->data)
410 OPENSSL_free(str->data); 410 free(str->data);
411 str->data = data; 411 str->data = data;
412 str->length = len; 412 str->length = len;
413 } 413 }
@@ -422,7 +422,7 @@ ASN1_STRING *ASN1_STRING_type_new(int type)
422 { 422 {
423 ASN1_STRING *ret; 423 ASN1_STRING *ret;
424 424
425 ret=(ASN1_STRING *)OPENSSL_malloc(sizeof(ASN1_STRING)); 425 ret=(ASN1_STRING *)malloc(sizeof(ASN1_STRING));
426 if (ret == NULL) 426 if (ret == NULL)
427 { 427 {
428 ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW,ERR_R_MALLOC_FAILURE); 428 ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW,ERR_R_MALLOC_FAILURE);
@@ -439,8 +439,8 @@ void ASN1_STRING_free(ASN1_STRING *a)
439 { 439 {
440 if (a == NULL) return; 440 if (a == NULL) return;
441 if (a->data && !(a->flags & ASN1_STRING_FLAG_NDEF)) 441 if (a->data && !(a->flags & ASN1_STRING_FLAG_NDEF))
442 OPENSSL_free(a->data); 442 free(a->data);
443 OPENSSL_free(a); 443 free(a);
444 } 444 }
445 445
446int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b) 446int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b)
diff --git a/src/lib/libcrypto/asn1/asn1_mac.h b/src/lib/libcrypto/asn1/asn1_mac.h
index c60b197552..ecc2c77228 100644
--- a/src/lib/libcrypto/asn1/asn1_mac.h
+++ b/src/lib/libcrypto/asn1/asn1_mac.h
@@ -289,7 +289,7 @@ err:\
289 289
290/* New macros */ 290/* New macros */
291#define M_ASN1_New_Malloc(ret,type) \ 291#define M_ASN1_New_Malloc(ret,type) \
292 if ((ret=(type *)OPENSSL_malloc(sizeof(type))) == NULL) \ 292 if ((ret=(type *)malloc(sizeof(type))) == NULL) \
293 { c.line=__LINE__; goto err2; } 293 { c.line=__LINE__; goto err2; }
294 294
295#define M_ASN1_New(arg,func) \ 295#define M_ASN1_New(arg,func) \
diff --git a/src/lib/libcrypto/asn1/asn_mime.c b/src/lib/libcrypto/asn1/asn_mime.c
index 54a704a969..d94b3cd6f8 100644
--- a/src/lib/libcrypto/asn1/asn_mime.c
+++ b/src/lib/libcrypto/asn1/asn_mime.c
@@ -220,7 +220,7 @@ static int asn1_write_micalg(BIO *out, STACK_OF(X509_ALGOR) *mdalgs)
220 if (rv > 0) 220 if (rv > 0)
221 { 221 {
222 BIO_puts(out, micstr); 222 BIO_puts(out, micstr);
223 OPENSSL_free(micstr); 223 free(micstr);
224 continue; 224 continue;
225 } 225 }
226 if (rv != -2) 226 if (rv != -2)
@@ -822,7 +822,7 @@ static MIME_HEADER *mime_hdr_new(char *name, char *value)
822 } 822 }
823 } 823 }
824 } else tmpval = NULL; 824 } else tmpval = NULL;
825 mhdr = (MIME_HEADER *) OPENSSL_malloc(sizeof(MIME_HEADER)); 825 mhdr = (MIME_HEADER *) malloc(sizeof(MIME_HEADER));
826 if(!mhdr) return NULL; 826 if(!mhdr) return NULL;
827 mhdr->name = tmpname; 827 mhdr->name = tmpname;
828 mhdr->value = tmpval; 828 mhdr->value = tmpval;
@@ -851,7 +851,7 @@ static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value)
851 if(!tmpval) return 0; 851 if(!tmpval) return 0;
852 } else tmpval = NULL; 852 } else tmpval = NULL;
853 /* Parameter values are case sensitive so leave as is */ 853 /* Parameter values are case sensitive so leave as is */
854 mparam = (MIME_PARAM *) OPENSSL_malloc(sizeof(MIME_PARAM)); 854 mparam = (MIME_PARAM *) malloc(sizeof(MIME_PARAM));
855 if(!mparam) return 0; 855 if(!mparam) return 0;
856 mparam->param_name = tmpname; 856 mparam->param_name = tmpname;
857 mparam->param_value = tmpval; 857 mparam->param_value = tmpval;
@@ -900,17 +900,17 @@ static MIME_PARAM *mime_param_find(MIME_HEADER *hdr, char *name)
900 900
901static void mime_hdr_free(MIME_HEADER *hdr) 901static void mime_hdr_free(MIME_HEADER *hdr)
902{ 902{
903 if(hdr->name) OPENSSL_free(hdr->name); 903 if(hdr->name) free(hdr->name);
904 if(hdr->value) OPENSSL_free(hdr->value); 904 if(hdr->value) free(hdr->value);
905 if(hdr->params) sk_MIME_PARAM_pop_free(hdr->params, mime_param_free); 905 if(hdr->params) sk_MIME_PARAM_pop_free(hdr->params, mime_param_free);
906 OPENSSL_free(hdr); 906 free(hdr);
907} 907}
908 908
909static void mime_param_free(MIME_PARAM *param) 909static void mime_param_free(MIME_PARAM *param)
910{ 910{
911 if(param->param_name) OPENSSL_free(param->param_name); 911 if(param->param_name) free(param->param_name);
912 if(param->param_value) OPENSSL_free(param->param_value); 912 if(param->param_value) free(param->param_value);
913 OPENSSL_free(param); 913 free(param);
914} 914}
915 915
916/* Check for a multipart boundary. Returns: 916/* Check for a multipart boundary. Returns:
diff --git a/src/lib/libcrypto/asn1/asn_moid.c b/src/lib/libcrypto/asn1/asn_moid.c
index 1ea6a59248..fd04d11459 100644
--- a/src/lib/libcrypto/asn1/asn_moid.c
+++ b/src/lib/libcrypto/asn1/asn_moid.c
@@ -145,7 +145,7 @@ static int do_create(char *value, char *name)
145 p--; 145 p--;
146 } 146 }
147 p++; 147 p++;
148 lntmp = OPENSSL_malloc((p - ln) + 1); 148 lntmp = malloc((p - ln) + 1);
149 if (lntmp == NULL) 149 if (lntmp == NULL)
150 return 0; 150 return 0;
151 memcpy(lntmp, ln, p - ln); 151 memcpy(lntmp, ln, p - ln);
diff --git a/src/lib/libcrypto/asn1/asn_pack.c b/src/lib/libcrypto/asn1/asn_pack.c
index 1886508654..13dc5d4665 100644
--- a/src/lib/libcrypto/asn1/asn_pack.c
+++ b/src/lib/libcrypto/asn1/asn_pack.c
@@ -75,7 +75,7 @@ ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
75 } else octmp = *oct; 75 } else octmp = *oct;
76 76
77 if(octmp->data) { 77 if(octmp->data) {
78 OPENSSL_free(octmp->data); 78 free(octmp->data);
79 octmp->data = NULL; 79 octmp->data = NULL;
80 } 80 }
81 81
diff --git a/src/lib/libcrypto/asn1/bio_asn1.c b/src/lib/libcrypto/asn1/bio_asn1.c
index dc7efd551c..fa98dba728 100644
--- a/src/lib/libcrypto/asn1/bio_asn1.c
+++ b/src/lib/libcrypto/asn1/bio_asn1.c
@@ -150,7 +150,7 @@ BIO_METHOD *BIO_f_asn1(void)
150static int asn1_bio_new(BIO *b) 150static int asn1_bio_new(BIO *b)
151 { 151 {
152 BIO_ASN1_BUF_CTX *ctx; 152 BIO_ASN1_BUF_CTX *ctx;
153 ctx = OPENSSL_malloc(sizeof(BIO_ASN1_BUF_CTX)); 153 ctx = malloc(sizeof(BIO_ASN1_BUF_CTX));
154 if (!ctx) 154 if (!ctx)
155 return 0; 155 return 0;
156 if (!asn1_bio_init(ctx, DEFAULT_ASN1_BUF_SIZE)) 156 if (!asn1_bio_init(ctx, DEFAULT_ASN1_BUF_SIZE))
@@ -163,7 +163,7 @@ static int asn1_bio_new(BIO *b)
163 163
164static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size) 164static int asn1_bio_init(BIO_ASN1_BUF_CTX *ctx, int size)
165 { 165 {
166 ctx->buf = OPENSSL_malloc(size); 166 ctx->buf = malloc(size);
167 if (!ctx->buf) 167 if (!ctx->buf)
168 return 0; 168 return 0;
169 ctx->bufsize = size; 169 ctx->bufsize = size;
@@ -186,8 +186,8 @@ static int asn1_bio_free(BIO *b)
186 if (ctx == NULL) 186 if (ctx == NULL)
187 return 0; 187 return 0;
188 if (ctx->buf) 188 if (ctx->buf)
189 OPENSSL_free(ctx->buf); 189 free(ctx->buf);
190 OPENSSL_free(ctx); 190 free(ctx);
191 b->init = 0; 191 b->init = 0;
192 b->ptr = NULL; 192 b->ptr = NULL;
193 b->flags = 0; 193 b->flags = 0;
diff --git a/src/lib/libcrypto/asn1/bio_ndef.c b/src/lib/libcrypto/asn1/bio_ndef.c
index b91f97a1b1..60f324bdae 100644
--- a/src/lib/libcrypto/asn1/bio_ndef.c
+++ b/src/lib/libcrypto/asn1/bio_ndef.c
@@ -110,7 +110,7 @@ BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it)
110 ASN1err(ASN1_F_BIO_NEW_NDEF, ASN1_R_STREAMING_NOT_SUPPORTED); 110 ASN1err(ASN1_F_BIO_NEW_NDEF, ASN1_R_STREAMING_NOT_SUPPORTED);
111 return NULL; 111 return NULL;
112 } 112 }
113 ndef_aux = OPENSSL_malloc(sizeof(NDEF_SUPPORT)); 113 ndef_aux = malloc(sizeof(NDEF_SUPPORT));
114 asn_bio = BIO_new(BIO_f_asn1()); 114 asn_bio = BIO_new(BIO_f_asn1());
115 115
116 /* ASN1 bio needs to be next to output BIO */ 116 /* ASN1 bio needs to be next to output BIO */
@@ -148,7 +148,7 @@ BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it)
148 if (asn_bio) 148 if (asn_bio)
149 BIO_free(asn_bio); 149 BIO_free(asn_bio);
150 if (ndef_aux) 150 if (ndef_aux)
151 OPENSSL_free(ndef_aux); 151 free(ndef_aux);
152 return NULL; 152 return NULL;
153 } 153 }
154 154
@@ -164,7 +164,7 @@ static int ndef_prefix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
164 ndef_aux = *(NDEF_SUPPORT **)parg; 164 ndef_aux = *(NDEF_SUPPORT **)parg;
165 165
166 derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it); 166 derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it);
167 p = OPENSSL_malloc(derlen); 167 p = malloc(derlen);
168 ndef_aux->derbuf = p; 168 ndef_aux->derbuf = p;
169 *pbuf = p; 169 *pbuf = p;
170 derlen = ASN1_item_ndef_i2d(ndef_aux->val, &p, ndef_aux->it); 170 derlen = ASN1_item_ndef_i2d(ndef_aux->val, &p, ndef_aux->it);
@@ -187,7 +187,7 @@ static int ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg)
187 ndef_aux = *(NDEF_SUPPORT **)parg; 187 ndef_aux = *(NDEF_SUPPORT **)parg;
188 188
189 if (ndef_aux->derbuf) 189 if (ndef_aux->derbuf)
190 OPENSSL_free(ndef_aux->derbuf); 190 free(ndef_aux->derbuf);
191 191
192 ndef_aux->derbuf = NULL; 192 ndef_aux->derbuf = NULL;
193 *pbuf = NULL; 193 *pbuf = NULL;
@@ -200,7 +200,7 @@ static int ndef_suffix_free(BIO *b, unsigned char **pbuf, int *plen, void *parg)
200 NDEF_SUPPORT **pndef_aux = (NDEF_SUPPORT **)parg; 200 NDEF_SUPPORT **pndef_aux = (NDEF_SUPPORT **)parg;
201 if (!ndef_prefix_free(b, pbuf, plen, parg)) 201 if (!ndef_prefix_free(b, pbuf, plen, parg))
202 return 0; 202 return 0;
203 OPENSSL_free(*pndef_aux); 203 free(*pndef_aux);
204 *pndef_aux = NULL; 204 *pndef_aux = NULL;
205 return 1; 205 return 1;
206 } 206 }
@@ -229,7 +229,7 @@ static int ndef_suffix(BIO *b, unsigned char **pbuf, int *plen, void *parg)
229 return 0; 229 return 0;
230 230
231 derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it); 231 derlen = ASN1_item_ndef_i2d(ndef_aux->val, NULL, ndef_aux->it);
232 p = OPENSSL_malloc(derlen); 232 p = malloc(derlen);
233 ndef_aux->derbuf = p; 233 ndef_aux->derbuf = p;
234 *pbuf = p; 234 *pbuf = p;
235 derlen = ASN1_item_ndef_i2d(ndef_aux->val, &p, ndef_aux->it); 235 derlen = ASN1_item_ndef_i2d(ndef_aux->val, &p, ndef_aux->it);
diff --git a/src/lib/libcrypto/asn1/f_enum.c b/src/lib/libcrypto/asn1/f_enum.c
index 56e3cc8df2..caf34ee97e 100644
--- a/src/lib/libcrypto/asn1/f_enum.c
+++ b/src/lib/libcrypto/asn1/f_enum.c
@@ -153,15 +153,15 @@ int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size)
153 if (num+i > slen) 153 if (num+i > slen)
154 { 154 {
155 if (s == NULL) 155 if (s == NULL)
156 sp=(unsigned char *)OPENSSL_malloc( 156 sp=(unsigned char *)malloc(
157 (unsigned int)num+i*2); 157 (unsigned int)num+i*2);
158 else 158 else
159 sp=(unsigned char *)OPENSSL_realloc(s, 159 sp=(unsigned char *)realloc(s,
160 (unsigned int)num+i*2); 160 (unsigned int)num+i*2);
161 if (sp == NULL) 161 if (sp == NULL)
162 { 162 {
163 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE); 163 ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE);
164 if (s != NULL) OPENSSL_free(s); 164 if (s != NULL) free(s);
165 goto err; 165 goto err;
166 } 166 }
167 s=sp; 167 s=sp;
diff --git a/src/lib/libcrypto/asn1/f_int.c b/src/lib/libcrypto/asn1/f_int.c
index 8b92fad9df..977e3d01b7 100644
--- a/src/lib/libcrypto/asn1/f_int.c
+++ b/src/lib/libcrypto/asn1/f_int.c
@@ -157,14 +157,14 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
157 if (num+i > slen) 157 if (num+i > slen)
158 { 158 {
159 if (s == NULL) 159 if (s == NULL)
160 sp=(unsigned char *)OPENSSL_malloc( 160 sp=(unsigned char *)malloc(
161 (unsigned int)num+i*2); 161 (unsigned int)num+i*2);
162 else 162 else
163 sp=OPENSSL_realloc_clean(s,slen,num+i*2); 163 sp=OPENSSL_realloc_clean(s,slen,num+i*2);
164 if (sp == NULL) 164 if (sp == NULL)
165 { 165 {
166 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); 166 ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE);
167 if (s != NULL) OPENSSL_free(s); 167 if (s != NULL) free(s);
168 goto err; 168 goto err;
169 } 169 }
170 s=sp; 170 s=sp;
diff --git a/src/lib/libcrypto/asn1/f_string.c b/src/lib/libcrypto/asn1/f_string.c
index f7d36adac7..f4bee15335 100644
--- a/src/lib/libcrypto/asn1/f_string.c
+++ b/src/lib/libcrypto/asn1/f_string.c
@@ -149,15 +149,15 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
149 if (num+i > slen) 149 if (num+i > slen)
150 { 150 {
151 if (s == NULL) 151 if (s == NULL)
152 sp=(unsigned char *)OPENSSL_malloc( 152 sp=(unsigned char *)malloc(
153 (unsigned int)num+i*2); 153 (unsigned int)num+i*2);
154 else 154 else
155 sp=(unsigned char *)OPENSSL_realloc(s, 155 sp=(unsigned char *)realloc(s,
156 (unsigned int)num+i*2); 156 (unsigned int)num+i*2);
157 if (sp == NULL) 157 if (sp == NULL)
158 { 158 {
159 ASN1err(ASN1_F_A2I_ASN1_STRING,ERR_R_MALLOC_FAILURE); 159 ASN1err(ASN1_F_A2I_ASN1_STRING,ERR_R_MALLOC_FAILURE);
160 if (s != NULL) OPENSSL_free(s); 160 if (s != NULL) free(s);
161 goto err; 161 goto err;
162 } 162 }
163 s=sp; 163 s=sp;
diff --git a/src/lib/libcrypto/asn1/n_pkey.c b/src/lib/libcrypto/asn1/n_pkey.c
index e251739933..97647d17e1 100644
--- a/src/lib/libcrypto/asn1/n_pkey.c
+++ b/src/lib/libcrypto/asn1/n_pkey.c
@@ -169,7 +169,7 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp,
169 169
170 170
171 /* Since its RC4 encrypted length is actual length */ 171 /* Since its RC4 encrypted length is actual length */
172 if ((zz=(unsigned char *)OPENSSL_malloc(rsalen)) == NULL) 172 if ((zz=(unsigned char *)malloc(rsalen)) == NULL)
173 { 173 {
174 ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); 174 ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE);
175 goto err; 175 goto err;
@@ -179,7 +179,7 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp,
179 /* Write out private key encoding */ 179 /* Write out private key encoding */
180 i2d_RSAPrivateKey(a,&zz); 180 i2d_RSAPrivateKey(a,&zz);
181 181
182 if ((zz=OPENSSL_malloc(pkeylen)) == NULL) 182 if ((zz=malloc(pkeylen)) == NULL)
183 { 183 {
184 ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); 184 ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE);
185 goto err; 185 goto err;
diff --git a/src/lib/libcrypto/asn1/p5_pbev2.c b/src/lib/libcrypto/asn1/p5_pbev2.c
index 4ea683036b..2d80334e01 100644
--- a/src/lib/libcrypto/asn1/p5_pbev2.c
+++ b/src/lib/libcrypto/asn1/p5_pbev2.c
@@ -214,7 +214,7 @@ X509_ALGOR *PKCS5_pbkdf2_set(int iter, unsigned char *salt, int saltlen,
214 214
215 if (!saltlen) 215 if (!saltlen)
216 saltlen = PKCS5_SALT_LEN; 216 saltlen = PKCS5_SALT_LEN;
217 if (!(osalt->data = OPENSSL_malloc (saltlen))) 217 if (!(osalt->data = malloc (saltlen)))
218 goto merr; 218 goto merr;
219 219
220 osalt->length = saltlen; 220 osalt->length = saltlen;
diff --git a/src/lib/libcrypto/asn1/t_crl.c b/src/lib/libcrypto/asn1/t_crl.c
index c61169208a..f6550b2b04 100644
--- a/src/lib/libcrypto/asn1/t_crl.c
+++ b/src/lib/libcrypto/asn1/t_crl.c
@@ -97,7 +97,7 @@ int X509_CRL_print(BIO *out, X509_CRL *x)
97 X509_signature_print(out, x->sig_alg, NULL); 97 X509_signature_print(out, x->sig_alg, NULL);
98 p=X509_NAME_oneline(X509_CRL_get_issuer(x),NULL,0); 98 p=X509_NAME_oneline(X509_CRL_get_issuer(x),NULL,0);
99 BIO_printf(out,"%8sIssuer: %s\n","",p); 99 BIO_printf(out,"%8sIssuer: %s\n","",p);
100 OPENSSL_free(p); 100 free(p);
101 BIO_printf(out,"%8sLast Update: ",""); 101 BIO_printf(out,"%8sLast Update: ","");
102 ASN1_TIME_print(out,X509_CRL_get_lastUpdate(x)); 102 ASN1_TIME_print(out,X509_CRL_get_lastUpdate(x));
103 BIO_printf(out,"\n%8sNext Update: ",""); 103 BIO_printf(out,"\n%8sNext Update: ","");
diff --git a/src/lib/libcrypto/asn1/t_x509.c b/src/lib/libcrypto/asn1/t_x509.c
index bbf00c7a29..8dfda07b92 100644
--- a/src/lib/libcrypto/asn1/t_x509.c
+++ b/src/lib/libcrypto/asn1/t_x509.c
@@ -239,7 +239,7 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag)
239 } 239 }
240 ret=1; 240 ret=1;
241err: 241err:
242 if (m != NULL) OPENSSL_free(m); 242 if (m != NULL) free(m);
243 return(ret); 243 return(ret);
244 } 244 }
245 245
@@ -256,7 +256,7 @@ int X509_ocspid_print (BIO *bp, X509 *x)
256 if (BIO_printf(bp," Subject OCSP hash: ") <= 0) 256 if (BIO_printf(bp," Subject OCSP hash: ") <= 0)
257 goto err; 257 goto err;
258 derlen = i2d_X509_NAME(x->cert_info->subject, NULL); 258 derlen = i2d_X509_NAME(x->cert_info->subject, NULL);
259 if ((der = dertmp = (unsigned char *)OPENSSL_malloc (derlen)) == NULL) 259 if ((der = dertmp = (unsigned char *)malloc (derlen)) == NULL)
260 goto err; 260 goto err;
261 i2d_X509_NAME(x->cert_info->subject, &dertmp); 261 i2d_X509_NAME(x->cert_info->subject, &dertmp);
262 262
@@ -266,7 +266,7 @@ int X509_ocspid_print (BIO *bp, X509 *x)
266 { 266 {
267 if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) goto err; 267 if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) goto err;
268 } 268 }
269 OPENSSL_free (der); 269 free (der);
270 der=NULL; 270 der=NULL;
271 271
272 /* display the hash of the public key as it would appear 272 /* display the hash of the public key as it would appear
@@ -287,7 +287,7 @@ int X509_ocspid_print (BIO *bp, X509 *x)
287 287
288 return (1); 288 return (1);
289err: 289err:
290 if (der != NULL) OPENSSL_free(der); 290 if (der != NULL) free(der);
291 return(0); 291 return(0);
292 } 292 }
293 293
@@ -477,7 +477,7 @@ int X509_NAME_print(BIO *bp, X509_NAME *name, int obase)
477 b=X509_NAME_oneline(name,NULL,0); 477 b=X509_NAME_oneline(name,NULL,0);
478 if (!*b) 478 if (!*b)
479 { 479 {
480 OPENSSL_free(b); 480 free(b);
481 return 1; 481 return 1;
482 } 482 }
483 s=b+1; /* skip the first slash */ 483 s=b+1; /* skip the first slash */
@@ -513,6 +513,6 @@ int X509_NAME_print(BIO *bp, X509_NAME *name, int obase)
513err: 513err:
514 X509err(X509_F_X509_NAME_PRINT,ERR_R_BUF_LIB); 514 X509err(X509_F_X509_NAME_PRINT,ERR_R_BUF_LIB);
515 } 515 }
516 OPENSSL_free(b); 516 free(b);
517 return(ret); 517 return(ret);
518 } 518 }
diff --git a/src/lib/libcrypto/asn1/tasn_dec.c b/src/lib/libcrypto/asn1/tasn_dec.c
index 87d7dfdf5c..c594db9140 100644
--- a/src/lib/libcrypto/asn1/tasn_dec.c
+++ b/src/lib/libcrypto/asn1/tasn_dec.c
@@ -910,7 +910,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
910 *in = p; 910 *in = p;
911 ret = 1; 911 ret = 1;
912 err: 912 err:
913 if (free_cont && buf.data) OPENSSL_free(buf.data); 913 if (free_cont && buf.data) free(buf.data);
914 return ret; 914 return ret;
915 } 915 }
916 916
@@ -1046,7 +1046,7 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
1046 if (*free_cont) 1046 if (*free_cont)
1047 { 1047 {
1048 if (stmp->data) 1048 if (stmp->data)
1049 OPENSSL_free(stmp->data); 1049 free(stmp->data);
1050 stmp->data = (unsigned char *)cont; /* UGLY CAST! RL */ 1050 stmp->data = (unsigned char *)cont; /* UGLY CAST! RL */
1051 stmp->length = len; 1051 stmp->length = len;
1052 *free_cont = 0; 1052 *free_cont = 0;
diff --git a/src/lib/libcrypto/asn1/tasn_enc.c b/src/lib/libcrypto/asn1/tasn_enc.c
index 936ad1f767..9ab0473d73 100644
--- a/src/lib/libcrypto/asn1/tasn_enc.c
+++ b/src/lib/libcrypto/asn1/tasn_enc.c
@@ -110,7 +110,7 @@ static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,
110 len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags); 110 len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags);
111 if (len <= 0) 111 if (len <= 0)
112 return len; 112 return len;
113 buf = OPENSSL_malloc(len); 113 buf = malloc(len);
114 if (!buf) 114 if (!buf)
115 return -1; 115 return -1;
116 p = buf; 116 p = buf;
@@ -451,9 +451,9 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
451 do_sort = 0; 451 do_sort = 0;
452 else 452 else
453 { 453 {
454 derlst = OPENSSL_malloc(sk_ASN1_VALUE_num(sk) 454 derlst = malloc(sk_ASN1_VALUE_num(sk)
455 * sizeof(*derlst)); 455 * sizeof(*derlst));
456 tmpdat = OPENSSL_malloc(skcontlen); 456 tmpdat = malloc(skcontlen);
457 if (!derlst || !tmpdat) 457 if (!derlst || !tmpdat)
458 return 0; 458 return 0;
459 } 459 }
@@ -496,8 +496,8 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
496 i++, tder++) 496 i++, tder++)
497 (void)sk_ASN1_VALUE_set(sk, i, tder->field); 497 (void)sk_ASN1_VALUE_set(sk, i, tder->field);
498 } 498 }
499 OPENSSL_free(derlst); 499 free(derlst);
500 OPENSSL_free(tmpdat); 500 free(tmpdat);
501 return 1; 501 return 1;
502 } 502 }
503 503
diff --git a/src/lib/libcrypto/asn1/tasn_fre.c b/src/lib/libcrypto/asn1/tasn_fre.c
index 77d3092d31..b04034ba4c 100644
--- a/src/lib/libcrypto/asn1/tasn_fre.c
+++ b/src/lib/libcrypto/asn1/tasn_fre.c
@@ -126,7 +126,7 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c
126 asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL); 126 asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL);
127 if (!combine) 127 if (!combine)
128 { 128 {
129 OPENSSL_free(*pval); 129 free(*pval);
130 *pval = NULL; 130 *pval = NULL;
131 } 131 }
132 break; 132 break;
@@ -173,7 +173,7 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c
173 asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL); 173 asn1_cb(ASN1_OP_FREE_POST, pval, it, NULL);
174 if (!combine) 174 if (!combine)
175 { 175 {
176 OPENSSL_free(*pval); 176 free(*pval);
177 *pval = NULL; 177 *pval = NULL;
178 } 178 }
179 break; 179 break;
@@ -254,7 +254,7 @@ void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
254 254
255 case V_ASN1_ANY: 255 case V_ASN1_ANY:
256 ASN1_primitive_free(pval, NULL); 256 ASN1_primitive_free(pval, NULL);
257 OPENSSL_free(*pval); 257 free(*pval);
258 break; 258 break;
259 259
260 default: 260 default:
diff --git a/src/lib/libcrypto/asn1/tasn_new.c b/src/lib/libcrypto/asn1/tasn_new.c
index 0d9e78cc7c..aab9ef08c4 100644
--- a/src/lib/libcrypto/asn1/tasn_new.c
+++ b/src/lib/libcrypto/asn1/tasn_new.c
@@ -160,7 +160,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
160 } 160 }
161 if (!combine) 161 if (!combine)
162 { 162 {
163 *pval = OPENSSL_malloc(it->size); 163 *pval = malloc(it->size);
164 if (!*pval) 164 if (!*pval)
165 goto memerr; 165 goto memerr;
166 memset(*pval, 0, it->size); 166 memset(*pval, 0, it->size);
@@ -188,7 +188,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
188 } 188 }
189 if (!combine) 189 if (!combine)
190 { 190 {
191 *pval = OPENSSL_malloc(it->size); 191 *pval = malloc(it->size);
192 if (!*pval) 192 if (!*pval)
193 goto memerr; 193 goto memerr;
194 memset(*pval, 0, it->size); 194 memset(*pval, 0, it->size);
@@ -354,7 +354,7 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
354 return 1; 354 return 1;
355 355
356 case V_ASN1_ANY: 356 case V_ASN1_ANY:
357 typ = OPENSSL_malloc(sizeof(ASN1_TYPE)); 357 typ = malloc(sizeof(ASN1_TYPE));
358 if (!typ) 358 if (!typ)
359 return 0; 359 return 0;
360 typ->value.ptr = NULL; 360 typ->value.ptr = NULL;
diff --git a/src/lib/libcrypto/asn1/tasn_prn.c b/src/lib/libcrypto/asn1/tasn_prn.c
index 542a091a66..ec524edac8 100644
--- a/src/lib/libcrypto/asn1/tasn_prn.c
+++ b/src/lib/libcrypto/asn1/tasn_prn.c
@@ -85,7 +85,7 @@ ASN1_PCTX default_pctx =
85ASN1_PCTX *ASN1_PCTX_new(void) 85ASN1_PCTX *ASN1_PCTX_new(void)
86 { 86 {
87 ASN1_PCTX *ret; 87 ASN1_PCTX *ret;
88 ret = OPENSSL_malloc(sizeof(ASN1_PCTX)); 88 ret = malloc(sizeof(ASN1_PCTX));
89 if (ret == NULL) 89 if (ret == NULL)
90 { 90 {
91 ASN1err(ASN1_F_ASN1_PCTX_NEW, ERR_R_MALLOC_FAILURE); 91 ASN1err(ASN1_F_ASN1_PCTX_NEW, ERR_R_MALLOC_FAILURE);
@@ -101,7 +101,7 @@ ASN1_PCTX *ASN1_PCTX_new(void)
101 101
102void ASN1_PCTX_free(ASN1_PCTX *p) 102void ASN1_PCTX_free(ASN1_PCTX *p)
103 { 103 {
104 OPENSSL_free(p); 104 free(p);
105 } 105 }
106 106
107unsigned long ASN1_PCTX_get_flags(ASN1_PCTX *p) 107unsigned long ASN1_PCTX_get_flags(ASN1_PCTX *p)
@@ -480,7 +480,7 @@ static int asn1_print_integer_ctx(BIO *out, ASN1_INTEGER *str,
480 s = i2s_ASN1_INTEGER(NULL, str); 480 s = i2s_ASN1_INTEGER(NULL, str);
481 if (BIO_puts(out, s) <= 0) 481 if (BIO_puts(out, s) <= 0)
482 ret = 0; 482 ret = 0;
483 OPENSSL_free(s); 483 free(s);
484 return ret; 484 return ret;
485 } 485 }
486 486
diff --git a/src/lib/libcrypto/asn1/tasn_utl.c b/src/lib/libcrypto/asn1/tasn_utl.c
index ca9ec7a32f..dfa63fb2bc 100644
--- a/src/lib/libcrypto/asn1/tasn_utl.c
+++ b/src/lib/libcrypto/asn1/tasn_utl.c
@@ -155,7 +155,7 @@ void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
155 if (enc) 155 if (enc)
156 { 156 {
157 if (enc->enc) 157 if (enc->enc)
158 OPENSSL_free(enc->enc); 158 free(enc->enc);
159 enc->enc = NULL; 159 enc->enc = NULL;
160 enc->len = 0; 160 enc->len = 0;
161 enc->modified = 1; 161 enc->modified = 1;
@@ -171,8 +171,8 @@ int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,
171 return 1; 171 return 1;
172 172
173 if (enc->enc) 173 if (enc->enc)
174 OPENSSL_free(enc->enc); 174 free(enc->enc);
175 enc->enc = OPENSSL_malloc(inlen); 175 enc->enc = malloc(inlen);
176 if (!enc->enc) 176 if (!enc->enc)
177 return 0; 177 return 0;
178 memcpy(enc->enc, in, inlen); 178 memcpy(enc->enc, in, inlen);
diff --git a/src/lib/libcrypto/asn1/x_crl.c b/src/lib/libcrypto/asn1/x_crl.c
index c51c690ba9..cf7e69aaaf 100644
--- a/src/lib/libcrypto/asn1/x_crl.c
+++ b/src/lib/libcrypto/asn1/x_crl.c
@@ -493,7 +493,7 @@ X509_CRL_METHOD *X509_CRL_METHOD_new(
493 int (*crl_verify)(X509_CRL *crl, EVP_PKEY *pk)) 493 int (*crl_verify)(X509_CRL *crl, EVP_PKEY *pk))
494 { 494 {
495 X509_CRL_METHOD *m; 495 X509_CRL_METHOD *m;
496 m = OPENSSL_malloc(sizeof(X509_CRL_METHOD)); 496 m = malloc(sizeof(X509_CRL_METHOD));
497 if (!m) 497 if (!m)
498 return NULL; 498 return NULL;
499 m->crl_init = crl_init; 499 m->crl_init = crl_init;
@@ -508,7 +508,7 @@ void X509_CRL_METHOD_free(X509_CRL_METHOD *m)
508 { 508 {
509 if (!(m->flags & X509_CRL_METHOD_DYNAMIC)) 509 if (!(m->flags & X509_CRL_METHOD_DYNAMIC))
510 return; 510 return;
511 OPENSSL_free(m); 511 free(m);
512 } 512 }
513 513
514void X509_CRL_set_meth_data(X509_CRL *crl, void *dat) 514void X509_CRL_set_meth_data(X509_CRL *crl, void *dat)
diff --git a/src/lib/libcrypto/asn1/x_info.c b/src/lib/libcrypto/asn1/x_info.c
index d44f6cdb01..c13fad056f 100644
--- a/src/lib/libcrypto/asn1/x_info.c
+++ b/src/lib/libcrypto/asn1/x_info.c
@@ -66,7 +66,7 @@ X509_INFO *X509_INFO_new(void)
66 { 66 {
67 X509_INFO *ret=NULL; 67 X509_INFO *ret=NULL;
68 68
69 ret=(X509_INFO *)OPENSSL_malloc(sizeof(X509_INFO)); 69 ret=(X509_INFO *)malloc(sizeof(X509_INFO));
70 if (ret == NULL) 70 if (ret == NULL)
71 { 71 {
72 ASN1err(ASN1_F_X509_INFO_NEW,ERR_R_MALLOC_FAILURE); 72 ASN1err(ASN1_F_X509_INFO_NEW,ERR_R_MALLOC_FAILURE);
@@ -106,8 +106,8 @@ void X509_INFO_free(X509_INFO *x)
106 if (x->x509 != NULL) X509_free(x->x509); 106 if (x->x509 != NULL) X509_free(x->x509);
107 if (x->crl != NULL) X509_CRL_free(x->crl); 107 if (x->crl != NULL) X509_CRL_free(x->crl);
108 if (x->x_pkey != NULL) X509_PKEY_free(x->x_pkey); 108 if (x->x_pkey != NULL) X509_PKEY_free(x->x_pkey);
109 if (x->enc_data != NULL) OPENSSL_free(x->enc_data); 109 if (x->enc_data != NULL) free(x->enc_data);
110 OPENSSL_free(x); 110 free(x);
111 } 111 }
112 112
113IMPLEMENT_STACK_OF(X509_INFO) 113IMPLEMENT_STACK_OF(X509_INFO)
diff --git a/src/lib/libcrypto/asn1/x_name.c b/src/lib/libcrypto/asn1/x_name.c
index d7c2318693..e14d329639 100644
--- a/src/lib/libcrypto/asn1/x_name.c
+++ b/src/lib/libcrypto/asn1/x_name.c
@@ -132,7 +132,7 @@ IMPLEMENT_ASN1_DUP_FUNCTION(X509_NAME)
132static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it) 132static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it)
133{ 133{
134 X509_NAME *ret = NULL; 134 X509_NAME *ret = NULL;
135 ret = OPENSSL_malloc(sizeof(X509_NAME)); 135 ret = malloc(sizeof(X509_NAME));
136 if(!ret) goto memerr; 136 if(!ret) goto memerr;
137 if ((ret->entries=sk_X509_NAME_ENTRY_new_null()) == NULL) 137 if ((ret->entries=sk_X509_NAME_ENTRY_new_null()) == NULL)
138 goto memerr; 138 goto memerr;
@@ -149,7 +149,7 @@ static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it)
149 { 149 {
150 if (ret->entries) 150 if (ret->entries)
151 sk_X509_NAME_ENTRY_free(ret->entries); 151 sk_X509_NAME_ENTRY_free(ret->entries);
152 OPENSSL_free(ret); 152 free(ret);
153 } 153 }
154 return 0; 154 return 0;
155} 155}
@@ -164,8 +164,8 @@ static void x509_name_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
164 BUF_MEM_free(a->bytes); 164 BUF_MEM_free(a->bytes);
165 sk_X509_NAME_ENTRY_pop_free(a->entries,X509_NAME_ENTRY_free); 165 sk_X509_NAME_ENTRY_pop_free(a->entries,X509_NAME_ENTRY_free);
166 if (a->canon_enc) 166 if (a->canon_enc)
167 OPENSSL_free(a->canon_enc); 167 free(a->canon_enc);
168 OPENSSL_free(a); 168 free(a);
169 *pval = NULL; 169 *pval = NULL;
170} 170}
171 171
@@ -325,7 +325,7 @@ static int x509_name_canon(X509_NAME *a)
325 325
326 if (a->canon_enc) 326 if (a->canon_enc)
327 { 327 {
328 OPENSSL_free(a->canon_enc); 328 free(a->canon_enc);
329 a->canon_enc = NULL; 329 a->canon_enc = NULL;
330 } 330 }
331 /* Special case: empty X509_NAME => null encoding */ 331 /* Special case: empty X509_NAME => null encoding */
@@ -362,7 +362,7 @@ static int x509_name_canon(X509_NAME *a)
362 362
363 a->canon_enclen = i2d_name_canon(intname, NULL); 363 a->canon_enclen = i2d_name_canon(intname, NULL);
364 364
365 p = OPENSSL_malloc(a->canon_enclen); 365 p = malloc(a->canon_enclen);
366 366
367 if (!p) 367 if (!p)
368 goto err; 368 goto err;
diff --git a/src/lib/libcrypto/asn1/x_pkey.c b/src/lib/libcrypto/asn1/x_pkey.c
index 8453618426..3bf2f5e915 100644
--- a/src/lib/libcrypto/asn1/x_pkey.c
+++ b/src/lib/libcrypto/asn1/x_pkey.c
@@ -146,6 +146,6 @@ void X509_PKEY_free(X509_PKEY *x)
146 if (x->enc_algor != NULL) X509_ALGOR_free(x->enc_algor); 146 if (x->enc_algor != NULL) X509_ALGOR_free(x->enc_algor);
147 if (x->enc_pkey != NULL) M_ASN1_OCTET_STRING_free(x->enc_pkey); 147 if (x->enc_pkey != NULL) M_ASN1_OCTET_STRING_free(x->enc_pkey);
148 if (x->dec_pkey != NULL)EVP_PKEY_free(x->dec_pkey); 148 if (x->dec_pkey != NULL)EVP_PKEY_free(x->dec_pkey);
149 if ((x->key_data != NULL) && (x->key_free)) OPENSSL_free(x->key_data); 149 if ((x->key_data != NULL) && (x->key_free)) free(x->key_data);
150 OPENSSL_free(x); 150 free(x);
151 } 151 }
diff --git a/src/lib/libcrypto/asn1/x_pubkey.c b/src/lib/libcrypto/asn1/x_pubkey.c
index b649e1fcf9..684f40899f 100644
--- a/src/lib/libcrypto/asn1/x_pubkey.c
+++ b/src/lib/libcrypto/asn1/x_pubkey.c
@@ -357,7 +357,7 @@ int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj,
357 if (penc) 357 if (penc)
358 { 358 {
359 if (pub->public_key->data) 359 if (pub->public_key->data)
360 OPENSSL_free(pub->public_key->data); 360 free(pub->public_key->data);
361 pub->public_key->data = penc; 361 pub->public_key->data = penc;
362 pub->public_key->length = penclen; 362 pub->public_key->length = penclen;
363 /* Set number of unused bits to zero */ 363 /* Set number of unused bits to zero */
diff --git a/src/lib/libcrypto/asn1/x_x509.c b/src/lib/libcrypto/asn1/x_x509.c
index de3df9eb51..5734f2b069 100644
--- a/src/lib/libcrypto/asn1/x_x509.c
+++ b/src/lib/libcrypto/asn1/x_x509.c
@@ -105,7 +105,7 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
105 break; 105 break;
106 106
107 case ASN1_OP_D2I_POST: 107 case ASN1_OP_D2I_POST:
108 if (ret->name != NULL) OPENSSL_free(ret->name); 108 if (ret->name != NULL) free(ret->name);
109 ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0); 109 ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0);
110 break; 110 break;
111 111
@@ -123,7 +123,7 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
123 ASIdentifiers_free(ret->rfc3779_asid); 123 ASIdentifiers_free(ret->rfc3779_asid);
124#endif 124#endif
125 125
126 if (ret->name != NULL) OPENSSL_free(ret->name); 126 if (ret->name != NULL) free(ret->name);
127 break; 127 break;
128 128
129 } 129 }
diff --git a/src/lib/libcrypto/bio/b_print.c b/src/lib/libcrypto/bio/b_print.c
index 55a5ca1a32..ff0089e82e 100644
--- a/src/lib/libcrypto/bio/b_print.c
+++ b/src/lib/libcrypto/bio/b_print.c
@@ -706,7 +706,7 @@ doapr_outch(char **sbuffer, char **buffer, size_t *currlen, size_t *maxlen,
706 if (*buffer == NULL) { 706 if (*buffer == NULL) {
707 if (*maxlen == 0) 707 if (*maxlen == 0)
708 *maxlen = 1024; 708 *maxlen = 1024;
709 *buffer = OPENSSL_malloc(*maxlen); 709 *buffer = malloc(*maxlen);
710 if (*currlen > 0) { 710 if (*currlen > 0) {
711 assert(*sbuffer != NULL); 711 assert(*sbuffer != NULL);
712 memcpy(*buffer, *sbuffer, *currlen); 712 memcpy(*buffer, *sbuffer, *currlen);
@@ -714,7 +714,7 @@ doapr_outch(char **sbuffer, char **buffer, size_t *currlen, size_t *maxlen,
714 *sbuffer = NULL; 714 *sbuffer = NULL;
715 } else { 715 } else {
716 *maxlen += 1024; 716 *maxlen += 1024;
717 *buffer = OPENSSL_realloc(*buffer, *maxlen); 717 *buffer = realloc(*buffer, *maxlen);
718 } 718 }
719 } 719 }
720 /* What to do if *buffer is NULL? */ 720 /* What to do if *buffer is NULL? */
@@ -764,7 +764,7 @@ int BIO_vprintf (BIO *bio, const char *format, va_list args)
764 format, args); 764 format, args);
765 if (dynbuf) { 765 if (dynbuf) {
766 ret = BIO_write(bio, dynbuf, (int)retlen); 766 ret = BIO_write(bio, dynbuf, (int)retlen);
767 OPENSSL_free(dynbuf); 767 free(dynbuf);
768 } else { 768 } else {
769 ret = BIO_write(bio, hugebuf, (int)retlen); 769 ret = BIO_write(bio, hugebuf, (int)retlen);
770 } 770 }
diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c
index b08226d52b..1ae9d96577 100644
--- a/src/lib/libcrypto/bio/b_sock.c
+++ b/src/lib/libcrypto/bio/b_sock.c
@@ -490,7 +490,7 @@ again:
490 ret = 1; 490 ret = 1;
491err: 491err:
492 if (str != NULL) 492 if (str != NULL)
493 OPENSSL_free(str); 493 free(str);
494 if ((ret == 0) && (s != -1)) { 494 if ((ret == 0) && (s != -1)) {
495 close(s); 495 close(s);
496 s = -1; 496 s = -1;
@@ -591,9 +591,9 @@ BIO_accept(int sock, char **addr)
591 p = *addr; 591 p = *addr;
592 if (p) { 592 if (p) {
593 *p = '\0'; 593 *p = '\0';
594 p = OPENSSL_realloc(p, nl); 594 p = realloc(p, nl);
595 } else { 595 } else {
596 p = OPENSSL_malloc(nl); 596 p = malloc(nl);
597 } 597 }
598 if (p == NULL) { 598 if (p == NULL) {
599 BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE); 599 BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE);
@@ -609,7 +609,7 @@ BIO_accept(int sock, char **addr)
609 l = ntohl(sa.from.sa_in.sin_addr.s_addr); 609 l = ntohl(sa.from.sa_in.sin_addr.s_addr);
610 port = ntohs(sa.from.sa_in.sin_port); 610 port = ntohs(sa.from.sa_in.sin_port);
611 if (*addr == NULL) { 611 if (*addr == NULL) {
612 if ((p = OPENSSL_malloc(24)) == NULL) { 612 if ((p = malloc(24)) == NULL) {
613 BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE); 613 BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE);
614 goto end; 614 goto end;
615 } 615 }
diff --git a/src/lib/libcrypto/bio/bf_buff.c b/src/lib/libcrypto/bio/bf_buff.c
index 937a1c58d5..be2ebab148 100644
--- a/src/lib/libcrypto/bio/bf_buff.c
+++ b/src/lib/libcrypto/bio/bf_buff.c
@@ -95,18 +95,18 @@ buffer_new(BIO *bi)
95{ 95{
96 BIO_F_BUFFER_CTX *ctx; 96 BIO_F_BUFFER_CTX *ctx;
97 97
98 ctx = (BIO_F_BUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_F_BUFFER_CTX)); 98 ctx = (BIO_F_BUFFER_CTX *)malloc(sizeof(BIO_F_BUFFER_CTX));
99 if (ctx == NULL) 99 if (ctx == NULL)
100 return (0); 100 return (0);
101 ctx->ibuf = (char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE); 101 ctx->ibuf = (char *)malloc(DEFAULT_BUFFER_SIZE);
102 if (ctx->ibuf == NULL) { 102 if (ctx->ibuf == NULL) {
103 OPENSSL_free(ctx); 103 free(ctx);
104 return (0); 104 return (0);
105 } 105 }
106 ctx->obuf = (char *)OPENSSL_malloc(DEFAULT_BUFFER_SIZE); 106 ctx->obuf = (char *)malloc(DEFAULT_BUFFER_SIZE);
107 if (ctx->obuf == NULL) { 107 if (ctx->obuf == NULL) {
108 OPENSSL_free(ctx->ibuf); 108 free(ctx->ibuf);
109 OPENSSL_free(ctx); 109 free(ctx);
110 return (0); 110 return (0);
111 } 111 }
112 ctx->ibuf_size = DEFAULT_BUFFER_SIZE; 112 ctx->ibuf_size = DEFAULT_BUFFER_SIZE;
@@ -131,10 +131,10 @@ buffer_free(BIO *a)
131 return (0); 131 return (0);
132 b = (BIO_F_BUFFER_CTX *)a->ptr; 132 b = (BIO_F_BUFFER_CTX *)a->ptr;
133 if (b->ibuf != NULL) 133 if (b->ibuf != NULL)
134 OPENSSL_free(b->ibuf); 134 free(b->ibuf);
135 if (b->obuf != NULL) 135 if (b->obuf != NULL)
136 OPENSSL_free(b->obuf); 136 free(b->obuf);
137 OPENSSL_free(a->ptr); 137 free(a->ptr);
138 a->ptr = NULL; 138 a->ptr = NULL;
139 a->init = 0; 139 a->init = 0;
140 a->flags = 0; 140 a->flags = 0;
@@ -339,11 +339,11 @@ buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
339 break; 339 break;
340 case BIO_C_SET_BUFF_READ_DATA: 340 case BIO_C_SET_BUFF_READ_DATA:
341 if (num > ctx->ibuf_size) { 341 if (num > ctx->ibuf_size) {
342 p1 = OPENSSL_malloc((int)num); 342 p1 = malloc((int)num);
343 if (p1 == NULL) 343 if (p1 == NULL)
344 goto malloc_error; 344 goto malloc_error;
345 if (ctx->ibuf != NULL) 345 if (ctx->ibuf != NULL)
346 OPENSSL_free(ctx->ibuf); 346 free(ctx->ibuf);
347 ctx->ibuf = p1; 347 ctx->ibuf = p1;
348 } 348 }
349 ctx->ibuf_off = 0; 349 ctx->ibuf_off = 0;
@@ -370,27 +370,27 @@ buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
370 p1 = ctx->ibuf; 370 p1 = ctx->ibuf;
371 p2 = ctx->obuf; 371 p2 = ctx->obuf;
372 if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size)) { 372 if ((ibs > DEFAULT_BUFFER_SIZE) && (ibs != ctx->ibuf_size)) {
373 p1 = (char *)OPENSSL_malloc((int)num); 373 p1 = (char *)malloc((int)num);
374 if (p1 == NULL) 374 if (p1 == NULL)
375 goto malloc_error; 375 goto malloc_error;
376 } 376 }
377 if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size)) { 377 if ((obs > DEFAULT_BUFFER_SIZE) && (obs != ctx->obuf_size)) {
378 p2 = (char *)OPENSSL_malloc((int)num); 378 p2 = (char *)malloc((int)num);
379 if (p2 == NULL) { 379 if (p2 == NULL) {
380 if (p1 != ctx->ibuf) 380 if (p1 != ctx->ibuf)
381 OPENSSL_free(p1); 381 free(p1);
382 goto malloc_error; 382 goto malloc_error;
383 } 383 }
384 } 384 }
385 if (ctx->ibuf != p1) { 385 if (ctx->ibuf != p1) {
386 OPENSSL_free(ctx->ibuf); 386 free(ctx->ibuf);
387 ctx->ibuf = p1; 387 ctx->ibuf = p1;
388 ctx->ibuf_off = 0; 388 ctx->ibuf_off = 0;
389 ctx->ibuf_len = 0; 389 ctx->ibuf_len = 0;
390 ctx->ibuf_size = ibs; 390 ctx->ibuf_size = ibs;
391 } 391 }
392 if (ctx->obuf != p2) { 392 if (ctx->obuf != p2) {
393 OPENSSL_free(ctx->obuf); 393 free(ctx->obuf);
394 ctx->obuf = p2; 394 ctx->obuf = p2;
395 ctx->obuf_off = 0; 395 ctx->obuf_off = 0;
396 ctx->obuf_len = 0; 396 ctx->obuf_len = 0;
diff --git a/src/lib/libcrypto/bio/bf_lbuf.c b/src/lib/libcrypto/bio/bf_lbuf.c
index 006ed9d91c..5020795ded 100644
--- a/src/lib/libcrypto/bio/bf_lbuf.c
+++ b/src/lib/libcrypto/bio/bf_lbuf.c
@@ -106,12 +106,12 @@ linebuffer_new(BIO *bi)
106{ 106{
107 BIO_LINEBUFFER_CTX *ctx; 107 BIO_LINEBUFFER_CTX *ctx;
108 108
109 ctx = (BIO_LINEBUFFER_CTX *)OPENSSL_malloc(sizeof(BIO_LINEBUFFER_CTX)); 109 ctx = (BIO_LINEBUFFER_CTX *)malloc(sizeof(BIO_LINEBUFFER_CTX));
110 if (ctx == NULL) 110 if (ctx == NULL)
111 return (0); 111 return (0);
112 ctx->obuf = (char *)OPENSSL_malloc(DEFAULT_LINEBUFFER_SIZE); 112 ctx->obuf = (char *)malloc(DEFAULT_LINEBUFFER_SIZE);
113 if (ctx->obuf == NULL) { 113 if (ctx->obuf == NULL) {
114 OPENSSL_free(ctx); 114 free(ctx);
115 return (0); 115 return (0);
116 } 116 }
117 ctx->obuf_size = DEFAULT_LINEBUFFER_SIZE; 117 ctx->obuf_size = DEFAULT_LINEBUFFER_SIZE;
@@ -132,8 +132,8 @@ linebuffer_free(BIO *a)
132 return (0); 132 return (0);
133 b = (BIO_LINEBUFFER_CTX *)a->ptr; 133 b = (BIO_LINEBUFFER_CTX *)a->ptr;
134 if (b->obuf != NULL) 134 if (b->obuf != NULL)
135 OPENSSL_free(b->obuf); 135 free(b->obuf);
136 OPENSSL_free(a->ptr); 136 free(a->ptr);
137 a->ptr = NULL; 137 a->ptr = NULL;
138 a->init = 0; 138 a->init = 0;
139 a->flags = 0; 139 a->flags = 0;
@@ -299,7 +299,7 @@ linebuffer_ctrl(BIO *b, int cmd, long num, void *ptr)
299 obs = (int)num; 299 obs = (int)num;
300 p = ctx->obuf; 300 p = ctx->obuf;
301 if ((obs > DEFAULT_LINEBUFFER_SIZE) && (obs != ctx->obuf_size)) { 301 if ((obs > DEFAULT_LINEBUFFER_SIZE) && (obs != ctx->obuf_size)) {
302 p = (char *)OPENSSL_malloc((int)num); 302 p = (char *)malloc((int)num);
303 if (p == NULL) 303 if (p == NULL)
304 goto malloc_error; 304 goto malloc_error;
305 } 305 }
@@ -308,7 +308,7 @@ linebuffer_ctrl(BIO *b, int cmd, long num, void *ptr)
308 ctx->obuf_len = obs; 308 ctx->obuf_len = obs;
309 } 309 }
310 memcpy(p, ctx->obuf, ctx->obuf_len); 310 memcpy(p, ctx->obuf, ctx->obuf_len);
311 OPENSSL_free(ctx->obuf); 311 free(ctx->obuf);
312 ctx->obuf = p; 312 ctx->obuf = p;
313 ctx->obuf_size = obs; 313 ctx->obuf_size = obs;
314 } 314 }
diff --git a/src/lib/libcrypto/bio/bf_nbio.c b/src/lib/libcrypto/bio/bf_nbio.c
index d181f518ec..200ca706ff 100644
--- a/src/lib/libcrypto/bio/bf_nbio.c
+++ b/src/lib/libcrypto/bio/bf_nbio.c
@@ -104,7 +104,7 @@ nbiof_new(BIO *bi)
104{ 104{
105 NBIO_TEST *nt; 105 NBIO_TEST *nt;
106 106
107 if (!(nt = (NBIO_TEST *)OPENSSL_malloc(sizeof(NBIO_TEST)))) 107 if (!(nt = (NBIO_TEST *)malloc(sizeof(NBIO_TEST))))
108 return (0); 108 return (0);
109 nt->lrn = -1; 109 nt->lrn = -1;
110 nt->lwn = -1; 110 nt->lwn = -1;
@@ -120,7 +120,7 @@ nbiof_free(BIO *a)
120 if (a == NULL) 120 if (a == NULL)
121 return (0); 121 return (0);
122 if (a->ptr != NULL) 122 if (a->ptr != NULL)
123 OPENSSL_free(a->ptr); 123 free(a->ptr);
124 a->ptr = NULL; 124 a->ptr = NULL;
125 a->init = 0; 125 a->init = 0;
126 a->flags = 0; 126 a->flags = 0;
diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c
index 90f1b1c1ef..c226d943af 100644
--- a/src/lib/libcrypto/bio/bio_lib.c
+++ b/src/lib/libcrypto/bio/bio_lib.c
@@ -68,13 +68,13 @@ BIO
68{ 68{
69 BIO *ret = NULL; 69 BIO *ret = NULL;
70 70
71 ret = (BIO *)OPENSSL_malloc(sizeof(BIO)); 71 ret = (BIO *)malloc(sizeof(BIO));
72 if (ret == NULL) { 72 if (ret == NULL) {
73 BIOerr(BIO_F_BIO_NEW, ERR_R_MALLOC_FAILURE); 73 BIOerr(BIO_F_BIO_NEW, ERR_R_MALLOC_FAILURE);
74 return (NULL); 74 return (NULL);
75 } 75 }
76 if (!BIO_set(ret, method)) { 76 if (!BIO_set(ret, method)) {
77 OPENSSL_free(ret); 77 free(ret);
78 ret = NULL; 78 ret = NULL;
79 } 79 }
80 return (ret); 80 return (ret);
@@ -136,7 +136,7 @@ BIO_free(BIO *a)
136 if ((a->method == NULL) || (a->method->destroy == NULL)) 136 if ((a->method == NULL) || (a->method->destroy == NULL))
137 return (1); 137 return (1);
138 a->method->destroy(a); 138 a->method->destroy(a);
139 OPENSSL_free(a); 139 free(a);
140 return (1); 140 return (1);
141} 141}
142 142
diff --git a/src/lib/libcrypto/bio/bss_acpt.c b/src/lib/libcrypto/bio/bss_acpt.c
index d7c151eaaa..161b5d01f8 100644
--- a/src/lib/libcrypto/bio/bss_acpt.c
+++ b/src/lib/libcrypto/bio/bss_acpt.c
@@ -137,7 +137,7 @@ static BIO_ACCEPT
137{ 137{
138 BIO_ACCEPT *ret; 138 BIO_ACCEPT *ret;
139 139
140 if ((ret = (BIO_ACCEPT *)OPENSSL_malloc(sizeof(BIO_ACCEPT))) == NULL) 140 if ((ret = (BIO_ACCEPT *)malloc(sizeof(BIO_ACCEPT))) == NULL)
141 return (NULL); 141 return (NULL);
142 142
143 memset(ret, 0, sizeof(BIO_ACCEPT)); 143 memset(ret, 0, sizeof(BIO_ACCEPT));
@@ -153,12 +153,12 @@ BIO_ACCEPT_free(BIO_ACCEPT *a)
153 return; 153 return;
154 154
155 if (a->param_addr != NULL) 155 if (a->param_addr != NULL)
156 OPENSSL_free(a->param_addr); 156 free(a->param_addr);
157 if (a->addr != NULL) 157 if (a->addr != NULL)
158 OPENSSL_free(a->addr); 158 free(a->addr);
159 if (a->bio_chain != NULL) 159 if (a->bio_chain != NULL)
160 BIO_free(a->bio_chain); 160 BIO_free(a->bio_chain);
161 OPENSSL_free(a); 161 free(a);
162} 162}
163 163
164static void 164static void
@@ -357,7 +357,7 @@ acpt_ctrl(BIO *b, int cmd, long num, void *ptr)
357 if (num == 0) { 357 if (num == 0) {
358 b->init = 1; 358 b->init = 1;
359 if (data->param_addr != NULL) 359 if (data->param_addr != NULL)
360 OPENSSL_free(data->param_addr); 360 free(data->param_addr);
361 data->param_addr = BUF_strdup(ptr); 361 data->param_addr = BUF_strdup(ptr);
362 } else if (num == 1) { 362 } else if (num == 1) {
363 data->accept_nbio = (ptr != NULL); 363 data->accept_nbio = (ptr != NULL);
diff --git a/src/lib/libcrypto/bio/bss_bio.c b/src/lib/libcrypto/bio/bss_bio.c
index a74fcfdabc..4d93aba0a4 100644
--- a/src/lib/libcrypto/bio/bss_bio.c
+++ b/src/lib/libcrypto/bio/bss_bio.c
@@ -146,7 +146,7 @@ bio_new(BIO *bio)
146{ 146{
147 struct bio_bio_st *b; 147 struct bio_bio_st *b;
148 148
149 b = OPENSSL_malloc(sizeof *b); 149 b = malloc(sizeof *b);
150 if (b == NULL) 150 if (b == NULL)
151 return 0; 151 return 0;
152 152
@@ -173,10 +173,10 @@ bio_free(BIO *bio)
173 bio_destroy_pair(bio); 173 bio_destroy_pair(bio);
174 174
175 if (b->buf != NULL) { 175 if (b->buf != NULL) {
176 OPENSSL_free(b->buf); 176 free(b->buf);
177 } 177 }
178 178
179 OPENSSL_free(b); 179 free(b);
180 180
181 return 1; 181 return 1;
182} 182}
@@ -516,7 +516,7 @@ bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
516 516
517 if (b->size != new_size) { 517 if (b->size != new_size) {
518 if (b->buf) { 518 if (b->buf) {
519 OPENSSL_free(b->buf); 519 free(b->buf);
520 b->buf = NULL; 520 b->buf = NULL;
521 } 521 }
522 b->size = new_size; 522 b->size = new_size;
@@ -701,7 +701,7 @@ bio_make_pair(BIO *bio1, BIO *bio2)
701 } 701 }
702 702
703 if (b1->buf == NULL) { 703 if (b1->buf == NULL) {
704 b1->buf = OPENSSL_malloc(b1->size); 704 b1->buf = malloc(b1->size);
705 if (b1->buf == NULL) { 705 if (b1->buf == NULL) {
706 BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE); 706 BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE);
707 return 0; 707 return 0;
@@ -711,7 +711,7 @@ bio_make_pair(BIO *bio1, BIO *bio2)
711 } 711 }
712 712
713 if (b2->buf == NULL) { 713 if (b2->buf == NULL) {
714 b2->buf = OPENSSL_malloc(b2->size); 714 b2->buf = malloc(b2->size);
715 if (b2->buf == NULL) { 715 if (b2->buf == NULL) {
716 BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE); 716 BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE);
717 return 0; 717 return 0;
diff --git a/src/lib/libcrypto/bio/bss_conn.c b/src/lib/libcrypto/bio/bss_conn.c
index db877b140b..78ce240648 100644
--- a/src/lib/libcrypto/bio/bss_conn.c
+++ b/src/lib/libcrypto/bio/bss_conn.c
@@ -147,7 +147,7 @@ conn_state(BIO *b, BIO_CONNECT *c)
147 break; 147 break;
148 } 148 }
149 if (c->param_port != NULL) 149 if (c->param_port != NULL)
150 OPENSSL_free(c->param_port); 150 free(c->param_port);
151 c->param_port = BUF_strdup(p); 151 c->param_port = BUF_strdup(p);
152 } 152 }
153 } 153 }
@@ -293,7 +293,7 @@ BIO_CONNECT
293{ 293{
294 BIO_CONNECT *ret; 294 BIO_CONNECT *ret;
295 295
296 if ((ret = (BIO_CONNECT *)OPENSSL_malloc(sizeof(BIO_CONNECT))) == NULL) 296 if ((ret = (BIO_CONNECT *)malloc(sizeof(BIO_CONNECT))) == NULL)
297 return (NULL); 297 return (NULL);
298 ret->state = BIO_CONN_S_BEFORE; 298 ret->state = BIO_CONN_S_BEFORE;
299 ret->param_hostname = NULL; 299 ret->param_hostname = NULL;
@@ -316,10 +316,10 @@ BIO_CONNECT_free(BIO_CONNECT *a)
316 return; 316 return;
317 317
318 if (a->param_hostname != NULL) 318 if (a->param_hostname != NULL)
319 OPENSSL_free(a->param_hostname); 319 free(a->param_hostname);
320 if (a->param_port != NULL) 320 if (a->param_port != NULL)
321 OPENSSL_free(a->param_port); 321 free(a->param_port);
322 OPENSSL_free(a); 322 free(a);
323} 323}
324 324
325BIO_METHOD 325BIO_METHOD
@@ -470,11 +470,11 @@ conn_ctrl(BIO *b, int cmd, long num, void *ptr)
470 b->init = 1; 470 b->init = 1;
471 if (num == 0) { 471 if (num == 0) {
472 if (data->param_hostname != NULL) 472 if (data->param_hostname != NULL)
473 OPENSSL_free(data->param_hostname); 473 free(data->param_hostname);
474 data->param_hostname = BUF_strdup(ptr); 474 data->param_hostname = BUF_strdup(ptr);
475 } else if (num == 1) { 475 } else if (num == 1) {
476 if (data->param_port != NULL) 476 if (data->param_port != NULL)
477 OPENSSL_free(data->param_port); 477 free(data->param_port);
478 data->param_port = BUF_strdup(ptr); 478 data->param_port = BUF_strdup(ptr);
479 } else if (num == 2) { 479 } else if (num == 2) {
480 char buf[16]; 480 char buf[16];
@@ -483,7 +483,7 @@ conn_ctrl(BIO *b, int cmd, long num, void *ptr)
483 (void) snprintf(buf, sizeof buf, "%d.%d.%d.%d", 483 (void) snprintf(buf, sizeof buf, "%d.%d.%d.%d",
484 p[0], p[1], p[2], p[3]); 484 p[0], p[1], p[2], p[3]);
485 if (data->param_hostname != NULL) 485 if (data->param_hostname != NULL)
486 OPENSSL_free(data->param_hostname); 486 free(data->param_hostname);
487 data->param_hostname = BUF_strdup(buf); 487 data->param_hostname = BUF_strdup(buf);
488 memcpy(&(data->ip[0]), ptr, 4); 488 memcpy(&(data->ip[0]), ptr, 4);
489 } else if (num == 3) { 489 } else if (num == 3) {
@@ -492,7 +492,7 @@ conn_ctrl(BIO *b, int cmd, long num, void *ptr)
492 (void) snprintf(buf, sizeof buf, "%d", 492 (void) snprintf(buf, sizeof buf, "%d",
493 *(int *)ptr); 493 *(int *)ptr);
494 if (data->param_port != NULL) 494 if (data->param_port != NULL)
495 OPENSSL_free(data->param_port); 495 free(data->param_port);
496 data->param_port = BUF_strdup(buf); 496 data->param_port = BUF_strdup(buf);
497 data->port= *(int *)ptr; 497 data->port= *(int *)ptr;
498 } 498 }
diff --git a/src/lib/libcrypto/bio/bss_dgram.c b/src/lib/libcrypto/bio/bss_dgram.c
index 478c765399..e0445fc97e 100644
--- a/src/lib/libcrypto/bio/bss_dgram.c
+++ b/src/lib/libcrypto/bio/bss_dgram.c
@@ -212,7 +212,7 @@ dgram_new(BIO *bi)
212 212
213 bi->init = 0; 213 bi->init = 0;
214 bi->num = 0; 214 bi->num = 0;
215 data = OPENSSL_malloc(sizeof(bio_dgram_data)); 215 data = malloc(sizeof(bio_dgram_data));
216 if (data == NULL) 216 if (data == NULL)
217 return 0; 217 return 0;
218 memset(data, 0x00, sizeof(bio_dgram_data)); 218 memset(data, 0x00, sizeof(bio_dgram_data));
@@ -234,7 +234,7 @@ dgram_free(BIO *a)
234 234
235 data = (bio_dgram_data *)a->ptr; 235 data = (bio_dgram_data *)a->ptr;
236 if (data != NULL) 236 if (data != NULL)
237 OPENSSL_free(data); 237 free(data);
238 238
239 return (1); 239 return (1);
240} 240}
@@ -805,7 +805,7 @@ BIO
805 * SCTP-AUTH has to be activated for the listening socket 805 * SCTP-AUTH has to be activated for the listening socket
806 * already, otherwise the connected socket won't use it. */ 806 * already, otherwise the connected socket won't use it. */
807 sockopt_len = (socklen_t)(sizeof(sctp_assoc_t) + 256 * sizeof(uint8_t)); 807 sockopt_len = (socklen_t)(sizeof(sctp_assoc_t) + 256 * sizeof(uint8_t));
808 authchunks = OPENSSL_malloc(sockopt_len); 808 authchunks = malloc(sockopt_len);
809 memset(authchunks, 0, sizeof(sockopt_len)); 809 memset(authchunks, 0, sizeof(sockopt_len));
810 ret = getsockopt(fd, IPPROTO_SCTP, SCTP_LOCAL_AUTH_CHUNKS, authchunks, &sockopt_len); 810 ret = getsockopt(fd, IPPROTO_SCTP, SCTP_LOCAL_AUTH_CHUNKS, authchunks, &sockopt_len);
811 OPENSSL_assert(ret >= 0); 811 OPENSSL_assert(ret >= 0);
@@ -819,7 +819,7 @@ BIO
819 auth_forward = 1; 819 auth_forward = 1;
820 } 820 }
821 821
822 OPENSSL_free(authchunks); 822 free(authchunks);
823 823
824 OPENSSL_assert(auth_data); 824 OPENSSL_assert(auth_data);
825 OPENSSL_assert(auth_forward); 825 OPENSSL_assert(auth_forward);
@@ -866,7 +866,7 @@ dgram_sctp_new(BIO *bi)
866 866
867 bi->init = 0; 867 bi->init = 0;
868 bi->num = 0; 868 bi->num = 0;
869 data = OPENSSL_malloc(sizeof(bio_dgram_sctp_data)); 869 data = malloc(sizeof(bio_dgram_sctp_data));
870 if (data == NULL) 870 if (data == NULL)
871 return 0; 871 return 0;
872 memset(data, 0x00, sizeof(bio_dgram_sctp_data)); 872 memset(data, 0x00, sizeof(bio_dgram_sctp_data));
@@ -891,7 +891,7 @@ dgram_sctp_free(BIO *a)
891 891
892 data = (bio_dgram_sctp_data *)a->ptr; 892 data = (bio_dgram_sctp_data *)a->ptr;
893 if (data != NULL) 893 if (data != NULL)
894 OPENSSL_free(data); 894 free(data);
895 895
896 return (1); 896 return (1);
897} 897}
@@ -998,7 +998,7 @@ dgram_sctp_read(BIO *b, char *out, int outl)
998 if (data->saved_message.length > 0) { 998 if (data->saved_message.length > 0) {
999 dgram_sctp_write(data->saved_message.bio, data->saved_message.data, 999 dgram_sctp_write(data->saved_message.bio, data->saved_message.data,
1000 data->saved_message.length); 1000 data->saved_message.length);
1001 OPENSSL_free(data->saved_message.data); 1001 free(data->saved_message.data);
1002 data->saved_message.length = 0; 1002 data->saved_message.length = 0;
1003 } 1003 }
1004 1004
@@ -1087,7 +1087,7 @@ dgram_sctp_read(BIO *b, char *out, int outl)
1087 struct sctp_authchunks *authchunks; 1087 struct sctp_authchunks *authchunks;
1088 1088
1089 optlen = (socklen_t)(sizeof(sctp_assoc_t) + 256 * sizeof(uint8_t)); 1089 optlen = (socklen_t)(sizeof(sctp_assoc_t) + 256 * sizeof(uint8_t));
1090 authchunks = OPENSSL_malloc(optlen); 1090 authchunks = malloc(optlen);
1091 memset(authchunks, 0, sizeof(optlen)); 1091 memset(authchunks, 0, sizeof(optlen));
1092 ii = getsockopt(b->num, IPPROTO_SCTP, SCTP_PEER_AUTH_CHUNKS, authchunks, &optlen); 1092 ii = getsockopt(b->num, IPPROTO_SCTP, SCTP_PEER_AUTH_CHUNKS, authchunks, &optlen);
1093 OPENSSL_assert(ii >= 0); 1093 OPENSSL_assert(ii >= 0);
@@ -1101,7 +1101,7 @@ dgram_sctp_read(BIO *b, char *out, int outl)
1101 auth_forward = 1; 1101 auth_forward = 1;
1102 } 1102 }
1103 1103
1104 OPENSSL_free(authchunks); 1104 free(authchunks);
1105 1105
1106 if (!auth_data || !auth_forward) { 1106 if (!auth_data || !auth_forward) {
1107 BIOerr(BIO_F_DGRAM_SCTP_READ, BIO_R_CONNECT_ERROR); 1107 BIOerr(BIO_F_DGRAM_SCTP_READ, BIO_R_CONNECT_ERROR);
@@ -1154,7 +1154,7 @@ dgram_sctp_write(BIO *b, const char *in, int inl)
1154 if (data->save_shutdown && !BIO_dgram_sctp_wait_for_dry(b)) { 1154 if (data->save_shutdown && !BIO_dgram_sctp_wait_for_dry(b)) {
1155 data->saved_message.bio = b; 1155 data->saved_message.bio = b;
1156 data->saved_message.length = inl; 1156 data->saved_message.length = inl;
1157 data->saved_message.data = OPENSSL_malloc(inl); 1157 data->saved_message.data = malloc(inl);
1158 memcpy(data->saved_message.data, in, inl); 1158 memcpy(data->saved_message.data, in, inl);
1159 return inl; 1159 return inl;
1160 } 1160 }
@@ -1282,7 +1282,7 @@ dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr)
1282 1282
1283 /* Add new key */ 1283 /* Add new key */
1284 sockopt_len = sizeof(struct sctp_authkey) + 64 * sizeof(uint8_t); 1284 sockopt_len = sizeof(struct sctp_authkey) + 64 * sizeof(uint8_t);
1285 authkey = OPENSSL_malloc(sockopt_len); 1285 authkey = malloc(sockopt_len);
1286 memset(authkey, 0x00, sockopt_len); 1286 memset(authkey, 0x00, sockopt_len);
1287 authkey->sca_keynumber = authkeyid.scact_keynumber + 1; 1287 authkey->sca_keynumber = authkeyid.scact_keynumber + 1;
1288#ifndef __FreeBSD__ 1288#ifndef __FreeBSD__
diff --git a/src/lib/libcrypto/bio/bss_log.c b/src/lib/libcrypto/bio/bss_log.c
index 2d38837f9e..cde3c858f1 100644
--- a/src/lib/libcrypto/bio/bss_log.c
+++ b/src/lib/libcrypto/bio/bss_log.c
@@ -157,7 +157,7 @@ slg_write(BIO *b, const char *in, int inl)
157 { 0, "", LOG_ERR } /* The default */ 157 { 0, "", LOG_ERR } /* The default */
158 }; 158 };
159 159
160 if ((buf = (char *)OPENSSL_malloc(inl + 1)) == NULL) { 160 if ((buf = (char *)malloc(inl + 1)) == NULL) {
161 return (0); 161 return (0);
162 } 162 }
163 strlcpy(buf, in, inl + 1); 163 strlcpy(buf, in, inl + 1);
@@ -169,7 +169,7 @@ slg_write(BIO *b, const char *in, int inl)
169 169
170 xsyslog(b, priority, pp); 170 xsyslog(b, priority, pp);
171 171
172 OPENSSL_free(buf); 172 free(buf);
173 return (ret); 173 return (ret);
174} 174}
175 175
diff --git a/src/lib/libcrypto/bn/bn_blind.c b/src/lib/libcrypto/bn/bn_blind.c
index 9ed8bc2b40..264531013e 100644
--- a/src/lib/libcrypto/bn/bn_blind.c
+++ b/src/lib/libcrypto/bn/bn_blind.c
@@ -140,7 +140,7 @@ BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, BIGNUM *mod)
140 140
141 bn_check_top(mod); 141 bn_check_top(mod);
142 142
143 if ((ret=(BN_BLINDING *)OPENSSL_malloc(sizeof(BN_BLINDING))) == NULL) 143 if ((ret=(BN_BLINDING *)malloc(sizeof(BN_BLINDING))) == NULL)
144 { 144 {
145 BNerr(BN_F_BN_BLINDING_NEW,ERR_R_MALLOC_FAILURE); 145 BNerr(BN_F_BN_BLINDING_NEW,ERR_R_MALLOC_FAILURE);
146 return(NULL); 146 return(NULL);
@@ -180,7 +180,7 @@ void BN_BLINDING_free(BN_BLINDING *r)
180 if (r->Ai != NULL) BN_free(r->Ai); 180 if (r->Ai != NULL) BN_free(r->Ai);
181 if (r->e != NULL) BN_free(r->e ); 181 if (r->e != NULL) BN_free(r->e );
182 if (r->mod != NULL) BN_free(r->mod); 182 if (r->mod != NULL) BN_free(r->mod);
183 OPENSSL_free(r); 183 free(r);
184 } 184 }
185 185
186int BN_BLINDING_update(BN_BLINDING *b, BN_CTX *ctx) 186int BN_BLINDING_update(BN_BLINDING *b, BN_CTX *ctx)
diff --git a/src/lib/libcrypto/bn/bn_ctx.c b/src/lib/libcrypto/bn/bn_ctx.c
index 3f2256f675..ef67f4781c 100644
--- a/src/lib/libcrypto/bn/bn_ctx.c
+++ b/src/lib/libcrypto/bn/bn_ctx.c
@@ -213,7 +213,7 @@ void BN_CTX_init(BN_CTX *ctx)
213 213
214BN_CTX *BN_CTX_new(void) 214BN_CTX *BN_CTX_new(void)
215 { 215 {
216 BN_CTX *ret = OPENSSL_malloc(sizeof(BN_CTX)); 216 BN_CTX *ret = malloc(sizeof(BN_CTX));
217 if(!ret) 217 if(!ret)
218 { 218 {
219 BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE); 219 BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);
@@ -249,7 +249,7 @@ void BN_CTX_free(BN_CTX *ctx)
249#endif 249#endif
250 BN_STACK_finish(&ctx->stack); 250 BN_STACK_finish(&ctx->stack);
251 BN_POOL_finish(&ctx->pool); 251 BN_POOL_finish(&ctx->pool);
252 OPENSSL_free(ctx); 252 free(ctx);
253 } 253 }
254 254
255void BN_CTX_start(BN_CTX *ctx) 255void BN_CTX_start(BN_CTX *ctx)
@@ -317,7 +317,7 @@ static void BN_STACK_init(BN_STACK *st)
317 317
318static void BN_STACK_finish(BN_STACK *st) 318static void BN_STACK_finish(BN_STACK *st)
319 { 319 {
320 if(st->size) OPENSSL_free(st->indexes); 320 if(st->size) free(st->indexes);
321 } 321 }
322 322
323#ifndef OPENSSL_NO_DEPRECATED 323#ifndef OPENSSL_NO_DEPRECATED
@@ -334,13 +334,13 @@ static int BN_STACK_push(BN_STACK *st, unsigned int idx)
334 { 334 {
335 unsigned int newsize = (st->size ? 335 unsigned int newsize = (st->size ?
336 (st->size * 3 / 2) : BN_CTX_START_FRAMES); 336 (st->size * 3 / 2) : BN_CTX_START_FRAMES);
337 unsigned int *newitems = OPENSSL_malloc(newsize * 337 unsigned int *newitems = malloc(newsize *
338 sizeof(unsigned int)); 338 sizeof(unsigned int));
339 if(!newitems) return 0; 339 if(!newitems) return 0;
340 if(st->depth) 340 if(st->depth)
341 memcpy(newitems, st->indexes, st->depth * 341 memcpy(newitems, st->indexes, st->depth *
342 sizeof(unsigned int)); 342 sizeof(unsigned int));
343 if(st->size) OPENSSL_free(st->indexes); 343 if(st->size) free(st->indexes);
344 st->indexes = newitems; 344 st->indexes = newitems;
345 st->size = newsize; 345 st->size = newsize;
346 } 346 }
@@ -375,7 +375,7 @@ static void BN_POOL_finish(BN_POOL *p)
375 bn++; 375 bn++;
376 } 376 }
377 p->current = p->head->next; 377 p->current = p->head->next;
378 OPENSSL_free(p->head); 378 free(p->head);
379 p->head = p->current; 379 p->head = p->current;
380 } 380 }
381 } 381 }
@@ -406,7 +406,7 @@ static BIGNUM *BN_POOL_get(BN_POOL *p)
406 { 406 {
407 BIGNUM *bn; 407 BIGNUM *bn;
408 unsigned int loop = 0; 408 unsigned int loop = 0;
409 BN_POOL_ITEM *item = OPENSSL_malloc(sizeof(BN_POOL_ITEM)); 409 BN_POOL_ITEM *item = malloc(sizeof(BN_POOL_ITEM));
410 if(!item) return NULL; 410 if(!item) return NULL;
411 /* Initialise the structure */ 411 /* Initialise the structure */
412 bn = item->vals; 412 bn = item->vals;
diff --git a/src/lib/libcrypto/bn/bn_exp.c b/src/lib/libcrypto/bn/bn_exp.c
index 2abf6fd678..2047e1cc3f 100644
--- a/src/lib/libcrypto/bn/bn_exp.c
+++ b/src/lib/libcrypto/bn/bn_exp.c
@@ -636,7 +636,7 @@ int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
636 powerbufFree = alloca(powerbufLen+MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH); 636 powerbufFree = alloca(powerbufLen+MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH);
637 else 637 else
638#endif 638#endif
639 if ((powerbufFree=(unsigned char*)OPENSSL_malloc(powerbufLen+MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH)) == NULL) 639 if ((powerbufFree=(unsigned char*)malloc(powerbufLen+MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH)) == NULL)
640 goto err; 640 goto err;
641 641
642 powerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree); 642 powerbuf = MOD_EXP_CTIME_ALIGN(powerbufFree);
@@ -823,7 +823,7 @@ err:
823 if (powerbuf!=NULL) 823 if (powerbuf!=NULL)
824 { 824 {
825 OPENSSL_cleanse(powerbuf,powerbufLen); 825 OPENSSL_cleanse(powerbuf,powerbufLen);
826 if (powerbufFree) OPENSSL_free(powerbufFree); 826 if (powerbufFree) free(powerbufFree);
827 } 827 }
828 BN_CTX_end(ctx); 828 BN_CTX_end(ctx);
829 return(ret); 829 return(ret);
diff --git a/src/lib/libcrypto/bn/bn_gf2m.c b/src/lib/libcrypto/bn/bn_gf2m.c
index 8a4dc20ad9..68a5faa52d 100644
--- a/src/lib/libcrypto/bn/bn_gf2m.c
+++ b/src/lib/libcrypto/bn/bn_gf2m.c
@@ -444,7 +444,7 @@ int BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *p
444 bn_check_top(a); 444 bn_check_top(a);
445 bn_check_top(b); 445 bn_check_top(b);
446 bn_check_top(p); 446 bn_check_top(p);
447 if ((arr = (int *)OPENSSL_malloc(sizeof(int) * max)) == NULL) goto err; 447 if ((arr = (int *)malloc(sizeof(int) * max)) == NULL) goto err;
448 ret = BN_GF2m_poly2arr(p, arr, max); 448 ret = BN_GF2m_poly2arr(p, arr, max);
449 if (!ret || ret > max) 449 if (!ret || ret > max)
450 { 450 {
@@ -454,7 +454,7 @@ int BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *p
454 ret = BN_GF2m_mod_mul_arr(r, a, b, arr, ctx); 454 ret = BN_GF2m_mod_mul_arr(r, a, b, arr, ctx);
455 bn_check_top(r); 455 bn_check_top(r);
456err: 456err:
457 if (arr) OPENSSL_free(arr); 457 if (arr) free(arr);
458 return ret; 458 return ret;
459 } 459 }
460 460
@@ -500,7 +500,7 @@ int BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
500 500
501 bn_check_top(a); 501 bn_check_top(a);
502 bn_check_top(p); 502 bn_check_top(p);
503 if ((arr = (int *)OPENSSL_malloc(sizeof(int) * max)) == NULL) goto err; 503 if ((arr = (int *)malloc(sizeof(int) * max)) == NULL) goto err;
504 ret = BN_GF2m_poly2arr(p, arr, max); 504 ret = BN_GF2m_poly2arr(p, arr, max);
505 if (!ret || ret > max) 505 if (!ret || ret > max)
506 { 506 {
@@ -510,7 +510,7 @@ int BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
510 ret = BN_GF2m_mod_sqr_arr(r, a, arr, ctx); 510 ret = BN_GF2m_mod_sqr_arr(r, a, arr, ctx);
511 bn_check_top(r); 511 bn_check_top(r);
512err: 512err:
513 if (arr) OPENSSL_free(arr); 513 if (arr) free(arr);
514 return ret; 514 return ret;
515 } 515 }
516 516
@@ -861,7 +861,7 @@ int BN_GF2m_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *p
861 bn_check_top(a); 861 bn_check_top(a);
862 bn_check_top(b); 862 bn_check_top(b);
863 bn_check_top(p); 863 bn_check_top(p);
864 if ((arr = (int *)OPENSSL_malloc(sizeof(int) * max)) == NULL) goto err; 864 if ((arr = (int *)malloc(sizeof(int) * max)) == NULL) goto err;
865 ret = BN_GF2m_poly2arr(p, arr, max); 865 ret = BN_GF2m_poly2arr(p, arr, max);
866 if (!ret || ret > max) 866 if (!ret || ret > max)
867 { 867 {
@@ -871,7 +871,7 @@ int BN_GF2m_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *p
871 ret = BN_GF2m_mod_exp_arr(r, a, b, arr, ctx); 871 ret = BN_GF2m_mod_exp_arr(r, a, b, arr, ctx);
872 bn_check_top(r); 872 bn_check_top(r);
873err: 873err:
874 if (arr) OPENSSL_free(arr); 874 if (arr) free(arr);
875 return ret; 875 return ret;
876 } 876 }
877 877
@@ -919,7 +919,7 @@ int BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
919 int *arr=NULL; 919 int *arr=NULL;
920 bn_check_top(a); 920 bn_check_top(a);
921 bn_check_top(p); 921 bn_check_top(p);
922 if ((arr = (int *)OPENSSL_malloc(sizeof(int) * max)) == NULL) goto err; 922 if ((arr = (int *)malloc(sizeof(int) * max)) == NULL) goto err;
923 ret = BN_GF2m_poly2arr(p, arr, max); 923 ret = BN_GF2m_poly2arr(p, arr, max);
924 if (!ret || ret > max) 924 if (!ret || ret > max)
925 { 925 {
@@ -929,7 +929,7 @@ int BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
929 ret = BN_GF2m_mod_sqrt_arr(r, a, arr, ctx); 929 ret = BN_GF2m_mod_sqrt_arr(r, a, arr, ctx);
930 bn_check_top(r); 930 bn_check_top(r);
931err: 931err:
932 if (arr) OPENSSL_free(arr); 932 if (arr) free(arr);
933 return ret; 933 return ret;
934 } 934 }
935 935
@@ -1037,7 +1037,7 @@ int BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *
1037 int *arr=NULL; 1037 int *arr=NULL;
1038 bn_check_top(a); 1038 bn_check_top(a);
1039 bn_check_top(p); 1039 bn_check_top(p);
1040 if ((arr = (int *)OPENSSL_malloc(sizeof(int) * 1040 if ((arr = (int *)malloc(sizeof(int) *
1041 max)) == NULL) goto err; 1041 max)) == NULL) goto err;
1042 ret = BN_GF2m_poly2arr(p, arr, max); 1042 ret = BN_GF2m_poly2arr(p, arr, max);
1043 if (!ret || ret > max) 1043 if (!ret || ret > max)
@@ -1048,7 +1048,7 @@ int BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *
1048 ret = BN_GF2m_mod_solve_quad_arr(r, a, arr, ctx); 1048 ret = BN_GF2m_mod_solve_quad_arr(r, a, arr, ctx);
1049 bn_check_top(r); 1049 bn_check_top(r);
1050err: 1050err:
1051 if (arr) OPENSSL_free(arr); 1051 if (arr) free(arr);
1052 return ret; 1052 return ret;
1053 } 1053 }
1054 1054
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c
index 5461e6ee7d..b491c785d4 100644
--- a/src/lib/libcrypto/bn/bn_lib.c
+++ b/src/lib/libcrypto/bn/bn_lib.c
@@ -245,12 +245,12 @@ void BN_clear_free(BIGNUM *a)
245 { 245 {
246 OPENSSL_cleanse(a->d,a->dmax*sizeof(a->d[0])); 246 OPENSSL_cleanse(a->d,a->dmax*sizeof(a->d[0]));
247 if (!(BN_get_flags(a,BN_FLG_STATIC_DATA))) 247 if (!(BN_get_flags(a,BN_FLG_STATIC_DATA)))
248 OPENSSL_free(a->d); 248 free(a->d);
249 } 249 }
250 i=BN_get_flags(a,BN_FLG_MALLOCED); 250 i=BN_get_flags(a,BN_FLG_MALLOCED);
251 OPENSSL_cleanse(a,sizeof(BIGNUM)); 251 OPENSSL_cleanse(a,sizeof(BIGNUM));
252 if (i) 252 if (i)
253 OPENSSL_free(a); 253 free(a);
254 } 254 }
255 255
256void BN_free(BIGNUM *a) 256void BN_free(BIGNUM *a)
@@ -258,9 +258,9 @@ void BN_free(BIGNUM *a)
258 if (a == NULL) return; 258 if (a == NULL) return;
259 bn_check_top(a); 259 bn_check_top(a);
260 if ((a->d != NULL) && !(BN_get_flags(a,BN_FLG_STATIC_DATA))) 260 if ((a->d != NULL) && !(BN_get_flags(a,BN_FLG_STATIC_DATA)))
261 OPENSSL_free(a->d); 261 free(a->d);
262 if (a->flags & BN_FLG_MALLOCED) 262 if (a->flags & BN_FLG_MALLOCED)
263 OPENSSL_free(a); 263 free(a);
264 else 264 else
265 { 265 {
266#ifndef OPENSSL_NO_DEPRECATED 266#ifndef OPENSSL_NO_DEPRECATED
@@ -280,7 +280,7 @@ BIGNUM *BN_new(void)
280 { 280 {
281 BIGNUM *ret; 281 BIGNUM *ret;
282 282
283 if ((ret=(BIGNUM *)OPENSSL_malloc(sizeof(BIGNUM))) == NULL) 283 if ((ret=(BIGNUM *)malloc(sizeof(BIGNUM))) == NULL)
284 { 284 {
285 BNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE); 285 BNerr(BN_F_BN_NEW,ERR_R_MALLOC_FAILURE);
286 return(NULL); 286 return(NULL);
@@ -314,7 +314,7 @@ static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
314 BNerr(BN_F_BN_EXPAND_INTERNAL,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); 314 BNerr(BN_F_BN_EXPAND_INTERNAL,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
315 return(NULL); 315 return(NULL);
316 } 316 }
317 a=A=(BN_ULONG *)OPENSSL_malloc(sizeof(BN_ULONG)*words); 317 a=A=(BN_ULONG *)malloc(sizeof(BN_ULONG)*words);
318 if (A == NULL) 318 if (A == NULL)
319 { 319 {
320 BNerr(BN_F_BN_EXPAND_INTERNAL,ERR_R_MALLOC_FAILURE); 320 BNerr(BN_F_BN_EXPAND_INTERNAL,ERR_R_MALLOC_FAILURE);
@@ -401,7 +401,7 @@ BIGNUM *bn_dup_expand(const BIGNUM *b, int words)
401 else 401 else
402 { 402 {
403 /* r == NULL, BN_new failure */ 403 /* r == NULL, BN_new failure */
404 OPENSSL_free(a); 404 free(a);
405 } 405 }
406 } 406 }
407 /* If a == NULL, there was an error in allocation in 407 /* If a == NULL, there was an error in allocation in
@@ -431,7 +431,7 @@ BIGNUM *bn_expand2(BIGNUM *b, int words)
431 { 431 {
432 BN_ULONG *a = bn_expand_internal(b, words); 432 BN_ULONG *a = bn_expand_internal(b, words);
433 if(!a) return NULL; 433 if(!a) return NULL;
434 if(b->d) OPENSSL_free(b->d); 434 if(b->d) free(b->d);
435 b->d=a; 435 b->d=a;
436 b->dmax=words; 436 b->dmax=words;
437 } 437 }
diff --git a/src/lib/libcrypto/bn/bn_mont.c b/src/lib/libcrypto/bn/bn_mont.c
index a6713ae5b1..133c597c33 100644
--- a/src/lib/libcrypto/bn/bn_mont.c
+++ b/src/lib/libcrypto/bn/bn_mont.c
@@ -322,7 +322,7 @@ BN_MONT_CTX *BN_MONT_CTX_new(void)
322 { 322 {
323 BN_MONT_CTX *ret; 323 BN_MONT_CTX *ret;
324 324
325 if ((ret=(BN_MONT_CTX *)OPENSSL_malloc(sizeof(BN_MONT_CTX))) == NULL) 325 if ((ret=(BN_MONT_CTX *)malloc(sizeof(BN_MONT_CTX))) == NULL)
326 return(NULL); 326 return(NULL);
327 327
328 BN_MONT_CTX_init(ret); 328 BN_MONT_CTX_init(ret);
@@ -349,7 +349,7 @@ void BN_MONT_CTX_free(BN_MONT_CTX *mont)
349 BN_free(&(mont->N)); 349 BN_free(&(mont->N));
350 BN_free(&(mont->Ni)); 350 BN_free(&(mont->Ni));
351 if (mont->flags & BN_FLG_MALLOCED) 351 if (mont->flags & BN_FLG_MALLOCED)
352 OPENSSL_free(mont); 352 free(mont);
353 } 353 }
354 354
355int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx) 355int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
diff --git a/src/lib/libcrypto/bn/bn_print.c b/src/lib/libcrypto/bn/bn_print.c
index c7c407e494..e2cab2497f 100644
--- a/src/lib/libcrypto/bn/bn_print.c
+++ b/src/lib/libcrypto/bn/bn_print.c
@@ -64,14 +64,14 @@
64 64
65static const char Hex[]="0123456789ABCDEF"; 65static const char Hex[]="0123456789ABCDEF";
66 66
67/* Must 'OPENSSL_free' the returned data */ 67/* Must 'free' the returned data */
68char *BN_bn2hex(const BIGNUM *a) 68char *BN_bn2hex(const BIGNUM *a)
69 { 69 {
70 int i,j,v,z=0; 70 int i,j,v,z=0;
71 char *buf; 71 char *buf;
72 char *p; 72 char *p;
73 73
74 buf=(char *)OPENSSL_malloc(a->top*BN_BYTES*2+2); 74 buf=(char *)malloc(a->top*BN_BYTES*2+2);
75 if (buf == NULL) 75 if (buf == NULL)
76 { 76 {
77 BNerr(BN_F_BN_BN2HEX,ERR_R_MALLOC_FAILURE); 77 BNerr(BN_F_BN_BN2HEX,ERR_R_MALLOC_FAILURE);
@@ -99,7 +99,7 @@ err:
99 return(buf); 99 return(buf);
100 } 100 }
101 101
102/* Must 'OPENSSL_free' the returned data */ 102/* Must 'free' the returned data */
103char *BN_bn2dec(const BIGNUM *a) 103char *BN_bn2dec(const BIGNUM *a)
104 { 104 {
105 int i=0,num, ok = 0; 105 int i=0,num, ok = 0;
@@ -115,8 +115,8 @@ char *BN_bn2dec(const BIGNUM *a)
115 */ 115 */
116 i=BN_num_bits(a)*3; 116 i=BN_num_bits(a)*3;
117 num=(i/10+i/1000+1)+1; 117 num=(i/10+i/1000+1)+1;
118 bn_data=(BN_ULONG *)OPENSSL_malloc((num/BN_DEC_NUM+1)*sizeof(BN_ULONG)); 118 bn_data=(BN_ULONG *)malloc((num/BN_DEC_NUM+1)*sizeof(BN_ULONG));
119 buf=(char *)OPENSSL_malloc(num+3); 119 buf=(char *)malloc(num+3);
120 if ((buf == NULL) || (bn_data == NULL)) 120 if ((buf == NULL) || (bn_data == NULL))
121 { 121 {
122 BNerr(BN_F_BN_BN2DEC,ERR_R_MALLOC_FAILURE); 122 BNerr(BN_F_BN_BN2DEC,ERR_R_MALLOC_FAILURE);
@@ -158,11 +158,11 @@ char *BN_bn2dec(const BIGNUM *a)
158 } 158 }
159 ok = 1; 159 ok = 1;
160err: 160err:
161 if (bn_data != NULL) OPENSSL_free(bn_data); 161 if (bn_data != NULL) free(bn_data);
162 if (t != NULL) BN_free(t); 162 if (t != NULL) BN_free(t);
163 if (!ok && buf) 163 if (!ok && buf)
164 { 164 {
165 OPENSSL_free(buf); 165 free(buf);
166 buf = NULL; 166 buf = NULL;
167 } 167 }
168 168
diff --git a/src/lib/libcrypto/bn/bn_rand.c b/src/lib/libcrypto/bn/bn_rand.c
index 5cbb1f33c1..baa62d584c 100644
--- a/src/lib/libcrypto/bn/bn_rand.c
+++ b/src/lib/libcrypto/bn/bn_rand.c
@@ -130,7 +130,7 @@ static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
130 bit=(bits-1)%8; 130 bit=(bits-1)%8;
131 mask=0xff<<(bit+1); 131 mask=0xff<<(bit+1);
132 132
133 buf=(unsigned char *)OPENSSL_malloc(bytes); 133 buf=(unsigned char *)malloc(bytes);
134 if (buf == NULL) 134 if (buf == NULL)
135 { 135 {
136 BNerr(BN_F_BNRAND,ERR_R_MALLOC_FAILURE); 136 BNerr(BN_F_BNRAND,ERR_R_MALLOC_FAILURE);
@@ -199,7 +199,7 @@ err:
199 if (buf != NULL) 199 if (buf != NULL)
200 { 200 {
201 OPENSSL_cleanse(buf,bytes); 201 OPENSSL_cleanse(buf,bytes);
202 OPENSSL_free(buf); 202 free(buf);
203 } 203 }
204 bn_check_top(rnd); 204 bn_check_top(rnd);
205 return(ret); 205 return(ret);
diff --git a/src/lib/libcrypto/bn/bn_recp.c b/src/lib/libcrypto/bn/bn_recp.c
index 2e8efb8dae..0f808fca64 100644
--- a/src/lib/libcrypto/bn/bn_recp.c
+++ b/src/lib/libcrypto/bn/bn_recp.c
@@ -72,7 +72,7 @@ BN_RECP_CTX *BN_RECP_CTX_new(void)
72 { 72 {
73 BN_RECP_CTX *ret; 73 BN_RECP_CTX *ret;
74 74
75 if ((ret=(BN_RECP_CTX *)OPENSSL_malloc(sizeof(BN_RECP_CTX))) == NULL) 75 if ((ret=(BN_RECP_CTX *)malloc(sizeof(BN_RECP_CTX))) == NULL)
76 return(NULL); 76 return(NULL);
77 77
78 BN_RECP_CTX_init(ret); 78 BN_RECP_CTX_init(ret);
@@ -88,7 +88,7 @@ void BN_RECP_CTX_free(BN_RECP_CTX *recp)
88 BN_free(&(recp->N)); 88 BN_free(&(recp->N));
89 BN_free(&(recp->Nr)); 89 BN_free(&(recp->Nr));
90 if (recp->flags & BN_FLG_MALLOCED) 90 if (recp->flags & BN_FLG_MALLOCED)
91 OPENSSL_free(recp); 91 free(recp);
92 } 92 }
93 93
94int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx) 94int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx)
diff --git a/src/lib/libcrypto/buffer/buf_str.c b/src/lib/libcrypto/buffer/buf_str.c
index 151f5ea971..ab5535f476 100644
--- a/src/lib/libcrypto/buffer/buf_str.c
+++ b/src/lib/libcrypto/buffer/buf_str.c
@@ -72,7 +72,7 @@ char *BUF_strndup(const char *str, size_t siz)
72 72
73 if (str == NULL) return(NULL); 73 if (str == NULL) return(NULL);
74 74
75 ret=OPENSSL_malloc(siz+1); 75 ret=malloc(siz+1);
76 if (ret == NULL) 76 if (ret == NULL)
77 { 77 {
78 BUFerr(BUF_F_BUF_STRNDUP,ERR_R_MALLOC_FAILURE); 78 BUFerr(BUF_F_BUF_STRNDUP,ERR_R_MALLOC_FAILURE);
@@ -88,7 +88,7 @@ void *BUF_memdup(const void *data, size_t siz)
88 88
89 if (data == NULL) return(NULL); 89 if (data == NULL) return(NULL);
90 90
91 ret=OPENSSL_malloc(siz); 91 ret=malloc(siz);
92 if (ret == NULL) 92 if (ret == NULL)
93 { 93 {
94 BUFerr(BUF_F_BUF_MEMDUP,ERR_R_MALLOC_FAILURE); 94 BUFerr(BUF_F_BUF_MEMDUP,ERR_R_MALLOC_FAILURE);
diff --git a/src/lib/libcrypto/buffer/buffer.c b/src/lib/libcrypto/buffer/buffer.c
index d4a4ce43b3..b52c59f8a3 100644
--- a/src/lib/libcrypto/buffer/buffer.c
+++ b/src/lib/libcrypto/buffer/buffer.c
@@ -69,7 +69,7 @@ BUF_MEM *BUF_MEM_new(void)
69 { 69 {
70 BUF_MEM *ret; 70 BUF_MEM *ret;
71 71
72 ret=OPENSSL_malloc(sizeof(BUF_MEM)); 72 ret=malloc(sizeof(BUF_MEM));
73 if (ret == NULL) 73 if (ret == NULL)
74 { 74 {
75 BUFerr(BUF_F_BUF_MEM_NEW,ERR_R_MALLOC_FAILURE); 75 BUFerr(BUF_F_BUF_MEM_NEW,ERR_R_MALLOC_FAILURE);
@@ -89,9 +89,9 @@ void BUF_MEM_free(BUF_MEM *a)
89 if (a->data != NULL) 89 if (a->data != NULL)
90 { 90 {
91 memset(a->data,0,(unsigned int)a->max); 91 memset(a->data,0,(unsigned int)a->max);
92 OPENSSL_free(a->data); 92 free(a->data);
93 } 93 }
94 OPENSSL_free(a); 94 free(a);
95 } 95 }
96 96
97int BUF_MEM_grow(BUF_MEM *str, size_t len) 97int BUF_MEM_grow(BUF_MEM *str, size_t len)
@@ -118,9 +118,9 @@ int BUF_MEM_grow(BUF_MEM *str, size_t len)
118 } 118 }
119 n=(len+3)/3*4; 119 n=(len+3)/3*4;
120 if (str->data == NULL) 120 if (str->data == NULL)
121 ret=OPENSSL_malloc(n); 121 ret=malloc(n);
122 else 122 else
123 ret=OPENSSL_realloc(str->data,n); 123 ret=realloc(str->data,n);
124 if (ret == NULL) 124 if (ret == NULL)
125 { 125 {
126 BUFerr(BUF_F_BUF_MEM_GROW,ERR_R_MALLOC_FAILURE); 126 BUFerr(BUF_F_BUF_MEM_GROW,ERR_R_MALLOC_FAILURE);
@@ -161,7 +161,7 @@ int BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
161 } 161 }
162 n=(len+3)/3*4; 162 n=(len+3)/3*4;
163 if (str->data == NULL) 163 if (str->data == NULL)
164 ret=OPENSSL_malloc(n); 164 ret=malloc(n);
165 else 165 else
166 ret=OPENSSL_realloc_clean(str->data,str->max,n); 166 ret=OPENSSL_realloc_clean(str->data,str->max,n);
167 if (ret == NULL) 167 if (ret == NULL)
diff --git a/src/lib/libcrypto/cmac/cm_pmeth.c b/src/lib/libcrypto/cmac/cm_pmeth.c
index 072228ec7f..00aa4d64d2 100644
--- a/src/lib/libcrypto/cmac/cm_pmeth.c
+++ b/src/lib/libcrypto/cmac/cm_pmeth.c
@@ -182,7 +182,7 @@ static int pkey_cmac_ctrl_str(EVP_PKEY_CTX *ctx,
182 if (!key) 182 if (!key)
183 return 0; 183 return 0;
184 r = pkey_cmac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, keylen, key); 184 r = pkey_cmac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, keylen, key);
185 OPENSSL_free(key); 185 free(key);
186 return r; 186 return r;
187 } 187 }
188 return -2; 188 return -2;
diff --git a/src/lib/libcrypto/cmac/cmac.c b/src/lib/libcrypto/cmac/cmac.c
index f92a7bb143..81188c8f5a 100644
--- a/src/lib/libcrypto/cmac/cmac.c
+++ b/src/lib/libcrypto/cmac/cmac.c
@@ -93,7 +93,7 @@ static void make_kn(unsigned char *k1, unsigned char *l, int bl)
93CMAC_CTX *CMAC_CTX_new(void) 93CMAC_CTX *CMAC_CTX_new(void)
94 { 94 {
95 CMAC_CTX *ctx; 95 CMAC_CTX *ctx;
96 ctx = OPENSSL_malloc(sizeof(CMAC_CTX)); 96 ctx = malloc(sizeof(CMAC_CTX));
97 if (!ctx) 97 if (!ctx)
98 return NULL; 98 return NULL;
99 EVP_CIPHER_CTX_init(&ctx->cctx); 99 EVP_CIPHER_CTX_init(&ctx->cctx);
@@ -119,7 +119,7 @@ EVP_CIPHER_CTX *CMAC_CTX_get0_cipher_ctx(CMAC_CTX *ctx)
119void CMAC_CTX_free(CMAC_CTX *ctx) 119void CMAC_CTX_free(CMAC_CTX *ctx)
120 { 120 {
121 CMAC_CTX_cleanup(ctx); 121 CMAC_CTX_cleanup(ctx);
122 OPENSSL_free(ctx); 122 free(ctx);
123 } 123 }
124 124
125int CMAC_CTX_copy(CMAC_CTX *out, const CMAC_CTX *in) 125int CMAC_CTX_copy(CMAC_CTX *out, const CMAC_CTX *in)
diff --git a/src/lib/libcrypto/cms/cms_asn1.c b/src/lib/libcrypto/cms/cms_asn1.c
index cfe67fb6c1..bd7466cc1d 100644
--- a/src/lib/libcrypto/cms/cms_asn1.c
+++ b/src/lib/libcrypto/cms/cms_asn1.c
@@ -234,7 +234,7 @@ static int cms_ri_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
234 if (kekri->key) 234 if (kekri->key)
235 { 235 {
236 OPENSSL_cleanse(kekri->key, kekri->keylen); 236 OPENSSL_cleanse(kekri->key, kekri->keylen);
237 OPENSSL_free(kekri->key); 237 free(kekri->key);
238 } 238 }
239 } 239 }
240 else if (ri->type == CMS_RECIPINFO_PASS) 240 else if (ri->type == CMS_RECIPINFO_PASS)
@@ -243,7 +243,7 @@ static int cms_ri_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
243 if (pwri->pass) 243 if (pwri->pass)
244 { 244 {
245 OPENSSL_cleanse(pwri->pass, pwri->passlen); 245 OPENSSL_cleanse(pwri->pass, pwri->passlen);
246 OPENSSL_free(pwri->pass); 246 free(pwri->pass);
247 } 247 }
248 } 248 }
249 } 249 }
diff --git a/src/lib/libcrypto/cms/cms_enc.c b/src/lib/libcrypto/cms/cms_enc.c
index bebeaf29c7..612fce6dde 100644
--- a/src/lib/libcrypto/cms/cms_enc.c
+++ b/src/lib/libcrypto/cms/cms_enc.c
@@ -143,7 +143,7 @@ BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec)
143 /* Generate random session key */ 143 /* Generate random session key */
144 if (!enc || !ec->key) 144 if (!enc || !ec->key)
145 { 145 {
146 tkey = OPENSSL_malloc(tkeylen); 146 tkey = malloc(tkeylen);
147 if (!tkey) 147 if (!tkey)
148 { 148 {
149 CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO, 149 CMSerr(CMS_F_CMS_ENCRYPTEDCONTENT_INIT_BIO,
@@ -184,7 +184,7 @@ BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec)
184 { 184 {
185 /* Use random key */ 185 /* Use random key */
186 OPENSSL_cleanse(ec->key, ec->keylen); 186 OPENSSL_cleanse(ec->key, ec->keylen);
187 OPENSSL_free(ec->key); 187 free(ec->key);
188 ec->key = tkey; 188 ec->key = tkey;
189 ec->keylen = tkeylen; 189 ec->keylen = tkeylen;
190 tkey = NULL; 190 tkey = NULL;
@@ -222,13 +222,13 @@ BIO *cms_EncryptedContent_init_bio(CMS_EncryptedContentInfo *ec)
222 if (ec->key && !keep_key) 222 if (ec->key && !keep_key)
223 { 223 {
224 OPENSSL_cleanse(ec->key, ec->keylen); 224 OPENSSL_cleanse(ec->key, ec->keylen);
225 OPENSSL_free(ec->key); 225 free(ec->key);
226 ec->key = NULL; 226 ec->key = NULL;
227 } 227 }
228 if (tkey) 228 if (tkey)
229 { 229 {
230 OPENSSL_cleanse(tkey, tkeylen); 230 OPENSSL_cleanse(tkey, tkeylen);
231 OPENSSL_free(tkey); 231 free(tkey);
232 } 232 }
233 if (ok) 233 if (ok)
234 return b; 234 return b;
@@ -243,7 +243,7 @@ int cms_EncryptedContent_init(CMS_EncryptedContentInfo *ec,
243 ec->cipher = cipher; 243 ec->cipher = cipher;
244 if (key) 244 if (key)
245 { 245 {
246 ec->key = OPENSSL_malloc(keylen); 246 ec->key = malloc(keylen);
247 if (!ec->key) 247 if (!ec->key)
248 return 0; 248 return 0;
249 memcpy(ec->key, key, keylen); 249 memcpy(ec->key, key, keylen);
diff --git a/src/lib/libcrypto/cms/cms_env.c b/src/lib/libcrypto/cms/cms_env.c
index be20b1c024..78fa2aa7b7 100644
--- a/src/lib/libcrypto/cms/cms_env.c
+++ b/src/lib/libcrypto/cms/cms_env.c
@@ -334,7 +334,7 @@ static int cms_RecipientInfo_ktri_encrypt(CMS_ContentInfo *cms,
334 if (EVP_PKEY_encrypt(pctx, NULL, &eklen, ec->key, ec->keylen) <= 0) 334 if (EVP_PKEY_encrypt(pctx, NULL, &eklen, ec->key, ec->keylen) <= 0)
335 goto err; 335 goto err;
336 336
337 ek = OPENSSL_malloc(eklen); 337 ek = malloc(eklen);
338 338
339 if (ek == NULL) 339 if (ek == NULL)
340 { 340 {
@@ -355,7 +355,7 @@ static int cms_RecipientInfo_ktri_encrypt(CMS_ContentInfo *cms,
355 if (pctx) 355 if (pctx)
356 EVP_PKEY_CTX_free(pctx); 356 EVP_PKEY_CTX_free(pctx);
357 if (ek) 357 if (ek)
358 OPENSSL_free(ek); 358 free(ek);
359 return ret; 359 return ret;
360 360
361 } 361 }
@@ -399,7 +399,7 @@ static int cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms,
399 ktri->encryptedKey->length) <= 0) 399 ktri->encryptedKey->length) <= 0)
400 goto err; 400 goto err;
401 401
402 ek = OPENSSL_malloc(eklen); 402 ek = malloc(eklen);
403 403
404 if (ek == NULL) 404 if (ek == NULL)
405 { 405 {
@@ -421,7 +421,7 @@ static int cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms,
421 if (ec->key) 421 if (ec->key)
422 { 422 {
423 OPENSSL_cleanse(ec->key, ec->keylen); 423 OPENSSL_cleanse(ec->key, ec->keylen);
424 OPENSSL_free(ec->key); 424 free(ec->key);
425 } 425 }
426 426
427 ec->key = ek; 427 ec->key = ek;
@@ -431,7 +431,7 @@ static int cms_RecipientInfo_ktri_decrypt(CMS_ContentInfo *cms,
431 if (pctx) 431 if (pctx)
432 EVP_PKEY_CTX_free(pctx); 432 EVP_PKEY_CTX_free(pctx);
433 if (!ret && ek) 433 if (!ret && ek)
434 OPENSSL_free(ek); 434 free(ek);
435 435
436 return ret; 436 return ret;
437 } 437 }
@@ -671,7 +671,7 @@ static int cms_RecipientInfo_kekri_encrypt(CMS_ContentInfo *cms,
671 goto err; 671 goto err;
672 } 672 }
673 673
674 wkey = OPENSSL_malloc(ec->keylen + 8); 674 wkey = malloc(ec->keylen + 8);
675 675
676 if (!wkey) 676 if (!wkey)
677 { 677 {
@@ -695,7 +695,7 @@ static int cms_RecipientInfo_kekri_encrypt(CMS_ContentInfo *cms,
695 err: 695 err:
696 696
697 if (!r && wkey) 697 if (!r && wkey)
698 OPENSSL_free(wkey); 698 free(wkey);
699 OPENSSL_cleanse(&actx, sizeof(actx)); 699 OPENSSL_cleanse(&actx, sizeof(actx));
700 700
701 return r; 701 return r;
@@ -748,7 +748,7 @@ static int cms_RecipientInfo_kekri_decrypt(CMS_ContentInfo *cms,
748 goto err; 748 goto err;
749 } 749 }
750 750
751 ukey = OPENSSL_malloc(kekri->encryptedKey->length - 8); 751 ukey = malloc(kekri->encryptedKey->length - 8);
752 752
753 if (!ukey) 753 if (!ukey)
754 { 754 {
@@ -776,7 +776,7 @@ static int cms_RecipientInfo_kekri_decrypt(CMS_ContentInfo *cms,
776 err: 776 err:
777 777
778 if (!r && ukey) 778 if (!r && ukey)
779 OPENSSL_free(ukey); 779 free(ukey);
780 OPENSSL_cleanse(&actx, sizeof(actx)); 780 OPENSSL_cleanse(&actx, sizeof(actx));
781 781
782 return r; 782 return r;
@@ -864,7 +864,7 @@ BIO *cms_EnvelopedData_init_bio(CMS_ContentInfo *cms)
864 if (ec->key) 864 if (ec->key)
865 { 865 {
866 OPENSSL_cleanse(ec->key, ec->keylen); 866 OPENSSL_cleanse(ec->key, ec->keylen);
867 OPENSSL_free(ec->key); 867 free(ec->key);
868 ec->key = NULL; 868 ec->key = NULL;
869 ec->keylen = 0; 869 ec->keylen = 0;
870 } 870 }
diff --git a/src/lib/libcrypto/cms/cms_ess.c b/src/lib/libcrypto/cms/cms_ess.c
index 90c0b82fb5..99a4da6356 100644
--- a/src/lib/libcrypto/cms/cms_ess.c
+++ b/src/lib/libcrypto/cms/cms_ess.c
@@ -157,7 +157,7 @@ int CMS_add1_ReceiptRequest(CMS_SignerInfo *si, CMS_ReceiptRequest *rr)
157 CMSerr(CMS_F_CMS_ADD1_RECEIPTREQUEST, ERR_R_MALLOC_FAILURE); 157 CMSerr(CMS_F_CMS_ADD1_RECEIPTREQUEST, ERR_R_MALLOC_FAILURE);
158 158
159 if (rrder) 159 if (rrder)
160 OPENSSL_free(rrder); 160 free(rrder);
161 161
162 return r; 162 return r;
163 163
diff --git a/src/lib/libcrypto/cms/cms_pwri.c b/src/lib/libcrypto/cms/cms_pwri.c
index b79612a12d..36a5db04b8 100644
--- a/src/lib/libcrypto/cms/cms_pwri.c
+++ b/src/lib/libcrypto/cms/cms_pwri.c
@@ -237,7 +237,7 @@ static int kek_unwrap_key(unsigned char *out, size_t *outlen,
237 /* Invalid size */ 237 /* Invalid size */
238 return 0; 238 return 0;
239 } 239 }
240 tmp = OPENSSL_malloc(inlen); 240 tmp = malloc(inlen);
241 /* setup IV by decrypting last two blocks */ 241 /* setup IV by decrypting last two blocks */
242 EVP_DecryptUpdate(ctx, tmp + inlen - 2 * blocklen, &outl, 242 EVP_DecryptUpdate(ctx, tmp + inlen - 2 * blocklen, &outl,
243 in + inlen - 2 * blocklen, blocklen * 2); 243 in + inlen - 2 * blocklen, blocklen * 2);
@@ -270,7 +270,7 @@ static int kek_unwrap_key(unsigned char *out, size_t *outlen,
270 rv = 1; 270 rv = 1;
271 err: 271 err:
272 OPENSSL_cleanse(tmp, inlen); 272 OPENSSL_cleanse(tmp, inlen);
273 OPENSSL_free(tmp); 273 free(tmp);
274 return rv; 274 return rv;
275 275
276 } 276 }
@@ -405,7 +405,7 @@ int cms_RecipientInfo_pwri_crypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri,
405 if (!kek_wrap_key(NULL, &keylen, ec->key, ec->keylen, &kekctx)) 405 if (!kek_wrap_key(NULL, &keylen, ec->key, ec->keylen, &kekctx))
406 goto err; 406 goto err;
407 407
408 key = OPENSSL_malloc(keylen); 408 key = malloc(keylen);
409 409
410 if (!key) 410 if (!key)
411 goto err; 411 goto err;
@@ -417,7 +417,7 @@ int cms_RecipientInfo_pwri_crypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri,
417 } 417 }
418 else 418 else
419 { 419 {
420 key = OPENSSL_malloc(pwri->encryptedKey->length); 420 key = malloc(pwri->encryptedKey->length);
421 421
422 if (!key) 422 if (!key)
423 { 423 {
@@ -446,7 +446,7 @@ int cms_RecipientInfo_pwri_crypt(CMS_ContentInfo *cms, CMS_RecipientInfo *ri,
446 EVP_CIPHER_CTX_cleanup(&kekctx); 446 EVP_CIPHER_CTX_cleanup(&kekctx);
447 447
448 if (!r && key) 448 if (!r && key)
449 OPENSSL_free(key); 449 free(key);
450 X509_ALGOR_free(kekalg); 450 X509_ALGOR_free(kekalg);
451 451
452 return r; 452 return r;
diff --git a/src/lib/libcrypto/cms/cms_sd.c b/src/lib/libcrypto/cms/cms_sd.c
index 77fbd13596..d852af596d 100644
--- a/src/lib/libcrypto/cms/cms_sd.c
+++ b/src/lib/libcrypto/cms/cms_sd.c
@@ -658,7 +658,7 @@ static int cms_SignerInfo_content_sign(CMS_ContentInfo *cms,
658 { 658 {
659 unsigned char *sig; 659 unsigned char *sig;
660 unsigned int siglen; 660 unsigned int siglen;
661 sig = OPENSSL_malloc(EVP_PKEY_size(si->pkey)); 661 sig = malloc(EVP_PKEY_size(si->pkey));
662 if (!sig) 662 if (!sig)
663 { 663 {
664 CMSerr(CMS_F_CMS_SIGNERINFO_CONTENT_SIGN, 664 CMSerr(CMS_F_CMS_SIGNERINFO_CONTENT_SIGN,
@@ -669,7 +669,7 @@ static int cms_SignerInfo_content_sign(CMS_ContentInfo *cms,
669 { 669 {
670 CMSerr(CMS_F_CMS_SIGNERINFO_CONTENT_SIGN, 670 CMSerr(CMS_F_CMS_SIGNERINFO_CONTENT_SIGN,
671 CMS_R_SIGNFINAL_ERROR); 671 CMS_R_SIGNFINAL_ERROR);
672 OPENSSL_free(sig); 672 free(sig);
673 goto err; 673 goto err;
674 } 674 }
675 ASN1_STRING_set0(si->signature, sig, siglen); 675 ASN1_STRING_set0(si->signature, sig, siglen);
@@ -738,8 +738,8 @@ int CMS_SignerInfo_sign(CMS_SignerInfo *si)
738 goto err; 738 goto err;
739 if (EVP_DigestSignFinal(&mctx, NULL, &siglen) <= 0) 739 if (EVP_DigestSignFinal(&mctx, NULL, &siglen) <= 0)
740 goto err; 740 goto err;
741 OPENSSL_free(abuf); 741 free(abuf);
742 abuf = OPENSSL_malloc(siglen); 742 abuf = malloc(siglen);
743 if(!abuf) 743 if(!abuf)
744 goto err; 744 goto err;
745 if (EVP_DigestSignFinal(&mctx, abuf, &siglen) <= 0) 745 if (EVP_DigestSignFinal(&mctx, abuf, &siglen) <= 0)
@@ -760,7 +760,7 @@ int CMS_SignerInfo_sign(CMS_SignerInfo *si)
760 760
761 err: 761 err:
762 if (abuf) 762 if (abuf)
763 OPENSSL_free(abuf); 763 free(abuf);
764 EVP_MD_CTX_cleanup(&mctx); 764 EVP_MD_CTX_cleanup(&mctx);
765 return 0; 765 return 0;
766 766
@@ -792,7 +792,7 @@ int CMS_SignerInfo_verify(CMS_SignerInfo *si)
792 if(!abuf) 792 if(!abuf)
793 goto err; 793 goto err;
794 r = EVP_DigestVerifyUpdate(&mctx, abuf, alen); 794 r = EVP_DigestVerifyUpdate(&mctx, abuf, alen);
795 OPENSSL_free(abuf); 795 free(abuf);
796 if (r <= 0) 796 if (r <= 0)
797 { 797 {
798 r = -1; 798 r = -1;
@@ -917,7 +917,7 @@ int CMS_add_smimecap(CMS_SignerInfo *si, STACK_OF(X509_ALGOR) *algs)
917 return 0; 917 return 0;
918 r = CMS_signed_add1_attr_by_NID(si, NID_SMIMECapabilities, 918 r = CMS_signed_add1_attr_by_NID(si, NID_SMIMECapabilities,
919 V_ASN1_SEQUENCE, smder, smderlen); 919 V_ASN1_SEQUENCE, smder, smderlen);
920 OPENSSL_free(smder); 920 free(smder);
921 return r; 921 return r;
922 } 922 }
923 923
diff --git a/src/lib/libcrypto/comp/c_zlib.c b/src/lib/libcrypto/comp/c_zlib.c
index 8adf35f3fc..2ced7c10cc 100644
--- a/src/lib/libcrypto/comp/c_zlib.c
+++ b/src/lib/libcrypto/comp/c_zlib.c
@@ -37,7 +37,7 @@ static void* zlib_zalloc(void* opaque, unsigned int no, unsigned int size)
37{ 37{
38 void *p; 38 void *p;
39 39
40 p=OPENSSL_malloc(no*size); 40 p=malloc(no*size);
41 if (p) 41 if (p)
42 memset(p, 0, no*size); 42 memset(p, 0, no*size);
43 return p; 43 return p;
@@ -46,7 +46,7 @@ static void* zlib_zalloc(void* opaque, unsigned int no, unsigned int size)
46 46
47static void zlib_zfree(void* opaque, void* address) 47static void zlib_zfree(void* opaque, void* address)
48{ 48{
49 OPENSSL_free(address); 49 free(address);
50} 50}
51 51
52#if 0 52#if 0
@@ -140,7 +140,7 @@ static int zlib_stateful_init(COMP_CTX *ctx)
140 { 140 {
141 int err; 141 int err;
142 struct zlib_state *state = 142 struct zlib_state *state =
143 (struct zlib_state *)OPENSSL_malloc(sizeof(struct zlib_state)); 143 (struct zlib_state *)malloc(sizeof(struct zlib_state));
144 144
145 if (state == NULL) 145 if (state == NULL)
146 goto err; 146 goto err;
@@ -173,7 +173,7 @@ static int zlib_stateful_init(COMP_CTX *ctx)
173 CRYPTO_set_ex_data(&ctx->ex_data,zlib_stateful_ex_idx,state); 173 CRYPTO_set_ex_data(&ctx->ex_data,zlib_stateful_ex_idx,state);
174 return 1; 174 return 1;
175 err: 175 err:
176 if (state) OPENSSL_free(state); 176 if (state) free(state);
177 return 0; 177 return 0;
178 } 178 }
179 179
@@ -184,7 +184,7 @@ static void zlib_stateful_finish(COMP_CTX *ctx)
184 zlib_stateful_ex_idx); 184 zlib_stateful_ex_idx);
185 inflateEnd(&state->istream); 185 inflateEnd(&state->istream);
186 deflateEnd(&state->ostream); 186 deflateEnd(&state->ostream);
187 OPENSSL_free(state); 187 free(state);
188 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_COMP,ctx,&ctx->ex_data); 188 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_COMP,ctx,&ctx->ex_data);
189 } 189 }
190 190
@@ -479,7 +479,7 @@ static int bio_zlib_new(BIO *bi)
479 return 0; 479 return 0;
480 } 480 }
481#endif 481#endif
482 ctx = OPENSSL_malloc(sizeof(BIO_ZLIB_CTX)); 482 ctx = malloc(sizeof(BIO_ZLIB_CTX));
483 if(!ctx) 483 if(!ctx)
484 { 484 {
485 COMPerr(COMP_F_BIO_ZLIB_NEW, ERR_R_MALLOC_FAILURE); 485 COMPerr(COMP_F_BIO_ZLIB_NEW, ERR_R_MALLOC_FAILURE);
@@ -518,15 +518,15 @@ static int bio_zlib_free(BIO *bi)
518 { 518 {
519 /* Destroy decompress context */ 519 /* Destroy decompress context */
520 inflateEnd(&ctx->zin); 520 inflateEnd(&ctx->zin);
521 OPENSSL_free(ctx->ibuf); 521 free(ctx->ibuf);
522 } 522 }
523 if(ctx->obuf) 523 if(ctx->obuf)
524 { 524 {
525 /* Destroy compress context */ 525 /* Destroy compress context */
526 deflateEnd(&ctx->zout); 526 deflateEnd(&ctx->zout);
527 OPENSSL_free(ctx->obuf); 527 free(ctx->obuf);
528 } 528 }
529 OPENSSL_free(ctx); 529 free(ctx);
530 bi->ptr = NULL; 530 bi->ptr = NULL;
531 bi->init = 0; 531 bi->init = 0;
532 bi->flags = 0; 532 bi->flags = 0;
@@ -544,7 +544,7 @@ static int bio_zlib_read(BIO *b, char *out, int outl)
544 BIO_clear_retry_flags(b); 544 BIO_clear_retry_flags(b);
545 if(!ctx->ibuf) 545 if(!ctx->ibuf)
546 { 546 {
547 ctx->ibuf = OPENSSL_malloc(ctx->ibufsize); 547 ctx->ibuf = malloc(ctx->ibufsize);
548 if(!ctx->ibuf) 548 if(!ctx->ibuf)
549 { 549 {
550 COMPerr(COMP_F_BIO_ZLIB_READ, ERR_R_MALLOC_FAILURE); 550 COMPerr(COMP_F_BIO_ZLIB_READ, ERR_R_MALLOC_FAILURE);
@@ -606,7 +606,7 @@ static int bio_zlib_write(BIO *b, const char *in, int inl)
606 BIO_clear_retry_flags(b); 606 BIO_clear_retry_flags(b);
607 if(!ctx->obuf) 607 if(!ctx->obuf)
608 { 608 {
609 ctx->obuf = OPENSSL_malloc(ctx->obufsize); 609 ctx->obuf = malloc(ctx->obufsize);
610 /* Need error here */ 610 /* Need error here */
611 if(!ctx->obuf) 611 if(!ctx->obuf)
612 { 612 {
@@ -754,7 +754,7 @@ static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr)
754 { 754 {
755 if (ctx->ibuf) 755 if (ctx->ibuf)
756 { 756 {
757 OPENSSL_free(ctx->ibuf); 757 free(ctx->ibuf);
758 ctx->ibuf = NULL; 758 ctx->ibuf = NULL;
759 } 759 }
760 ctx->ibufsize = ibs; 760 ctx->ibufsize = ibs;
@@ -764,7 +764,7 @@ static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr)
764 { 764 {
765 if (ctx->obuf) 765 if (ctx->obuf)
766 { 766 {
767 OPENSSL_free(ctx->obuf); 767 free(ctx->obuf);
768 ctx->obuf = NULL; 768 ctx->obuf = NULL;
769 } 769 }
770 ctx->obufsize = obs; 770 ctx->obufsize = obs;
diff --git a/src/lib/libcrypto/comp/comp_lib.c b/src/lib/libcrypto/comp/comp_lib.c
index b60ae371e8..feb07ea881 100644
--- a/src/lib/libcrypto/comp/comp_lib.c
+++ b/src/lib/libcrypto/comp/comp_lib.c
@@ -8,7 +8,7 @@ COMP_CTX *COMP_CTX_new(COMP_METHOD *meth)
8 { 8 {
9 COMP_CTX *ret; 9 COMP_CTX *ret;
10 10
11 if ((ret=(COMP_CTX *)OPENSSL_malloc(sizeof(COMP_CTX))) == NULL) 11 if ((ret=(COMP_CTX *)malloc(sizeof(COMP_CTX))) == NULL)
12 { 12 {
13 /* ZZZZZZZZZZZZZZZZ */ 13 /* ZZZZZZZZZZZZZZZZ */
14 return(NULL); 14 return(NULL);
@@ -17,7 +17,7 @@ COMP_CTX *COMP_CTX_new(COMP_METHOD *meth)
17 ret->meth=meth; 17 ret->meth=meth;
18 if ((ret->meth->init != NULL) && !ret->meth->init(ret)) 18 if ((ret->meth->init != NULL) && !ret->meth->init(ret))
19 { 19 {
20 OPENSSL_free(ret); 20 free(ret);
21 ret=NULL; 21 ret=NULL;
22 } 22 }
23 return(ret); 23 return(ret);
@@ -31,7 +31,7 @@ void COMP_CTX_free(COMP_CTX *ctx)
31 if (ctx->meth->finish != NULL) 31 if (ctx->meth->finish != NULL)
32 ctx->meth->finish(ctx); 32 ctx->meth->finish(ctx);
33 33
34 OPENSSL_free(ctx); 34 free(ctx);
35 } 35 }
36 36
37int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen, 37int COMP_compress_block(COMP_CTX *ctx, unsigned char *out, int olen,
diff --git a/src/lib/libcrypto/conf/conf_api.c b/src/lib/libcrypto/conf/conf_api.c
index f5fcbb9f6b..dc6eb579bf 100644
--- a/src/lib/libcrypto/conf/conf_api.c
+++ b/src/lib/libcrypto/conf/conf_api.c
@@ -119,9 +119,9 @@ int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value)
119 if (v != NULL) 119 if (v != NULL)
120 { 120 {
121 (void)sk_CONF_VALUE_delete_ptr(ts,v); 121 (void)sk_CONF_VALUE_delete_ptr(ts,v);
122 OPENSSL_free(v->name); 122 free(v->name);
123 OPENSSL_free(v->value); 123 free(v->value);
124 OPENSSL_free(v); 124 free(v);
125 } 125 }
126 return 1; 126 return 1;
127 } 127 }
@@ -226,7 +226,7 @@ void _CONF_free_data(CONF *conf)
226 if (conf == NULL || conf->data == NULL) return; 226 if (conf == NULL || conf->data == NULL) return;
227 227
228 lh_CONF_VALUE_down_load(conf->data)=0; /* evil thing to make 228 lh_CONF_VALUE_down_load(conf->data)=0; /* evil thing to make
229 * sure the 'OPENSSL_free()' works as 229 * sure the 'free()' works as
230 * expected */ 230 * expected */
231 lh_CONF_VALUE_doall_arg(conf->data, 231 lh_CONF_VALUE_doall_arg(conf->data,
232 LHASH_DOALL_ARG_FN(value_free_hash), 232 LHASH_DOALL_ARG_FN(value_free_hash),
@@ -257,13 +257,13 @@ static void value_free_stack_doall(CONF_VALUE *a)
257 for (i=sk_CONF_VALUE_num(sk)-1; i>=0; i--) 257 for (i=sk_CONF_VALUE_num(sk)-1; i>=0; i--)
258 { 258 {
259 vv=sk_CONF_VALUE_value(sk,i); 259 vv=sk_CONF_VALUE_value(sk,i);
260 OPENSSL_free(vv->value); 260 free(vv->value);
261 OPENSSL_free(vv->name); 261 free(vv->name);
262 OPENSSL_free(vv); 262 free(vv);
263 } 263 }
264 if (sk != NULL) sk_CONF_VALUE_free(sk); 264 if (sk != NULL) sk_CONF_VALUE_free(sk);
265 OPENSSL_free(a->section); 265 free(a->section);
266 OPENSSL_free(a); 266 free(a);
267 } 267 }
268 268
269/* Up until OpenSSL 0.9.5a, this was new_section */ 269/* Up until OpenSSL 0.9.5a, this was new_section */
@@ -275,10 +275,10 @@ CONF_VALUE *_CONF_new_section(CONF *conf, const char *section)
275 275
276 if ((sk=sk_CONF_VALUE_new_null()) == NULL) 276 if ((sk=sk_CONF_VALUE_new_null()) == NULL)
277 goto err; 277 goto err;
278 if ((v=OPENSSL_malloc(sizeof(CONF_VALUE))) == NULL) 278 if ((v=malloc(sizeof(CONF_VALUE))) == NULL)
279 goto err; 279 goto err;
280 i=strlen(section)+1; 280 i=strlen(section)+1;
281 if ((v->section=OPENSSL_malloc(i)) == NULL) 281 if ((v->section=malloc(i)) == NULL)
282 goto err; 282 goto err;
283 283
284 memcpy(v->section,section,i); 284 memcpy(v->section,section,i);
@@ -292,7 +292,7 @@ err:
292 if (!ok) 292 if (!ok)
293 { 293 {
294 if (sk != NULL) sk_CONF_VALUE_free(sk); 294 if (sk != NULL) sk_CONF_VALUE_free(sk);
295 if (v != NULL) OPENSSL_free(v); 295 if (v != NULL) free(v);
296 v=NULL; 296 v=NULL;
297 } 297 }
298 return(v); 298 return(v);
diff --git a/src/lib/libcrypto/conf/conf_def.c b/src/lib/libcrypto/conf/conf_def.c
index 15e5613e36..32d47458a0 100644
--- a/src/lib/libcrypto/conf/conf_def.c
+++ b/src/lib/libcrypto/conf/conf_def.c
@@ -129,11 +129,11 @@ static CONF *def_create(CONF_METHOD *meth)
129 { 129 {
130 CONF *ret; 130 CONF *ret;
131 131
132 ret = OPENSSL_malloc(sizeof(CONF) + sizeof(unsigned short *)); 132 ret = malloc(sizeof(CONF) + sizeof(unsigned short *));
133 if (ret) 133 if (ret)
134 if (meth->init(ret) == 0) 134 if (meth->init(ret) == 0)
135 { 135 {
136 OPENSSL_free(ret); 136 free(ret);
137 ret = NULL; 137 ret = NULL;
138 } 138 }
139 return ret; 139 return ret;
@@ -167,7 +167,7 @@ static int def_destroy(CONF *conf)
167 { 167 {
168 if (def_destroy_data(conf)) 168 if (def_destroy_data(conf))
169 { 169 {
170 OPENSSL_free(conf); 170 free(conf);
171 return 1; 171 return 1;
172 } 172 }
173 return 0; 173 return 0;
@@ -228,7 +228,7 @@ static int def_load_bio(CONF *conf, BIO *in, long *line)
228 goto err; 228 goto err;
229 } 229 }
230 230
231 section=(char *)OPENSSL_malloc(10); 231 section=(char *)malloc(10);
232 if (section == NULL) 232 if (section == NULL)
233 { 233 {
234 CONFerr(CONF_F_DEF_LOAD_BIO,ERR_R_MALLOC_FAILURE); 234 CONFerr(CONF_F_DEF_LOAD_BIO,ERR_R_MALLOC_FAILURE);
@@ -373,14 +373,14 @@ again:
373 p++; 373 p++;
374 *p='\0'; 374 *p='\0';
375 375
376 if (!(v=(CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE)))) 376 if (!(v=(CONF_VALUE *)malloc(sizeof(CONF_VALUE))))
377 { 377 {
378 CONFerr(CONF_F_DEF_LOAD_BIO, 378 CONFerr(CONF_F_DEF_LOAD_BIO,
379 ERR_R_MALLOC_FAILURE); 379 ERR_R_MALLOC_FAILURE);
380 goto err; 380 goto err;
381 } 381 }
382 if (psection == NULL) psection=section; 382 if (psection == NULL) psection=section;
383 v->name=(char *)OPENSSL_malloc(strlen(pname)+1); 383 v->name=(char *)malloc(strlen(pname)+1);
384 v->value=NULL; 384 v->value=NULL;
385 if (v->name == NULL) 385 if (v->name == NULL)
386 { 386 {
@@ -424,20 +424,20 @@ again:
424 if (vv != NULL) 424 if (vv != NULL)
425 { 425 {
426 sk_CONF_VALUE_delete_ptr(ts,vv); 426 sk_CONF_VALUE_delete_ptr(ts,vv);
427 OPENSSL_free(vv->name); 427 free(vv->name);
428 OPENSSL_free(vv->value); 428 free(vv->value);
429 OPENSSL_free(vv); 429 free(vv);
430 } 430 }
431#endif 431#endif
432 v=NULL; 432 v=NULL;
433 } 433 }
434 } 434 }
435 if (buff != NULL) BUF_MEM_free(buff); 435 if (buff != NULL) BUF_MEM_free(buff);
436 if (section != NULL) OPENSSL_free(section); 436 if (section != NULL) free(section);
437 return(1); 437 return(1);
438err: 438err:
439 if (buff != NULL) BUF_MEM_free(buff); 439 if (buff != NULL) BUF_MEM_free(buff);
440 if (section != NULL) OPENSSL_free(section); 440 if (section != NULL) free(section);
441 if (line != NULL) *line=eline; 441 if (line != NULL) *line=eline;
442 (void) snprintf(btmp,sizeof btmp,"%ld",eline); 442 (void) snprintf(btmp,sizeof btmp,"%ld",eline);
443 ERR_add_error_data(2,"line ",btmp); 443 ERR_add_error_data(2,"line ",btmp);
@@ -448,9 +448,9 @@ err:
448 } 448 }
449 if (v != NULL) 449 if (v != NULL)
450 { 450 {
451 if (v->name != NULL) OPENSSL_free(v->name); 451 if (v->name != NULL) free(v->name);
452 if (v->value != NULL) OPENSSL_free(v->value); 452 if (v->value != NULL) free(v->value);
453 if (v != NULL) OPENSSL_free(v); 453 if (v != NULL) free(v);
454 } 454 }
455 return(0); 455 return(0);
456 } 456 }
@@ -637,9 +637,9 @@ static int str_copy(CONF *conf, char *section, char **pto, char *from)
637 buf->data[to++]= *(from++); 637 buf->data[to++]= *(from++);
638 } 638 }
639 buf->data[to]='\0'; 639 buf->data[to]='\0';
640 if (*pto != NULL) OPENSSL_free(*pto); 640 if (*pto != NULL) free(*pto);
641 *pto=buf->data; 641 *pto=buf->data;
642 OPENSSL_free(buf); 642 free(buf);
643 return(1); 643 return(1);
644err: 644err:
645 if (buf != NULL) BUF_MEM_free(buf); 645 if (buf != NULL) BUF_MEM_free(buf);
diff --git a/src/lib/libcrypto/conf/conf_mod.c b/src/lib/libcrypto/conf/conf_mod.c
index 994294f655..652ad6469a 100644
--- a/src/lib/libcrypto/conf/conf_mod.c
+++ b/src/lib/libcrypto/conf/conf_mod.c
@@ -197,7 +197,7 @@ int CONF_modules_load_file(const char *filename, const char *appname,
197 197
198 err: 198 err:
199 if (filename == NULL) 199 if (filename == NULL)
200 OPENSSL_free(file); 200 free(file);
201 NCONF_free(conf); 201 NCONF_free(conf);
202 202
203 return ret; 203 return ret;
@@ -296,7 +296,7 @@ static CONF_MODULE *module_add(DSO *dso, const char *name,
296 supported_modules = sk_CONF_MODULE_new_null(); 296 supported_modules = sk_CONF_MODULE_new_null();
297 if (supported_modules == NULL) 297 if (supported_modules == NULL)
298 return NULL; 298 return NULL;
299 tmod = OPENSSL_malloc(sizeof(CONF_MODULE)); 299 tmod = malloc(sizeof(CONF_MODULE));
300 if (tmod == NULL) 300 if (tmod == NULL)
301 return NULL; 301 return NULL;
302 302
@@ -308,7 +308,7 @@ static CONF_MODULE *module_add(DSO *dso, const char *name,
308 308
309 if (!sk_CONF_MODULE_push(supported_modules, tmod)) 309 if (!sk_CONF_MODULE_push(supported_modules, tmod))
310 { 310 {
311 OPENSSL_free(tmod); 311 free(tmod);
312 return NULL; 312 return NULL;
313 } 313 }
314 314
@@ -352,7 +352,7 @@ static int module_init(CONF_MODULE *pmod, char *name, char *value,
352 CONF_IMODULE *imod = NULL; 352 CONF_IMODULE *imod = NULL;
353 353
354 /* Otherwise add initialized module to list */ 354 /* Otherwise add initialized module to list */
355 imod = OPENSSL_malloc(sizeof(CONF_IMODULE)); 355 imod = malloc(sizeof(CONF_IMODULE));
356 if (!imod) 356 if (!imod)
357 goto err; 357 goto err;
358 358
@@ -404,10 +404,10 @@ static int module_init(CONF_MODULE *pmod, char *name, char *value,
404 if (imod) 404 if (imod)
405 { 405 {
406 if (imod->name) 406 if (imod->name)
407 OPENSSL_free(imod->name); 407 free(imod->name);
408 if (imod->value) 408 if (imod->value)
409 OPENSSL_free(imod->value); 409 free(imod->value);
410 OPENSSL_free(imod); 410 free(imod);
411 } 411 }
412 412
413 return -1; 413 return -1;
@@ -447,8 +447,8 @@ static void module_free(CONF_MODULE *md)
447 { 447 {
448 if (md->dso) 448 if (md->dso)
449 DSO_free(md->dso); 449 DSO_free(md->dso);
450 OPENSSL_free(md->name); 450 free(md->name);
451 OPENSSL_free(md); 451 free(md);
452 } 452 }
453 453
454/* finish and free up all modules instances */ 454/* finish and free up all modules instances */
@@ -472,9 +472,9 @@ static void module_finish(CONF_IMODULE *imod)
472 if (imod->pmod->finish) 472 if (imod->pmod->finish)
473 imod->pmod->finish(imod); 473 imod->pmod->finish(imod);
474 imod->pmod->links--; 474 imod->pmod->links--;
475 OPENSSL_free(imod->name); 475 free(imod->name);
476 OPENSSL_free(imod->value); 476 free(imod->value);
477 OPENSSL_free(imod); 477 free(imod);
478 } 478 }
479 479
480/* Add a static module to OpenSSL */ 480/* Add a static module to OpenSSL */
@@ -558,7 +558,7 @@ char *CONF_get1_default_config_file(void)
558#endif 558#endif
559 len += strlen(OPENSSL_CONF); 559 len += strlen(OPENSSL_CONF);
560 560
561 file = OPENSSL_malloc(len + 1); 561 file = malloc(len + 1);
562 562
563 if (!file) 563 if (!file)
564 return NULL; 564 return NULL;
diff --git a/src/lib/libcrypto/cryptlib.c b/src/lib/libcrypto/cryptlib.c
index 2bf5def17d..dc3cc2ab02 100644
--- a/src/lib/libcrypto/cryptlib.c
+++ b/src/lib/libcrypto/cryptlib.c
@@ -211,7 +211,7 @@ CRYPTO_get_new_lockid(char *name)
211 } 211 }
212 i = sk_OPENSSL_STRING_push(app_locks, str); 212 i = sk_OPENSSL_STRING_push(app_locks, str);
213 if (!i) 213 if (!i)
214 OPENSSL_free(str); 214 free(str);
215 else 215 else
216 i += CRYPTO_NUM_LOCKS; /* gap of one :-) */ 216 i += CRYPTO_NUM_LOCKS; /* gap of one :-) */
217 return (i); 217 return (i);
@@ -242,7 +242,7 @@ CRYPTO_get_new_dynlockid(void)
242 } 242 }
243 CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK); 243 CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
244 244
245 pointer = (CRYPTO_dynlock *)OPENSSL_malloc(sizeof(CRYPTO_dynlock)); 245 pointer = (CRYPTO_dynlock *)malloc(sizeof(CRYPTO_dynlock));
246 if (pointer == NULL) { 246 if (pointer == NULL) {
247 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID, ERR_R_MALLOC_FAILURE); 247 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID, ERR_R_MALLOC_FAILURE);
248 return (0); 248 return (0);
@@ -250,7 +250,7 @@ CRYPTO_get_new_dynlockid(void)
250 pointer->references = 1; 250 pointer->references = 1;
251 pointer->data = dynlock_create_callback(__FILE__, __LINE__); 251 pointer->data = dynlock_create_callback(__FILE__, __LINE__);
252 if (pointer->data == NULL) { 252 if (pointer->data == NULL) {
253 OPENSSL_free(pointer); 253 free(pointer);
254 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID, ERR_R_MALLOC_FAILURE); 254 CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_DYNLOCKID, ERR_R_MALLOC_FAILURE);
255 return (0); 255 return (0);
256 } 256 }
@@ -273,7 +273,7 @@ CRYPTO_get_new_dynlockid(void)
273 273
274 if (i == -1) { 274 if (i == -1) {
275 dynlock_destroy_callback(pointer->data, __FILE__, __LINE__); 275 dynlock_destroy_callback(pointer->data, __FILE__, __LINE__);
276 OPENSSL_free(pointer); 276 free(pointer);
277 } else 277 } else
278 i += 1; /* to avoid 0 */ 278 i += 1; /* to avoid 0 */
279 return - i; 279 return - i;
@@ -312,7 +312,7 @@ CRYPTO_destroy_dynlockid(int i)
312 312
313 if (pointer) { 313 if (pointer) {
314 dynlock_destroy_callback(pointer->data, __FILE__, __LINE__); 314 dynlock_destroy_callback(pointer->data, __FILE__, __LINE__);
315 OPENSSL_free(pointer); 315 free(pointer);
316 } 316 }
317} 317}
318 318
diff --git a/src/lib/libcrypto/des/enc_read.c b/src/lib/libcrypto/des/enc_read.c
index edb6620d08..23ad458dcf 100644
--- a/src/lib/libcrypto/des/enc_read.c
+++ b/src/lib/libcrypto/des/enc_read.c
@@ -106,17 +106,17 @@ int DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched,
106 106
107 if (tmpbuf == NULL) 107 if (tmpbuf == NULL)
108 { 108 {
109 tmpbuf=OPENSSL_malloc(BSIZE); 109 tmpbuf=malloc(BSIZE);
110 if (tmpbuf == NULL) return(-1); 110 if (tmpbuf == NULL) return(-1);
111 } 111 }
112 if (net == NULL) 112 if (net == NULL)
113 { 113 {
114 net=OPENSSL_malloc(BSIZE); 114 net=malloc(BSIZE);
115 if (net == NULL) return(-1); 115 if (net == NULL) return(-1);
116 } 116 }
117 if (unnet == NULL) 117 if (unnet == NULL)
118 { 118 {
119 unnet=OPENSSL_malloc(BSIZE); 119 unnet=malloc(BSIZE);
120 if (unnet == NULL) return(-1); 120 if (unnet == NULL) return(-1);
121 } 121 }
122 /* left over data from last decrypt */ 122 /* left over data from last decrypt */
diff --git a/src/lib/libcrypto/des/enc_writ.c b/src/lib/libcrypto/des/enc_writ.c
index 2353ac1e89..8f6b033c87 100644
--- a/src/lib/libcrypto/des/enc_writ.c
+++ b/src/lib/libcrypto/des/enc_writ.c
@@ -98,7 +98,7 @@ int DES_enc_write(int fd, const void *_buf, int len,
98 98
99 if (outbuf == NULL) 99 if (outbuf == NULL)
100 { 100 {
101 outbuf=OPENSSL_malloc(BSIZE+HDRSIZE); 101 outbuf=malloc(BSIZE+HDRSIZE);
102 if (outbuf == NULL) return(-1); 102 if (outbuf == NULL) return(-1);
103 } 103 }
104 /* If we are sending less than 8 bytes, the same char will look 104 /* If we are sending less than 8 bytes, the same char will look
diff --git a/src/lib/libcrypto/dh/dh_ameth.c b/src/lib/libcrypto/dh/dh_ameth.c
index 02ec2d47b4..d39f4b373d 100644
--- a/src/lib/libcrypto/dh/dh_ameth.c
+++ b/src/lib/libcrypto/dh/dh_ameth.c
@@ -168,7 +168,7 @@ static int dh_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
168 168
169 err: 169 err:
170 if (penc) 170 if (penc)
171 OPENSSL_free(penc); 171 free(penc);
172 if (pval) 172 if (pval)
173 ASN1_STRING_free(pval); 173 ASN1_STRING_free(pval);
174 174
@@ -277,7 +277,7 @@ static int dh_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
277 277
278err: 278err:
279 if (dp != NULL) 279 if (dp != NULL)
280 OPENSSL_free(dp); 280 free(dp);
281 if (params != NULL) 281 if (params != NULL)
282 ASN1_STRING_free(params); 282 ASN1_STRING_free(params);
283 if (prkey != NULL) 283 if (prkey != NULL)
@@ -353,7 +353,7 @@ static int do_dh_print(BIO *bp, const DH *x, int indent,
353 else 353 else
354 ktype = "PKCS#3 DH Parameters"; 354 ktype = "PKCS#3 DH Parameters";
355 355
356 m= OPENSSL_malloc(buf_len+10); 356 m= malloc(buf_len+10);
357 if (m == NULL) 357 if (m == NULL)
358 { 358 {
359 reason=ERR_R_MALLOC_FAILURE; 359 reason=ERR_R_MALLOC_FAILURE;
@@ -384,7 +384,7 @@ static int do_dh_print(BIO *bp, const DH *x, int indent,
384err: 384err:
385 DHerr(DH_F_DO_DH_PRINT,reason); 385 DHerr(DH_F_DO_DH_PRINT,reason);
386 } 386 }
387 if (m != NULL) OPENSSL_free(m); 387 if (m != NULL) free(m);
388 return(ret); 388 return(ret);
389 } 389 }
390 390
diff --git a/src/lib/libcrypto/dh/dh_lib.c b/src/lib/libcrypto/dh/dh_lib.c
index a40caaf75b..4e3d25b7e5 100644
--- a/src/lib/libcrypto/dh/dh_lib.c
+++ b/src/lib/libcrypto/dh/dh_lib.c
@@ -110,7 +110,7 @@ DH *DH_new_method(ENGINE *engine)
110 { 110 {
111 DH *ret; 111 DH *ret;
112 112
113 ret=(DH *)OPENSSL_malloc(sizeof(DH)); 113 ret=(DH *)malloc(sizeof(DH));
114 if (ret == NULL) 114 if (ret == NULL)
115 { 115 {
116 DHerr(DH_F_DH_NEW_METHOD,ERR_R_MALLOC_FAILURE); 116 DHerr(DH_F_DH_NEW_METHOD,ERR_R_MALLOC_FAILURE);
@@ -124,7 +124,7 @@ DH *DH_new_method(ENGINE *engine)
124 if (!ENGINE_init(engine)) 124 if (!ENGINE_init(engine))
125 { 125 {
126 DHerr(DH_F_DH_NEW_METHOD, ERR_R_ENGINE_LIB); 126 DHerr(DH_F_DH_NEW_METHOD, ERR_R_ENGINE_LIB);
127 OPENSSL_free(ret); 127 free(ret);
128 return NULL; 128 return NULL;
129 } 129 }
130 ret->engine = engine; 130 ret->engine = engine;
@@ -138,7 +138,7 @@ DH *DH_new_method(ENGINE *engine)
138 { 138 {
139 DHerr(DH_F_DH_NEW_METHOD,ERR_R_ENGINE_LIB); 139 DHerr(DH_F_DH_NEW_METHOD,ERR_R_ENGINE_LIB);
140 ENGINE_finish(ret->engine); 140 ENGINE_finish(ret->engine);
141 OPENSSL_free(ret); 141 free(ret);
142 return NULL; 142 return NULL;
143 } 143 }
144 } 144 }
@@ -167,7 +167,7 @@ DH *DH_new_method(ENGINE *engine)
167 ENGINE_finish(ret->engine); 167 ENGINE_finish(ret->engine);
168#endif 168#endif
169 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data); 169 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data);
170 OPENSSL_free(ret); 170 free(ret);
171 ret=NULL; 171 ret=NULL;
172 } 172 }
173 return(ret); 173 return(ret);
@@ -203,11 +203,11 @@ void DH_free(DH *r)
203 if (r->g != NULL) BN_clear_free(r->g); 203 if (r->g != NULL) BN_clear_free(r->g);
204 if (r->q != NULL) BN_clear_free(r->q); 204 if (r->q != NULL) BN_clear_free(r->q);
205 if (r->j != NULL) BN_clear_free(r->j); 205 if (r->j != NULL) BN_clear_free(r->j);
206 if (r->seed) OPENSSL_free(r->seed); 206 if (r->seed) free(r->seed);
207 if (r->counter != NULL) BN_clear_free(r->counter); 207 if (r->counter != NULL) BN_clear_free(r->counter);
208 if (r->pub_key != NULL) BN_clear_free(r->pub_key); 208 if (r->pub_key != NULL) BN_clear_free(r->pub_key);
209 if (r->priv_key != NULL) BN_clear_free(r->priv_key); 209 if (r->priv_key != NULL) BN_clear_free(r->priv_key);
210 OPENSSL_free(r); 210 free(r);
211 } 211 }
212 212
213int DH_up_ref(DH *r) 213int DH_up_ref(DH *r)
diff --git a/src/lib/libcrypto/dh/dh_pmeth.c b/src/lib/libcrypto/dh/dh_pmeth.c
index 5ae72b7d4c..ec4553c0a8 100644
--- a/src/lib/libcrypto/dh/dh_pmeth.c
+++ b/src/lib/libcrypto/dh/dh_pmeth.c
@@ -80,7 +80,7 @@ typedef struct
80static int pkey_dh_init(EVP_PKEY_CTX *ctx) 80static int pkey_dh_init(EVP_PKEY_CTX *ctx)
81 { 81 {
82 DH_PKEY_CTX *dctx; 82 DH_PKEY_CTX *dctx;
83 dctx = OPENSSL_malloc(sizeof(DH_PKEY_CTX)); 83 dctx = malloc(sizeof(DH_PKEY_CTX));
84 if (!dctx) 84 if (!dctx)
85 return 0; 85 return 0;
86 dctx->prime_len = 1024; 86 dctx->prime_len = 1024;
@@ -111,7 +111,7 @@ static void pkey_dh_cleanup(EVP_PKEY_CTX *ctx)
111 { 111 {
112 DH_PKEY_CTX *dctx = ctx->data; 112 DH_PKEY_CTX *dctx = ctx->data;
113 if (dctx) 113 if (dctx)
114 OPENSSL_free(dctx); 114 free(dctx);
115 } 115 }
116 116
117static int pkey_dh_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) 117static int pkey_dh_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
diff --git a/src/lib/libcrypto/dsa/dsa_ameth.c b/src/lib/libcrypto/dsa/dsa_ameth.c
index 376156ec5e..e9c549802d 100644
--- a/src/lib/libcrypto/dsa/dsa_ameth.c
+++ b/src/lib/libcrypto/dsa/dsa_ameth.c
@@ -176,7 +176,7 @@ static int dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
176 176
177 err: 177 err:
178 if (penc) 178 if (penc)
179 OPENSSL_free(penc); 179 free(penc);
180 if (pval) 180 if (pval)
181 ASN1_STRING_free(pval); 181 ASN1_STRING_free(pval);
182 182
@@ -344,7 +344,7 @@ static int dsa_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
344 344
345err: 345err:
346 if (dp != NULL) 346 if (dp != NULL)
347 OPENSSL_free(dp); 347 free(dp);
348 if (params != NULL) 348 if (params != NULL)
349 ASN1_STRING_free(params); 349 ASN1_STRING_free(params);
350 if (prkey != NULL) 350 if (prkey != NULL)
@@ -459,7 +459,7 @@ static int do_dsa_print(BIO *bp, const DSA *x, int off, int ptype)
459 update_buflen(priv_key, &buf_len); 459 update_buflen(priv_key, &buf_len);
460 update_buflen(pub_key, &buf_len); 460 update_buflen(pub_key, &buf_len);
461 461
462 m=(unsigned char *)OPENSSL_malloc(buf_len+10); 462 m=(unsigned char *)malloc(buf_len+10);
463 if (m == NULL) 463 if (m == NULL)
464 { 464 {
465 DSAerr(DSA_F_DO_DSA_PRINT,ERR_R_MALLOC_FAILURE); 465 DSAerr(DSA_F_DO_DSA_PRINT,ERR_R_MALLOC_FAILURE);
@@ -483,7 +483,7 @@ static int do_dsa_print(BIO *bp, const DSA *x, int off, int ptype)
483 if (!ASN1_bn_print(bp,"G: ",x->g,m,off)) goto err; 483 if (!ASN1_bn_print(bp,"G: ",x->g,m,off)) goto err;
484 ret=1; 484 ret=1;
485err: 485err:
486 if (m != NULL) OPENSSL_free(m); 486 if (m != NULL) free(m);
487 return(ret); 487 return(ret);
488 } 488 }
489 489
@@ -564,7 +564,7 @@ static int dsa_sig_print(BIO *bp, const X509_ALGOR *sigalg,
564 unsigned char *m=NULL; 564 unsigned char *m=NULL;
565 update_buflen(dsa_sig->r, &buf_len); 565 update_buflen(dsa_sig->r, &buf_len);
566 update_buflen(dsa_sig->s, &buf_len); 566 update_buflen(dsa_sig->s, &buf_len);
567 m = OPENSSL_malloc(buf_len+10); 567 m = malloc(buf_len+10);
568 if (m == NULL) 568 if (m == NULL)
569 { 569 {
570 DSAerr(DSA_F_DSA_SIG_PRINT,ERR_R_MALLOC_FAILURE); 570 DSAerr(DSA_F_DSA_SIG_PRINT,ERR_R_MALLOC_FAILURE);
@@ -581,7 +581,7 @@ static int dsa_sig_print(BIO *bp, const X509_ALGOR *sigalg,
581 rv = 1; 581 rv = 1;
582 err: 582 err:
583 if (m) 583 if (m)
584 OPENSSL_free(m); 584 free(m);
585 DSA_SIG_free(dsa_sig); 585 DSA_SIG_free(dsa_sig);
586 return rv; 586 return rv;
587 } 587 }
diff --git a/src/lib/libcrypto/dsa/dsa_asn1.c b/src/lib/libcrypto/dsa/dsa_asn1.c
index 19528dcd7a..f8a918d72c 100644
--- a/src/lib/libcrypto/dsa/dsa_asn1.c
+++ b/src/lib/libcrypto/dsa/dsa_asn1.c
@@ -69,7 +69,7 @@ static int sig_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
69{ 69{
70 if(operation == ASN1_OP_NEW_PRE) { 70 if(operation == ASN1_OP_NEW_PRE) {
71 DSA_SIG *sig; 71 DSA_SIG *sig;
72 sig = OPENSSL_malloc(sizeof(DSA_SIG)); 72 sig = malloc(sizeof(DSA_SIG));
73 if (!sig) 73 if (!sig)
74 { 74 {
75 DSAerr(DSA_F_SIG_CB, ERR_R_MALLOC_FAILURE); 75 DSAerr(DSA_F_SIG_CB, ERR_R_MALLOC_FAILURE);
diff --git a/src/lib/libcrypto/dsa/dsa_lib.c b/src/lib/libcrypto/dsa/dsa_lib.c
index 897c085968..27a4c66618 100644
--- a/src/lib/libcrypto/dsa/dsa_lib.c
+++ b/src/lib/libcrypto/dsa/dsa_lib.c
@@ -116,7 +116,7 @@ DSA *DSA_new_method(ENGINE *engine)
116 { 116 {
117 DSA *ret; 117 DSA *ret;
118 118
119 ret=(DSA *)OPENSSL_malloc(sizeof(DSA)); 119 ret=(DSA *)malloc(sizeof(DSA));
120 if (ret == NULL) 120 if (ret == NULL)
121 { 121 {
122 DSAerr(DSA_F_DSA_NEW_METHOD,ERR_R_MALLOC_FAILURE); 122 DSAerr(DSA_F_DSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);
@@ -129,7 +129,7 @@ DSA *DSA_new_method(ENGINE *engine)
129 if (!ENGINE_init(engine)) 129 if (!ENGINE_init(engine))
130 { 130 {
131 DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_ENGINE_LIB); 131 DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_ENGINE_LIB);
132 OPENSSL_free(ret); 132 free(ret);
133 return NULL; 133 return NULL;
134 } 134 }
135 ret->engine = engine; 135 ret->engine = engine;
@@ -144,7 +144,7 @@ DSA *DSA_new_method(ENGINE *engine)
144 DSAerr(DSA_F_DSA_NEW_METHOD, 144 DSAerr(DSA_F_DSA_NEW_METHOD,
145 ERR_R_ENGINE_LIB); 145 ERR_R_ENGINE_LIB);
146 ENGINE_finish(ret->engine); 146 ENGINE_finish(ret->engine);
147 OPENSSL_free(ret); 147 free(ret);
148 return NULL; 148 return NULL;
149 } 149 }
150 } 150 }
@@ -174,7 +174,7 @@ DSA *DSA_new_method(ENGINE *engine)
174 ENGINE_finish(ret->engine); 174 ENGINE_finish(ret->engine);
175#endif 175#endif
176 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data); 176 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data);
177 OPENSSL_free(ret); 177 free(ret);
178 ret=NULL; 178 ret=NULL;
179 } 179 }
180 180
@@ -216,7 +216,7 @@ void DSA_free(DSA *r)
216 if (r->priv_key != NULL) BN_clear_free(r->priv_key); 216 if (r->priv_key != NULL) BN_clear_free(r->priv_key);
217 if (r->kinv != NULL) BN_clear_free(r->kinv); 217 if (r->kinv != NULL) BN_clear_free(r->kinv);
218 if (r->r != NULL) BN_clear_free(r->r); 218 if (r->r != NULL) BN_clear_free(r->r);
219 OPENSSL_free(r); 219 free(r);
220 } 220 }
221 221
222int DSA_up_ref(DSA *r) 222int DSA_up_ref(DSA *r)
diff --git a/src/lib/libcrypto/dsa/dsa_pmeth.c b/src/lib/libcrypto/dsa/dsa_pmeth.c
index 715d8d675b..7076bf7b67 100644
--- a/src/lib/libcrypto/dsa/dsa_pmeth.c
+++ b/src/lib/libcrypto/dsa/dsa_pmeth.c
@@ -81,7 +81,7 @@ typedef struct
81static int pkey_dsa_init(EVP_PKEY_CTX *ctx) 81static int pkey_dsa_init(EVP_PKEY_CTX *ctx)
82 { 82 {
83 DSA_PKEY_CTX *dctx; 83 DSA_PKEY_CTX *dctx;
84 dctx = OPENSSL_malloc(sizeof(DSA_PKEY_CTX)); 84 dctx = malloc(sizeof(DSA_PKEY_CTX));
85 if (!dctx) 85 if (!dctx)
86 return 0; 86 return 0;
87 dctx->nbits = 1024; 87 dctx->nbits = 1024;
@@ -114,7 +114,7 @@ static void pkey_dsa_cleanup(EVP_PKEY_CTX *ctx)
114 { 114 {
115 DSA_PKEY_CTX *dctx = ctx->data; 115 DSA_PKEY_CTX *dctx = ctx->data;
116 if (dctx) 116 if (dctx)
117 OPENSSL_free(dctx); 117 free(dctx);
118 } 118 }
119 119
120static int pkey_dsa_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, 120static int pkey_dsa_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
diff --git a/src/lib/libcrypto/dsa/dsa_sign.c b/src/lib/libcrypto/dsa/dsa_sign.c
index e02365a8b1..5f48d6b622 100644
--- a/src/lib/libcrypto/dsa/dsa_sign.c
+++ b/src/lib/libcrypto/dsa/dsa_sign.c
@@ -76,7 +76,7 @@ int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
76DSA_SIG *DSA_SIG_new(void) 76DSA_SIG *DSA_SIG_new(void)
77 { 77 {
78 DSA_SIG *sig; 78 DSA_SIG *sig;
79 sig = OPENSSL_malloc(sizeof(DSA_SIG)); 79 sig = malloc(sizeof(DSA_SIG));
80 if (!sig) 80 if (!sig)
81 return NULL; 81 return NULL;
82 sig->r = NULL; 82 sig->r = NULL;
@@ -92,7 +92,7 @@ void DSA_SIG_free(DSA_SIG *sig)
92 BN_free(sig->r); 92 BN_free(sig->r);
93 if (sig->s) 93 if (sig->s)
94 BN_free(sig->s); 94 BN_free(sig->s);
95 OPENSSL_free(sig); 95 free(sig);
96 } 96 }
97 } 97 }
98 98
diff --git a/src/lib/libcrypto/dso/dso.h b/src/lib/libcrypto/dso/dso.h
index f36f209afd..9010251bbc 100644
--- a/src/lib/libcrypto/dso/dso.h
+++ b/src/lib/libcrypto/dso/dso.h
@@ -112,7 +112,7 @@ typedef struct dso_st DSO;
112 * (or NULL if they are to be used independantly of a DSO object) and a 112 * (or NULL if they are to be used independantly of a DSO object) and a
113 * filename to transform. They should either return NULL (if there is an error 113 * filename to transform. They should either return NULL (if there is an error
114 * condition) or a newly allocated string containing the transformed form that 114 * condition) or a newly allocated string containing the transformed form that
115 * the caller will need to free with OPENSSL_free() when done. */ 115 * the caller will need to free with free() when done. */
116typedef char* (*DSO_NAME_CONVERTER_FUNC)(DSO *, const char *); 116typedef char* (*DSO_NAME_CONVERTER_FUNC)(DSO *, const char *);
117/* The function prototype used for method functions (or caller-provided 117/* The function prototype used for method functions (or caller-provided
118 * callbacks) that merge two file specifications. They are passed a 118 * callbacks) that merge two file specifications. They are passed a
@@ -120,7 +120,7 @@ typedef char* (*DSO_NAME_CONVERTER_FUNC)(DSO *, const char *);
120 * a DSO object) and two file specifications to merge. They should 120 * a DSO object) and two file specifications to merge. They should
121 * either return NULL (if there is an error condition) or a newly allocated 121 * either return NULL (if there is an error condition) or a newly allocated
122 * string containing the result of merging that the caller will need 122 * string containing the result of merging that the caller will need
123 * to free with OPENSSL_free() when done. 123 * to free with free() when done.
124 * Here, merging means that bits and pieces are taken from each of the 124 * Here, merging means that bits and pieces are taken from each of the
125 * file specifications and added together in whatever fashion that is 125 * file specifications and added together in whatever fashion that is
126 * sensible for the DSO method in question. The only rule that really 126 * sensible for the DSO method in question. The only rule that really
@@ -136,7 +136,7 @@ typedef struct dso_meth_st
136 const char *name; 136 const char *name;
137 /* Loads a shared library, NB: new DSO_METHODs must ensure that a 137 /* Loads a shared library, NB: new DSO_METHODs must ensure that a
138 * successful load populates the loaded_filename field, and likewise a 138 * successful load populates the loaded_filename field, and likewise a
139 * successful unload OPENSSL_frees and NULLs it out. */ 139 * successful unload frees and NULLs it out. */
140 int (*dso_load)(DSO *dso); 140 int (*dso_load)(DSO *dso);
141 /* Unloads a shared library */ 141 /* Unloads a shared library */
142 int (*dso_unload)(DSO *dso); 142 int (*dso_unload)(DSO *dso);
@@ -242,12 +242,12 @@ int DSO_set_filename(DSO *dso, const char *filename);
242 * simply duplicated. NB: This function is usually called from within a 242 * simply duplicated. NB: This function is usually called from within a
243 * DSO_METHOD during the processing of a DSO_load() call, and is exposed so that 243 * DSO_METHOD during the processing of a DSO_load() call, and is exposed so that
244 * caller-created DSO_METHODs can do the same thing. A non-NULL return value 244 * caller-created DSO_METHODs can do the same thing. A non-NULL return value
245 * will need to be OPENSSL_free()'d. */ 245 * will need to be free()'d. */
246char *DSO_convert_filename(DSO *dso, const char *filename); 246char *DSO_convert_filename(DSO *dso, const char *filename);
247/* This function will invoke the DSO's merger callback to merge two file 247/* This function will invoke the DSO's merger callback to merge two file
248 * specifications, or if the callback isn't set it will instead use the 248 * specifications, or if the callback isn't set it will instead use the
249 * DSO_METHOD's merger. A non-NULL return value will need to be 249 * DSO_METHOD's merger. A non-NULL return value will need to be
250 * OPENSSL_free()'d. */ 250 * free()'d. */
251char *DSO_merge(DSO *dso, const char *filespec1, const char *filespec2); 251char *DSO_merge(DSO *dso, const char *filespec1, const char *filespec2);
252/* If the DSO is currently loaded, this returns the filename that it was loaded 252/* If the DSO is currently loaded, this returns the filename that it was loaded
253 * under, otherwise it returns NULL. So it is also useful as a test as to 253 * under, otherwise it returns NULL. So it is also useful as a test as to
diff --git a/src/lib/libcrypto/dso/dso_dlfcn.c b/src/lib/libcrypto/dso/dso_dlfcn.c
index fe5f0ffdb0..648ddb5ac0 100644
--- a/src/lib/libcrypto/dso/dso_dlfcn.c
+++ b/src/lib/libcrypto/dso/dso_dlfcn.c
@@ -153,7 +153,7 @@ static int dlfcn_load(DSO *dso)
153err: 153err:
154 /* Cleanup! */ 154 /* Cleanup! */
155 if(filename != NULL) 155 if(filename != NULL)
156 OPENSSL_free(filename); 156 free(filename);
157 if(ptr != NULL) 157 if(ptr != NULL)
158 dlclose(ptr); 158 dlclose(ptr);
159 return(0); 159 return(0);
@@ -264,7 +264,7 @@ static char *dlfcn_merger(DSO *dso, const char *filespec1,
264 if (!filespec2 || (filespec1 != NULL && filespec1[0] == '/')) 264 if (!filespec2 || (filespec1 != NULL && filespec1[0] == '/'))
265 { 265 {
266 len = strlen(filespec1) + 1; 266 len = strlen(filespec1) + 1;
267 merged = OPENSSL_malloc(len); 267 merged = malloc(len);
268 if(!merged) 268 if(!merged)
269 { 269 {
270 DSOerr(DSO_F_DLFCN_MERGER, ERR_R_MALLOC_FAILURE); 270 DSOerr(DSO_F_DLFCN_MERGER, ERR_R_MALLOC_FAILURE);
@@ -276,7 +276,7 @@ static char *dlfcn_merger(DSO *dso, const char *filespec1,
276 else if (!filespec1) 276 else if (!filespec1)
277 { 277 {
278 len = strlen(filespec2) + 1; 278 len = strlen(filespec2) + 1;
279 merged = OPENSSL_malloc(strlen(filespec2) + 1); 279 merged = malloc(strlen(filespec2) + 1);
280 if(!merged) 280 if(!merged)
281 { 281 {
282 DSOerr(DSO_F_DLFCN_MERGER, 282 DSOerr(DSO_F_DLFCN_MERGER,
@@ -302,7 +302,7 @@ static char *dlfcn_merger(DSO *dso, const char *filespec1,
302 spec2len--; 302 spec2len--;
303 len--; 303 len--;
304 } 304 }
305 merged = OPENSSL_malloc(len + 2); 305 merged = malloc(len + 2);
306 if(!merged) 306 if(!merged)
307 { 307 {
308 DSOerr(DSO_F_DLFCN_MERGER, 308 DSOerr(DSO_F_DLFCN_MERGER,
@@ -334,7 +334,7 @@ static char *dlfcn_name_converter(DSO *dso, const char *filename)
334 if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0) 334 if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0)
335 rsize += 3; /* The length of "lib" */ 335 rsize += 3; /* The length of "lib" */
336 } 336 }
337 translated = OPENSSL_malloc(rsize); 337 translated = malloc(rsize);
338 if(translated == NULL) 338 if(translated == NULL)
339 { 339 {
340 DSOerr(DSO_F_DLFCN_NAME_CONVERTER, 340 DSOerr(DSO_F_DLFCN_NAME_CONVERTER,
diff --git a/src/lib/libcrypto/dso/dso_lib.c b/src/lib/libcrypto/dso/dso_lib.c
index 8a15b794ab..68f5430ea8 100644
--- a/src/lib/libcrypto/dso/dso_lib.c
+++ b/src/lib/libcrypto/dso/dso_lib.c
@@ -100,7 +100,7 @@ DSO *DSO_new_method(DSO_METHOD *meth)
100 * to stealing the "best available" method. Will fallback 100 * to stealing the "best available" method. Will fallback
101 * to DSO_METH_null() in the worst case. */ 101 * to DSO_METH_null() in the worst case. */
102 default_DSO_meth = DSO_METHOD_openssl(); 102 default_DSO_meth = DSO_METHOD_openssl();
103 ret = (DSO *)OPENSSL_malloc(sizeof(DSO)); 103 ret = (DSO *)malloc(sizeof(DSO));
104 if(ret == NULL) 104 if(ret == NULL)
105 { 105 {
106 DSOerr(DSO_F_DSO_NEW_METHOD,ERR_R_MALLOC_FAILURE); 106 DSOerr(DSO_F_DSO_NEW_METHOD,ERR_R_MALLOC_FAILURE);
@@ -112,7 +112,7 @@ DSO *DSO_new_method(DSO_METHOD *meth)
112 { 112 {
113 /* sk_new doesn't generate any errors so we do */ 113 /* sk_new doesn't generate any errors so we do */
114 DSOerr(DSO_F_DSO_NEW_METHOD,ERR_R_MALLOC_FAILURE); 114 DSOerr(DSO_F_DSO_NEW_METHOD,ERR_R_MALLOC_FAILURE);
115 OPENSSL_free(ret); 115 free(ret);
116 return(NULL); 116 return(NULL);
117 } 117 }
118 if(meth == NULL) 118 if(meth == NULL)
@@ -122,7 +122,7 @@ DSO *DSO_new_method(DSO_METHOD *meth)
122 ret->references = 1; 122 ret->references = 1;
123 if((ret->meth->init != NULL) && !ret->meth->init(ret)) 123 if((ret->meth->init != NULL) && !ret->meth->init(ret))
124 { 124 {
125 OPENSSL_free(ret); 125 free(ret);
126 ret=NULL; 126 ret=NULL;
127 } 127 }
128 return(ret); 128 return(ret);
@@ -165,11 +165,11 @@ int DSO_free(DSO *dso)
165 165
166 sk_void_free(dso->meth_data); 166 sk_void_free(dso->meth_data);
167 if(dso->filename != NULL) 167 if(dso->filename != NULL)
168 OPENSSL_free(dso->filename); 168 free(dso->filename);
169 if(dso->loaded_filename != NULL) 169 if(dso->loaded_filename != NULL)
170 OPENSSL_free(dso->loaded_filename); 170 free(dso->loaded_filename);
171 171
172 OPENSSL_free(dso); 172 free(dso);
173 return(1); 173 return(1);
174 } 174 }
175 175
@@ -377,7 +377,7 @@ int DSO_set_filename(DSO *dso, const char *filename)
377 return(0); 377 return(0);
378 } 378 }
379 /* We'll duplicate filename */ 379 /* We'll duplicate filename */
380 copied = OPENSSL_malloc(strlen(filename) + 1); 380 copied = malloc(strlen(filename) + 1);
381 if(copied == NULL) 381 if(copied == NULL)
382 { 382 {
383 DSOerr(DSO_F_DSO_SET_FILENAME,ERR_R_MALLOC_FAILURE); 383 DSOerr(DSO_F_DSO_SET_FILENAME,ERR_R_MALLOC_FAILURE);
@@ -385,7 +385,7 @@ int DSO_set_filename(DSO *dso, const char *filename)
385 } 385 }
386 BUF_strlcpy(copied, filename, strlen(filename) + 1); 386 BUF_strlcpy(copied, filename, strlen(filename) + 1);
387 if(dso->filename) 387 if(dso->filename)
388 OPENSSL_free(dso->filename); 388 free(dso->filename);
389 dso->filename = copied; 389 dso->filename = copied;
390 return(1); 390 return(1);
391 } 391 }
@@ -435,7 +435,7 @@ char *DSO_convert_filename(DSO *dso, const char *filename)
435 } 435 }
436 if(result == NULL) 436 if(result == NULL)
437 { 437 {
438 result = OPENSSL_malloc(strlen(filename) + 1); 438 result = malloc(strlen(filename) + 1);
439 if(result == NULL) 439 if(result == NULL)
440 { 440 {
441 DSOerr(DSO_F_DSO_CONVERT_FILENAME, 441 DSOerr(DSO_F_DSO_CONVERT_FILENAME,
diff --git a/src/lib/libcrypto/ec/ec_ameth.c b/src/lib/libcrypto/ec/ec_ameth.c
index 0ce4524076..6331903141 100644
--- a/src/lib/libcrypto/ec/ec_ameth.c
+++ b/src/lib/libcrypto/ec/ec_ameth.c
@@ -116,7 +116,7 @@ static int eckey_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
116 penclen = i2o_ECPublicKey(ec_key, NULL); 116 penclen = i2o_ECPublicKey(ec_key, NULL);
117 if (penclen <= 0) 117 if (penclen <= 0)
118 goto err; 118 goto err;
119 penc = OPENSSL_malloc(penclen); 119 penc = malloc(penclen);
120 if (!penc) 120 if (!penc)
121 goto err; 121 goto err;
122 p = penc; 122 p = penc;
@@ -132,7 +132,7 @@ static int eckey_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
132 else 132 else
133 ASN1_STRING_free(pval); 133 ASN1_STRING_free(pval);
134 if (penc) 134 if (penc)
135 OPENSSL_free(penc); 135 free(penc);
136 return 0; 136 return 0;
137 } 137 }
138 138
@@ -339,7 +339,7 @@ static int eckey_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
339 ECerr(EC_F_ECKEY_PRIV_ENCODE, ERR_R_EC_LIB); 339 ECerr(EC_F_ECKEY_PRIV_ENCODE, ERR_R_EC_LIB);
340 return 0; 340 return 0;
341 } 341 }
342 ep = (unsigned char *) OPENSSL_malloc(eplen); 342 ep = (unsigned char *) malloc(eplen);
343 if (!ep) 343 if (!ep)
344 { 344 {
345 EC_KEY_set_enc_flags(ec_key, old_flags); 345 EC_KEY_set_enc_flags(ec_key, old_flags);
@@ -350,7 +350,7 @@ static int eckey_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
350 if (!i2d_ECPrivateKey(ec_key, &p)) 350 if (!i2d_ECPrivateKey(ec_key, &p))
351 { 351 {
352 EC_KEY_set_enc_flags(ec_key, old_flags); 352 EC_KEY_set_enc_flags(ec_key, old_flags);
353 OPENSSL_free(ep); 353 free(ep);
354 ECerr(EC_F_ECKEY_PRIV_ENCODE, ERR_R_EC_LIB); 354 ECerr(EC_F_ECKEY_PRIV_ENCODE, ERR_R_EC_LIB);
355 } 355 }
356 /* restore old encoding flags */ 356 /* restore old encoding flags */
@@ -474,7 +474,7 @@ static int do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, int ktype)
474 if (ktype > 0) 474 if (ktype > 0)
475 { 475 {
476 buf_len += 10; 476 buf_len += 10;
477 if ((buffer = OPENSSL_malloc(buf_len)) == NULL) 477 if ((buffer = malloc(buf_len)) == NULL)
478 { 478 {
479 reason = ERR_R_MALLOC_FAILURE; 479 reason = ERR_R_MALLOC_FAILURE;
480 goto err; 480 goto err;
@@ -515,7 +515,7 @@ err:
515 if (ctx) 515 if (ctx)
516 BN_CTX_free(ctx); 516 BN_CTX_free(ctx);
517 if (buffer != NULL) 517 if (buffer != NULL)
518 OPENSSL_free(buffer); 518 free(buffer);
519 return(ret); 519 return(ret);
520 } 520 }
521 521
diff --git a/src/lib/libcrypto/ec/ec_asn1.c b/src/lib/libcrypto/ec/ec_asn1.c
index 145807b611..2bde9a6a3c 100644
--- a/src/lib/libcrypto/ec/ec_asn1.c
+++ b/src/lib/libcrypto/ec/ec_asn1.c
@@ -485,7 +485,7 @@ static int ec_asn1_group2curve(const EC_GROUP *group, X9_62_CURVE *curve)
485 } 485 }
486 else 486 else
487 { 487 {
488 if ((buffer_1 = OPENSSL_malloc(len_1)) == NULL) 488 if ((buffer_1 = malloc(len_1)) == NULL)
489 { 489 {
490 ECerr(EC_F_EC_ASN1_GROUP2CURVE, 490 ECerr(EC_F_EC_ASN1_GROUP2CURVE,
491 ERR_R_MALLOC_FAILURE); 491 ERR_R_MALLOC_FAILURE);
@@ -507,7 +507,7 @@ static int ec_asn1_group2curve(const EC_GROUP *group, X9_62_CURVE *curve)
507 } 507 }
508 else 508 else
509 { 509 {
510 if ((buffer_2 = OPENSSL_malloc(len_2)) == NULL) 510 if ((buffer_2 = malloc(len_2)) == NULL)
511 { 511 {
512 ECerr(EC_F_EC_ASN1_GROUP2CURVE, 512 ECerr(EC_F_EC_ASN1_GROUP2CURVE,
513 ERR_R_MALLOC_FAILURE); 513 ERR_R_MALLOC_FAILURE);
@@ -559,9 +559,9 @@ static int ec_asn1_group2curve(const EC_GROUP *group, X9_62_CURVE *curve)
559 ok = 1; 559 ok = 1;
560 560
561err: if (buffer_1) 561err: if (buffer_1)
562 OPENSSL_free(buffer_1); 562 free(buffer_1);
563 if (buffer_2) 563 if (buffer_2)
564 OPENSSL_free(buffer_2); 564 free(buffer_2);
565 if (tmp_1) 565 if (tmp_1)
566 BN_free(tmp_1); 566 BN_free(tmp_1);
567 if (tmp_2) 567 if (tmp_2)
@@ -630,7 +630,7 @@ static ECPARAMETERS *ec_asn1_group2parameters(const EC_GROUP *group,
630 ECerr(EC_F_EC_ASN1_GROUP2PARAMETERS, ERR_R_EC_LIB); 630 ECerr(EC_F_EC_ASN1_GROUP2PARAMETERS, ERR_R_EC_LIB);
631 goto err; 631 goto err;
632 } 632 }
633 if ((buffer = OPENSSL_malloc(len)) == NULL) 633 if ((buffer = malloc(len)) == NULL)
634 { 634 {
635 ECerr(EC_F_EC_ASN1_GROUP2PARAMETERS, ERR_R_MALLOC_FAILURE); 635 ECerr(EC_F_EC_ASN1_GROUP2PARAMETERS, ERR_R_MALLOC_FAILURE);
636 goto err; 636 goto err;
@@ -686,7 +686,7 @@ err : if(!ok)
686 if (tmp) 686 if (tmp)
687 BN_free(tmp); 687 BN_free(tmp);
688 if (buffer) 688 if (buffer)
689 OPENSSL_free(buffer); 689 free(buffer);
690 return(ret); 690 return(ret);
691 } 691 }
692 692
@@ -925,8 +925,8 @@ static EC_GROUP *ec_asn1_parameters2group(const ECPARAMETERS *params)
925 if (params->curve->seed != NULL) 925 if (params->curve->seed != NULL)
926 { 926 {
927 if (ret->seed != NULL) 927 if (ret->seed != NULL)
928 OPENSSL_free(ret->seed); 928 free(ret->seed);
929 if (!(ret->seed = OPENSSL_malloc(params->curve->seed->length))) 929 if (!(ret->seed = malloc(params->curve->seed->length)))
930 { 930 {
931 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, 931 ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP,
932 ERR_R_MALLOC_FAILURE); 932 ERR_R_MALLOC_FAILURE);
@@ -1247,7 +1247,7 @@ int i2d_ECPrivateKey(EC_KEY *a, unsigned char **out)
1247 priv_key->version = a->version; 1247 priv_key->version = a->version;
1248 1248
1249 buf_len = (size_t)BN_num_bytes(a->priv_key); 1249 buf_len = (size_t)BN_num_bytes(a->priv_key);
1250 buffer = OPENSSL_malloc(buf_len); 1250 buffer = malloc(buf_len);
1251 if (buffer == NULL) 1251 if (buffer == NULL)
1252 { 1252 {
1253 ECerr(EC_F_I2D_ECPRIVATEKEY, 1253 ECerr(EC_F_I2D_ECPRIVATEKEY,
@@ -1292,7 +1292,7 @@ int i2d_ECPrivateKey(EC_KEY *a, unsigned char **out)
1292 1292
1293 if (tmp_len > buf_len) 1293 if (tmp_len > buf_len)
1294 { 1294 {
1295 unsigned char *tmp_buffer = OPENSSL_realloc(buffer, tmp_len); 1295 unsigned char *tmp_buffer = realloc(buffer, tmp_len);
1296 if (!tmp_buffer) 1296 if (!tmp_buffer)
1297 { 1297 {
1298 ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE); 1298 ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE);
@@ -1327,7 +1327,7 @@ int i2d_ECPrivateKey(EC_KEY *a, unsigned char **out)
1327 ok=1; 1327 ok=1;
1328err: 1328err:
1329 if (buffer) 1329 if (buffer)
1330 OPENSSL_free(buffer); 1330 free(buffer);
1331 if (priv_key) 1331 if (priv_key)
1332 EC_PRIVATEKEY_free(priv_key); 1332 EC_PRIVATEKEY_free(priv_key);
1333 return(ok?ret:0); 1333 return(ok?ret:0);
@@ -1424,7 +1424,7 @@ int i2o_ECPublicKey(EC_KEY *a, unsigned char **out)
1424 1424
1425 if (*out == NULL) 1425 if (*out == NULL)
1426 { 1426 {
1427 if ((*out = OPENSSL_malloc(buf_len)) == NULL) 1427 if ((*out = malloc(buf_len)) == NULL)
1428 { 1428 {
1429 ECerr(EC_F_I2O_ECPUBLICKEY, ERR_R_MALLOC_FAILURE); 1429 ECerr(EC_F_I2O_ECPUBLICKEY, ERR_R_MALLOC_FAILURE);
1430 return 0; 1430 return 0;
@@ -1435,7 +1435,7 @@ int i2o_ECPublicKey(EC_KEY *a, unsigned char **out)
1435 *out, buf_len, NULL)) 1435 *out, buf_len, NULL))
1436 { 1436 {
1437 ECerr(EC_F_I2O_ECPUBLICKEY, ERR_R_EC_LIB); 1437 ECerr(EC_F_I2O_ECPUBLICKEY, ERR_R_EC_LIB);
1438 OPENSSL_free(*out); 1438 free(*out);
1439 *out = NULL; 1439 *out = NULL;
1440 return 0; 1440 return 0;
1441 } 1441 }
diff --git a/src/lib/libcrypto/ec/ec_key.c b/src/lib/libcrypto/ec/ec_key.c
index d528601036..4375514ef5 100644
--- a/src/lib/libcrypto/ec/ec_key.c
+++ b/src/lib/libcrypto/ec/ec_key.c
@@ -69,7 +69,7 @@ EC_KEY *EC_KEY_new(void)
69 { 69 {
70 EC_KEY *ret; 70 EC_KEY *ret;
71 71
72 ret=(EC_KEY *)OPENSSL_malloc(sizeof(EC_KEY)); 72 ret=(EC_KEY *)malloc(sizeof(EC_KEY));
73 if (ret == NULL) 73 if (ret == NULL)
74 { 74 {
75 ECerr(EC_F_EC_KEY_NEW, ERR_R_MALLOC_FAILURE); 75 ECerr(EC_F_EC_KEY_NEW, ERR_R_MALLOC_FAILURE);
@@ -132,7 +132,7 @@ void EC_KEY_free(EC_KEY *r)
132 132
133 OPENSSL_cleanse((void *)r, sizeof(EC_KEY)); 133 OPENSSL_cleanse((void *)r, sizeof(EC_KEY));
134 134
135 OPENSSL_free(r); 135 free(r);
136 } 136 }
137 137
138EC_KEY *EC_KEY_copy(EC_KEY *dest, const EC_KEY *src) 138EC_KEY *EC_KEY_copy(EC_KEY *dest, const EC_KEY *src)
diff --git a/src/lib/libcrypto/ec/ec_lib.c b/src/lib/libcrypto/ec/ec_lib.c
index e2c4741b5b..546fd08e38 100644
--- a/src/lib/libcrypto/ec/ec_lib.c
+++ b/src/lib/libcrypto/ec/ec_lib.c
@@ -88,7 +88,7 @@ EC_GROUP *EC_GROUP_new(const EC_METHOD *meth)
88 return NULL; 88 return NULL;
89 } 89 }
90 90
91 ret = OPENSSL_malloc(sizeof *ret); 91 ret = malloc(sizeof *ret);
92 if (ret == NULL) 92 if (ret == NULL)
93 { 93 {
94 ECerr(EC_F_EC_GROUP_NEW, ERR_R_MALLOC_FAILURE); 94 ECerr(EC_F_EC_GROUP_NEW, ERR_R_MALLOC_FAILURE);
@@ -112,7 +112,7 @@ EC_GROUP *EC_GROUP_new(const EC_METHOD *meth)
112 112
113 if (!meth->group_init(ret)) 113 if (!meth->group_init(ret))
114 { 114 {
115 OPENSSL_free(ret); 115 free(ret);
116 return NULL; 116 return NULL;
117 } 117 }
118 118
@@ -135,9 +135,9 @@ void EC_GROUP_free(EC_GROUP *group)
135 BN_free(&group->cofactor); 135 BN_free(&group->cofactor);
136 136
137 if (group->seed) 137 if (group->seed)
138 OPENSSL_free(group->seed); 138 free(group->seed);
139 139
140 OPENSSL_free(group); 140 free(group);
141 } 141 }
142 142
143 143
@@ -160,11 +160,11 @@ void EC_GROUP_clear_free(EC_GROUP *group)
160 if (group->seed) 160 if (group->seed)
161 { 161 {
162 OPENSSL_cleanse(group->seed, group->seed_len); 162 OPENSSL_cleanse(group->seed, group->seed_len);
163 OPENSSL_free(group->seed); 163 free(group->seed);
164 } 164 }
165 165
166 OPENSSL_cleanse(group, sizeof *group); 166 OPENSSL_cleanse(group, sizeof *group);
167 OPENSSL_free(group); 167 free(group);
168 } 168 }
169 169
170 170
@@ -226,8 +226,8 @@ int EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src)
226 if (src->seed) 226 if (src->seed)
227 { 227 {
228 if (dest->seed) 228 if (dest->seed)
229 OPENSSL_free(dest->seed); 229 free(dest->seed);
230 dest->seed = OPENSSL_malloc(src->seed_len); 230 dest->seed = malloc(src->seed_len);
231 if (dest->seed == NULL) 231 if (dest->seed == NULL)
232 return 0; 232 return 0;
233 if (!memcpy(dest->seed, src->seed, src->seed_len)) 233 if (!memcpy(dest->seed, src->seed, src->seed_len))
@@ -237,7 +237,7 @@ int EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src)
237 else 237 else
238 { 238 {
239 if (dest->seed) 239 if (dest->seed)
240 OPENSSL_free(dest->seed); 240 free(dest->seed);
241 dest->seed = NULL; 241 dest->seed = NULL;
242 dest->seed_len = 0; 242 dest->seed_len = 0;
243 } 243 }
@@ -375,7 +375,7 @@ size_t EC_GROUP_set_seed(EC_GROUP *group, const unsigned char *p, size_t len)
375 { 375 {
376 if (group->seed) 376 if (group->seed)
377 { 377 {
378 OPENSSL_free(group->seed); 378 free(group->seed);
379 group->seed = NULL; 379 group->seed = NULL;
380 group->seed_len = 0; 380 group->seed_len = 0;
381 } 381 }
@@ -383,7 +383,7 @@ size_t EC_GROUP_set_seed(EC_GROUP *group, const unsigned char *p, size_t len)
383 if (!len || !p) 383 if (!len || !p)
384 return 1; 384 return 1;
385 385
386 if ((group->seed = OPENSSL_malloc(len)) == NULL) 386 if ((group->seed = malloc(len)) == NULL)
387 return 0; 387 return 0;
388 memcpy(group->seed, p, len); 388 memcpy(group->seed, p, len);
389 group->seed_len = len; 389 group->seed_len = len;
@@ -567,7 +567,7 @@ int EC_EX_DATA_set_data(EC_EXTRA_DATA **ex_data, void *data,
567 /* no explicit entry needed */ 567 /* no explicit entry needed */
568 return 1; 568 return 1;
569 569
570 d = OPENSSL_malloc(sizeof *d); 570 d = malloc(sizeof *d);
571 if (d == NULL) 571 if (d == NULL)
572 return 0; 572 return 0;
573 573
@@ -613,7 +613,7 @@ void EC_EX_DATA_free_data(EC_EXTRA_DATA **ex_data,
613 EC_EXTRA_DATA *next = (*p)->next; 613 EC_EXTRA_DATA *next = (*p)->next;
614 614
615 (*p)->free_func((*p)->data); 615 (*p)->free_func((*p)->data);
616 OPENSSL_free(*p); 616 free(*p);
617 617
618 *p = next; 618 *p = next;
619 return; 619 return;
@@ -637,7 +637,7 @@ void EC_EX_DATA_clear_free_data(EC_EXTRA_DATA **ex_data,
637 EC_EXTRA_DATA *next = (*p)->next; 637 EC_EXTRA_DATA *next = (*p)->next;
638 638
639 (*p)->clear_free_func((*p)->data); 639 (*p)->clear_free_func((*p)->data);
640 OPENSSL_free(*p); 640 free(*p);
641 641
642 *p = next; 642 *p = next;
643 return; 643 return;
@@ -659,7 +659,7 @@ void EC_EX_DATA_free_all_data(EC_EXTRA_DATA **ex_data)
659 EC_EXTRA_DATA *next = d->next; 659 EC_EXTRA_DATA *next = d->next;
660 660
661 d->free_func(d->data); 661 d->free_func(d->data);
662 OPENSSL_free(d); 662 free(d);
663 663
664 d = next; 664 d = next;
665 } 665 }
@@ -680,7 +680,7 @@ void EC_EX_DATA_clear_free_all_data(EC_EXTRA_DATA **ex_data)
680 EC_EXTRA_DATA *next = d->next; 680 EC_EXTRA_DATA *next = d->next;
681 681
682 d->clear_free_func(d->data); 682 d->clear_free_func(d->data);
683 OPENSSL_free(d); 683 free(d);
684 684
685 d = next; 685 d = next;
686 } 686 }
@@ -705,7 +705,7 @@ EC_POINT *EC_POINT_new(const EC_GROUP *group)
705 return NULL; 705 return NULL;
706 } 706 }
707 707
708 ret = OPENSSL_malloc(sizeof *ret); 708 ret = malloc(sizeof *ret);
709 if (ret == NULL) 709 if (ret == NULL)
710 { 710 {
711 ECerr(EC_F_EC_POINT_NEW, ERR_R_MALLOC_FAILURE); 711 ECerr(EC_F_EC_POINT_NEW, ERR_R_MALLOC_FAILURE);
@@ -716,7 +716,7 @@ EC_POINT *EC_POINT_new(const EC_GROUP *group)
716 716
717 if (!ret->meth->point_init(ret)) 717 if (!ret->meth->point_init(ret))
718 { 718 {
719 OPENSSL_free(ret); 719 free(ret);
720 return NULL; 720 return NULL;
721 } 721 }
722 722
@@ -730,7 +730,7 @@ void EC_POINT_free(EC_POINT *point)
730 730
731 if (point->meth->point_finish != 0) 731 if (point->meth->point_finish != 0)
732 point->meth->point_finish(point); 732 point->meth->point_finish(point);
733 OPENSSL_free(point); 733 free(point);
734 } 734 }
735 735
736 736
@@ -743,7 +743,7 @@ void EC_POINT_clear_free(EC_POINT *point)
743 else if (point->meth->point_finish != 0) 743 else if (point->meth->point_finish != 0)
744 point->meth->point_finish(point); 744 point->meth->point_finish(point);
745 OPENSSL_cleanse(point, sizeof *point); 745 OPENSSL_cleanse(point, sizeof *point);
746 OPENSSL_free(point); 746 free(point);
747 } 747 }
748 748
749 749
diff --git a/src/lib/libcrypto/ec/ec_mult.c b/src/lib/libcrypto/ec/ec_mult.c
index 19f21675fb..b48c888048 100644
--- a/src/lib/libcrypto/ec/ec_mult.c
+++ b/src/lib/libcrypto/ec/ec_mult.c
@@ -102,7 +102,7 @@ static EC_PRE_COMP *ec_pre_comp_new(const EC_GROUP *group)
102 if (!group) 102 if (!group)
103 return NULL; 103 return NULL;
104 104
105 ret = (EC_PRE_COMP *)OPENSSL_malloc(sizeof(EC_PRE_COMP)); 105 ret = (EC_PRE_COMP *)malloc(sizeof(EC_PRE_COMP));
106 if (!ret) 106 if (!ret)
107 { 107 {
108 ECerr(EC_F_EC_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE); 108 ECerr(EC_F_EC_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE);
@@ -147,9 +147,9 @@ static void ec_pre_comp_free(void *pre_)
147 147
148 for (p = pre->points; *p != NULL; p++) 148 for (p = pre->points; *p != NULL; p++)
149 EC_POINT_free(*p); 149 EC_POINT_free(*p);
150 OPENSSL_free(pre->points); 150 free(pre->points);
151 } 151 }
152 OPENSSL_free(pre); 152 free(pre);
153 } 153 }
154 154
155static void ec_pre_comp_clear_free(void *pre_) 155static void ec_pre_comp_clear_free(void *pre_)
@@ -173,10 +173,10 @@ static void ec_pre_comp_clear_free(void *pre_)
173 EC_POINT_clear_free(*p); 173 EC_POINT_clear_free(*p);
174 OPENSSL_cleanse(p, sizeof *p); 174 OPENSSL_cleanse(p, sizeof *p);
175 } 175 }
176 OPENSSL_free(pre->points); 176 free(pre->points);
177 } 177 }
178 OPENSSL_cleanse(pre, sizeof *pre); 178 OPENSSL_cleanse(pre, sizeof *pre);
179 OPENSSL_free(pre); 179 free(pre);
180 } 180 }
181 181
182 182
@@ -201,7 +201,7 @@ static signed char *compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len)
201 201
202 if (BN_is_zero(scalar)) 202 if (BN_is_zero(scalar))
203 { 203 {
204 r = OPENSSL_malloc(1); 204 r = malloc(1);
205 if (!r) 205 if (!r)
206 { 206 {
207 ECerr(EC_F_COMPUTE_WNAF, ERR_R_MALLOC_FAILURE); 207 ECerr(EC_F_COMPUTE_WNAF, ERR_R_MALLOC_FAILURE);
@@ -233,7 +233,7 @@ static signed char *compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len)
233 } 233 }
234 234
235 len = BN_num_bits(scalar); 235 len = BN_num_bits(scalar);
236 r = OPENSSL_malloc(len + 1); /* modified wNAF may be one digit longer than binary representation 236 r = malloc(len + 1); /* modified wNAF may be one digit longer than binary representation
237 * (*ret_len will be set to the actual length, i.e. at most 237 * (*ret_len will be set to the actual length, i.e. at most
238 * BN_num_bits(scalar) + 1) */ 238 * BN_num_bits(scalar) + 1) */
239 if (r == NULL) 239 if (r == NULL)
@@ -315,7 +315,7 @@ static signed char *compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len)
315 err: 315 err:
316 if (!ok) 316 if (!ok)
317 { 317 {
318 OPENSSL_free(r); 318 free(r);
319 r = NULL; 319 r = NULL;
320 } 320 }
321 if (ok) 321 if (ok)
@@ -441,10 +441,10 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
441 441
442 totalnum = num + numblocks; 442 totalnum = num + numblocks;
443 443
444 wsize = OPENSSL_malloc(totalnum * sizeof wsize[0]); 444 wsize = malloc(totalnum * sizeof wsize[0]);
445 wNAF_len = OPENSSL_malloc(totalnum * sizeof wNAF_len[0]); 445 wNAF_len = malloc(totalnum * sizeof wNAF_len[0]);
446 wNAF = OPENSSL_malloc((totalnum + 1) * sizeof wNAF[0]); /* includes space for pivot */ 446 wNAF = malloc((totalnum + 1) * sizeof wNAF[0]); /* includes space for pivot */
447 val_sub = OPENSSL_malloc(totalnum * sizeof val_sub[0]); 447 val_sub = malloc(totalnum * sizeof val_sub[0]);
448 448
449 if (!wsize || !wNAF_len || !wNAF || !val_sub) 449 if (!wsize || !wNAF_len || !wNAF || !val_sub)
450 { 450 {
@@ -560,11 +560,11 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
560 wNAF_len[i] = tmp_len; 560 wNAF_len[i] = tmp_len;
561 561
562 wNAF[i + 1] = NULL; 562 wNAF[i + 1] = NULL;
563 wNAF[i] = OPENSSL_malloc(wNAF_len[i]); 563 wNAF[i] = malloc(wNAF_len[i]);
564 if (wNAF[i] == NULL) 564 if (wNAF[i] == NULL)
565 { 565 {
566 ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE); 566 ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);
567 OPENSSL_free(tmp_wNAF); 567 free(tmp_wNAF);
568 goto err; 568 goto err;
569 } 569 }
570 memcpy(wNAF[i], pp, wNAF_len[i]); 570 memcpy(wNAF[i], pp, wNAF_len[i]);
@@ -574,14 +574,14 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
574 if (*tmp_points == NULL) 574 if (*tmp_points == NULL)
575 { 575 {
576 ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); 576 ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);
577 OPENSSL_free(tmp_wNAF); 577 free(tmp_wNAF);
578 goto err; 578 goto err;
579 } 579 }
580 val_sub[i] = tmp_points; 580 val_sub[i] = tmp_points;
581 tmp_points += pre_points_per_block; 581 tmp_points += pre_points_per_block;
582 pp += blocksize; 582 pp += blocksize;
583 } 583 }
584 OPENSSL_free(tmp_wNAF); 584 free(tmp_wNAF);
585 } 585 }
586 } 586 }
587 } 587 }
@@ -589,7 +589,7 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
589 /* All points we precompute now go into a single array 'val'. 589 /* All points we precompute now go into a single array 'val'.
590 * 'val_sub[i]' is a pointer to the subarray for the i-th point, 590 * 'val_sub[i]' is a pointer to the subarray for the i-th point,
591 * or to a subarray of 'pre_comp->points' if we already have precomputation. */ 591 * or to a subarray of 'pre_comp->points' if we already have precomputation. */
592 val = OPENSSL_malloc((num_val + 1) * sizeof val[0]); 592 val = malloc((num_val + 1) * sizeof val[0]);
593 if (val == NULL) 593 if (val == NULL)
594 { 594 {
595 ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE); 595 ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);
@@ -716,28 +716,28 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
716 if (tmp != NULL) 716 if (tmp != NULL)
717 EC_POINT_free(tmp); 717 EC_POINT_free(tmp);
718 if (wsize != NULL) 718 if (wsize != NULL)
719 OPENSSL_free(wsize); 719 free(wsize);
720 if (wNAF_len != NULL) 720 if (wNAF_len != NULL)
721 OPENSSL_free(wNAF_len); 721 free(wNAF_len);
722 if (wNAF != NULL) 722 if (wNAF != NULL)
723 { 723 {
724 signed char **w; 724 signed char **w;
725 725
726 for (w = wNAF; *w != NULL; w++) 726 for (w = wNAF; *w != NULL; w++)
727 OPENSSL_free(*w); 727 free(*w);
728 728
729 OPENSSL_free(wNAF); 729 free(wNAF);
730 } 730 }
731 if (val != NULL) 731 if (val != NULL)
732 { 732 {
733 for (v = val; *v != NULL; v++) 733 for (v = val; *v != NULL; v++)
734 EC_POINT_clear_free(*v); 734 EC_POINT_clear_free(*v);
735 735
736 OPENSSL_free(val); 736 free(val);
737 } 737 }
738 if (val_sub != NULL) 738 if (val_sub != NULL)
739 { 739 {
740 OPENSSL_free(val_sub); 740 free(val_sub);
741 } 741 }
742 return ret; 742 return ret;
743 } 743 }
@@ -825,7 +825,7 @@ int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
825 pre_points_per_block = (size_t)1 << (w - 1); 825 pre_points_per_block = (size_t)1 << (w - 1);
826 num = pre_points_per_block * numblocks; /* number of points to compute and store */ 826 num = pre_points_per_block * numblocks; /* number of points to compute and store */
827 827
828 points = OPENSSL_malloc(sizeof (EC_POINT*)*(num + 1)); 828 points = malloc(sizeof (EC_POINT*)*(num + 1));
829 if (!points) 829 if (!points)
830 { 830 {
831 ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, ERR_R_MALLOC_FAILURE); 831 ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, ERR_R_MALLOC_FAILURE);
@@ -921,7 +921,7 @@ int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
921 921
922 for (p = points; *p != NULL; p++) 922 for (p = points; *p != NULL; p++)
923 EC_POINT_free(*p); 923 EC_POINT_free(*p);
924 OPENSSL_free(points); 924 free(points);
925 } 925 }
926 if (tmp_point) 926 if (tmp_point)
927 EC_POINT_free(tmp_point); 927 EC_POINT_free(tmp_point);
diff --git a/src/lib/libcrypto/ec/ec_pmeth.c b/src/lib/libcrypto/ec/ec_pmeth.c
index 66ee397d86..dfc8ace27b 100644
--- a/src/lib/libcrypto/ec/ec_pmeth.c
+++ b/src/lib/libcrypto/ec/ec_pmeth.c
@@ -77,7 +77,7 @@ typedef struct
77static int pkey_ec_init(EVP_PKEY_CTX *ctx) 77static int pkey_ec_init(EVP_PKEY_CTX *ctx)
78 { 78 {
79 EC_PKEY_CTX *dctx; 79 EC_PKEY_CTX *dctx;
80 dctx = OPENSSL_malloc(sizeof(EC_PKEY_CTX)); 80 dctx = malloc(sizeof(EC_PKEY_CTX));
81 if (!dctx) 81 if (!dctx)
82 return 0; 82 return 0;
83 dctx->gen_group = NULL; 83 dctx->gen_group = NULL;
@@ -112,7 +112,7 @@ static void pkey_ec_cleanup(EVP_PKEY_CTX *ctx)
112 { 112 {
113 if (dctx->gen_group) 113 if (dctx->gen_group)
114 EC_GROUP_free(dctx->gen_group); 114 EC_GROUP_free(dctx->gen_group);
115 OPENSSL_free(dctx); 115 free(dctx);
116 } 116 }
117 } 117 }
118 118
diff --git a/src/lib/libcrypto/ec/ec_print.c b/src/lib/libcrypto/ec/ec_print.c
index f7c8a303ac..1655332c3c 100644
--- a/src/lib/libcrypto/ec/ec_print.c
+++ b/src/lib/libcrypto/ec/ec_print.c
@@ -70,18 +70,18 @@ BIGNUM *EC_POINT_point2bn(const EC_GROUP *group,
70 if (buf_len == 0) 70 if (buf_len == 0)
71 return NULL; 71 return NULL;
72 72
73 if ((buf = OPENSSL_malloc(buf_len)) == NULL) 73 if ((buf = malloc(buf_len)) == NULL)
74 return NULL; 74 return NULL;
75 75
76 if (!EC_POINT_point2oct(group, point, form, buf, buf_len, ctx)) 76 if (!EC_POINT_point2oct(group, point, form, buf, buf_len, ctx))
77 { 77 {
78 OPENSSL_free(buf); 78 free(buf);
79 return NULL; 79 return NULL;
80 } 80 }
81 81
82 ret = BN_bin2bn(buf, buf_len, ret); 82 ret = BN_bin2bn(buf, buf_len, ret);
83 83
84 OPENSSL_free(buf); 84 free(buf);
85 85
86 return ret; 86 return ret;
87} 87}
@@ -96,13 +96,13 @@ EC_POINT *EC_POINT_bn2point(const EC_GROUP *group,
96 EC_POINT *ret; 96 EC_POINT *ret;
97 97
98 if ((buf_len = BN_num_bytes(bn)) == 0) return NULL; 98 if ((buf_len = BN_num_bytes(bn)) == 0) return NULL;
99 buf = OPENSSL_malloc(buf_len); 99 buf = malloc(buf_len);
100 if (buf == NULL) 100 if (buf == NULL)
101 return NULL; 101 return NULL;
102 102
103 if (!BN_bn2bin(bn, buf)) 103 if (!BN_bn2bin(bn, buf))
104 { 104 {
105 OPENSSL_free(buf); 105 free(buf);
106 return NULL; 106 return NULL;
107 } 107 }
108 108
@@ -110,7 +110,7 @@ EC_POINT *EC_POINT_bn2point(const EC_GROUP *group,
110 { 110 {
111 if ((ret = EC_POINT_new(group)) == NULL) 111 if ((ret = EC_POINT_new(group)) == NULL)
112 { 112 {
113 OPENSSL_free(buf); 113 free(buf);
114 return NULL; 114 return NULL;
115 } 115 }
116 } 116 }
@@ -121,17 +121,17 @@ EC_POINT *EC_POINT_bn2point(const EC_GROUP *group,
121 { 121 {
122 if (point == NULL) 122 if (point == NULL)
123 EC_POINT_clear_free(ret); 123 EC_POINT_clear_free(ret);
124 OPENSSL_free(buf); 124 free(buf);
125 return NULL; 125 return NULL;
126 } 126 }
127 127
128 OPENSSL_free(buf); 128 free(buf);
129 return ret; 129 return ret;
130 } 130 }
131 131
132static const char *HEX_DIGITS = "0123456789ABCDEF"; 132static const char *HEX_DIGITS = "0123456789ABCDEF";
133 133
134/* the return value must be freed (using OPENSSL_free()) */ 134/* the return value must be freed (using free()) */
135char *EC_POINT_point2hex(const EC_GROUP *group, 135char *EC_POINT_point2hex(const EC_GROUP *group,
136 const EC_POINT *point, 136 const EC_POINT *point,
137 point_conversion_form_t form, 137 point_conversion_form_t form,
@@ -146,19 +146,19 @@ char *EC_POINT_point2hex(const EC_GROUP *group,
146 if (buf_len == 0) 146 if (buf_len == 0)
147 return NULL; 147 return NULL;
148 148
149 if ((buf = OPENSSL_malloc(buf_len)) == NULL) 149 if ((buf = malloc(buf_len)) == NULL)
150 return NULL; 150 return NULL;
151 151
152 if (!EC_POINT_point2oct(group, point, form, buf, buf_len, ctx)) 152 if (!EC_POINT_point2oct(group, point, form, buf, buf_len, ctx))
153 { 153 {
154 OPENSSL_free(buf); 154 free(buf);
155 return NULL; 155 return NULL;
156 } 156 }
157 157
158 ret = (char *)OPENSSL_malloc(buf_len*2+2); 158 ret = (char *)malloc(buf_len*2+2);
159 if (ret == NULL) 159 if (ret == NULL)
160 { 160 {
161 OPENSSL_free(buf); 161 free(buf);
162 return NULL; 162 return NULL;
163 } 163 }
164 p = ret; 164 p = ret;
@@ -171,7 +171,7 @@ char *EC_POINT_point2hex(const EC_GROUP *group,
171 } 171 }
172 *p='\0'; 172 *p='\0';
173 173
174 OPENSSL_free(buf); 174 free(buf);
175 175
176 return ret; 176 return ret;
177 } 177 }
diff --git a/src/lib/libcrypto/ec/eck_prn.c b/src/lib/libcrypto/ec/eck_prn.c
index 06de8f3959..4e8c748bbc 100644
--- a/src/lib/libcrypto/ec/eck_prn.c
+++ b/src/lib/libcrypto/ec/eck_prn.c
@@ -263,7 +263,7 @@ int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off)
263 seed_len = EC_GROUP_get_seed_len(x); 263 seed_len = EC_GROUP_get_seed_len(x);
264 264
265 buf_len += 10; 265 buf_len += 10;
266 if ((buffer = OPENSSL_malloc(buf_len)) == NULL) 266 if ((buffer = malloc(buf_len)) == NULL)
267 { 267 {
268 reason = ERR_R_MALLOC_FAILURE; 268 reason = ERR_R_MALLOC_FAILURE;
269 goto err; 269 goto err;
@@ -349,7 +349,7 @@ err:
349 if (ctx) 349 if (ctx)
350 BN_CTX_free(ctx); 350 BN_CTX_free(ctx);
351 if (buffer != NULL) 351 if (buffer != NULL)
352 OPENSSL_free(buffer); 352 free(buffer);
353 return(ret); 353 return(ret);
354 } 354 }
355 355
diff --git a/src/lib/libcrypto/ec/ecp_nistp224.c b/src/lib/libcrypto/ec/ecp_nistp224.c
index b5ff56c252..03f2d9c1d7 100644
--- a/src/lib/libcrypto/ec/ecp_nistp224.c
+++ b/src/lib/libcrypto/ec/ecp_nistp224.c
@@ -1148,7 +1148,7 @@ static void batch_mul(felem x_out, felem y_out, felem z_out,
1148static NISTP224_PRE_COMP *nistp224_pre_comp_new() 1148static NISTP224_PRE_COMP *nistp224_pre_comp_new()
1149 { 1149 {
1150 NISTP224_PRE_COMP *ret = NULL; 1150 NISTP224_PRE_COMP *ret = NULL;
1151 ret = (NISTP224_PRE_COMP *) OPENSSL_malloc(sizeof *ret); 1151 ret = (NISTP224_PRE_COMP *) malloc(sizeof *ret);
1152 if (!ret) 1152 if (!ret)
1153 { 1153 {
1154 ECerr(EC_F_NISTP224_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE); 1154 ECerr(EC_F_NISTP224_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE);
@@ -1181,7 +1181,7 @@ static void nistp224_pre_comp_free(void *pre_)
1181 if (i > 0) 1181 if (i > 0)
1182 return; 1182 return;
1183 1183
1184 OPENSSL_free(pre); 1184 free(pre);
1185 } 1185 }
1186 1186
1187static void nistp224_pre_comp_clear_free(void *pre_) 1187static void nistp224_pre_comp_clear_free(void *pre_)
@@ -1197,7 +1197,7 @@ static void nistp224_pre_comp_clear_free(void *pre_)
1197 return; 1197 return;
1198 1198
1199 OPENSSL_cleanse(pre, sizeof *pre); 1199 OPENSSL_cleanse(pre, sizeof *pre);
1200 OPENSSL_free(pre); 1200 free(pre);
1201 } 1201 }
1202 1202
1203/******************************************************************************/ 1203/******************************************************************************/
@@ -1382,10 +1382,10 @@ int ec_GFp_nistp224_points_mul(const EC_GROUP *group, EC_POINT *r,
1382 * converting those into affine form is time well spent */ 1382 * converting those into affine form is time well spent */
1383 mixed = 1; 1383 mixed = 1;
1384 } 1384 }
1385 secrets = OPENSSL_malloc(num_points * sizeof(felem_bytearray)); 1385 secrets = malloc(num_points * sizeof(felem_bytearray));
1386 pre_comp = OPENSSL_malloc(num_points * 17 * 3 * sizeof(felem)); 1386 pre_comp = malloc(num_points * 17 * 3 * sizeof(felem));
1387 if (mixed) 1387 if (mixed)
1388 tmp_felems = OPENSSL_malloc((num_points * 17 + 1) * sizeof(felem)); 1388 tmp_felems = malloc((num_points * 17 + 1) * sizeof(felem));
1389 if ((secrets == NULL) || (pre_comp == NULL) || (mixed && (tmp_felems == NULL))) 1389 if ((secrets == NULL) || (pre_comp == NULL) || (mixed && (tmp_felems == NULL)))
1390 { 1390 {
1391 ECerr(EC_F_EC_GFP_NISTP224_POINTS_MUL, ERR_R_MALLOC_FAILURE); 1391 ECerr(EC_F_EC_GFP_NISTP224_POINTS_MUL, ERR_R_MALLOC_FAILURE);
@@ -1506,11 +1506,11 @@ err:
1506 if (new_ctx != NULL) 1506 if (new_ctx != NULL)
1507 BN_CTX_free(new_ctx); 1507 BN_CTX_free(new_ctx);
1508 if (secrets != NULL) 1508 if (secrets != NULL)
1509 OPENSSL_free(secrets); 1509 free(secrets);
1510 if (pre_comp != NULL) 1510 if (pre_comp != NULL)
1511 OPENSSL_free(pre_comp); 1511 free(pre_comp);
1512 if (tmp_felems != NULL) 1512 if (tmp_felems != NULL)
1513 OPENSSL_free(tmp_felems); 1513 free(tmp_felems);
1514 return ret; 1514 return ret;
1515 } 1515 }
1516 1516
diff --git a/src/lib/libcrypto/ec/ecp_nistp256.c b/src/lib/libcrypto/ec/ecp_nistp256.c
index 4bc0f5dce0..947fb7eee0 100644
--- a/src/lib/libcrypto/ec/ecp_nistp256.c
+++ b/src/lib/libcrypto/ec/ecp_nistp256.c
@@ -1666,7 +1666,7 @@ const EC_METHOD *EC_GFp_nistp256_method(void)
1666static NISTP256_PRE_COMP *nistp256_pre_comp_new() 1666static NISTP256_PRE_COMP *nistp256_pre_comp_new()
1667 { 1667 {
1668 NISTP256_PRE_COMP *ret = NULL; 1668 NISTP256_PRE_COMP *ret = NULL;
1669 ret = (NISTP256_PRE_COMP *) OPENSSL_malloc(sizeof *ret); 1669 ret = (NISTP256_PRE_COMP *) malloc(sizeof *ret);
1670 if (!ret) 1670 if (!ret)
1671 { 1671 {
1672 ECerr(EC_F_NISTP256_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE); 1672 ECerr(EC_F_NISTP256_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE);
@@ -1699,7 +1699,7 @@ static void nistp256_pre_comp_free(void *pre_)
1699 if (i > 0) 1699 if (i > 0)
1700 return; 1700 return;
1701 1701
1702 OPENSSL_free(pre); 1702 free(pre);
1703 } 1703 }
1704 1704
1705static void nistp256_pre_comp_clear_free(void *pre_) 1705static void nistp256_pre_comp_clear_free(void *pre_)
@@ -1715,7 +1715,7 @@ static void nistp256_pre_comp_clear_free(void *pre_)
1715 return; 1715 return;
1716 1716
1717 OPENSSL_cleanse(pre, sizeof *pre); 1717 OPENSSL_cleanse(pre, sizeof *pre);
1718 OPENSSL_free(pre); 1718 free(pre);
1719 } 1719 }
1720 1720
1721/******************************************************************************/ 1721/******************************************************************************/
@@ -1901,10 +1901,10 @@ int ec_GFp_nistp256_points_mul(const EC_GROUP *group, EC_POINT *r,
1901 * converting those into affine form is time well spent */ 1901 * converting those into affine form is time well spent */
1902 mixed = 1; 1902 mixed = 1;
1903 } 1903 }
1904 secrets = OPENSSL_malloc(num_points * sizeof(felem_bytearray)); 1904 secrets = malloc(num_points * sizeof(felem_bytearray));
1905 pre_comp = OPENSSL_malloc(num_points * 17 * 3 * sizeof(smallfelem)); 1905 pre_comp = malloc(num_points * 17 * 3 * sizeof(smallfelem));
1906 if (mixed) 1906 if (mixed)
1907 tmp_smallfelems = OPENSSL_malloc((num_points * 17 + 1) * sizeof(smallfelem)); 1907 tmp_smallfelems = malloc((num_points * 17 + 1) * sizeof(smallfelem));
1908 if ((secrets == NULL) || (pre_comp == NULL) || (mixed && (tmp_smallfelems == NULL))) 1908 if ((secrets == NULL) || (pre_comp == NULL) || (mixed && (tmp_smallfelems == NULL)))
1909 { 1909 {
1910 ECerr(EC_F_EC_GFP_NISTP256_POINTS_MUL, ERR_R_MALLOC_FAILURE); 1910 ECerr(EC_F_EC_GFP_NISTP256_POINTS_MUL, ERR_R_MALLOC_FAILURE);
@@ -2026,11 +2026,11 @@ err:
2026 if (new_ctx != NULL) 2026 if (new_ctx != NULL)
2027 BN_CTX_free(new_ctx); 2027 BN_CTX_free(new_ctx);
2028 if (secrets != NULL) 2028 if (secrets != NULL)
2029 OPENSSL_free(secrets); 2029 free(secrets);
2030 if (pre_comp != NULL) 2030 if (pre_comp != NULL)
2031 OPENSSL_free(pre_comp); 2031 free(pre_comp);
2032 if (tmp_smallfelems != NULL) 2032 if (tmp_smallfelems != NULL)
2033 OPENSSL_free(tmp_smallfelems); 2033 free(tmp_smallfelems);
2034 return ret; 2034 return ret;
2035 } 2035 }
2036 2036
diff --git a/src/lib/libcrypto/ec/ecp_nistp521.c b/src/lib/libcrypto/ec/ecp_nistp521.c
index 178b655f7f..24eb032951 100644
--- a/src/lib/libcrypto/ec/ecp_nistp521.c
+++ b/src/lib/libcrypto/ec/ecp_nistp521.c
@@ -1533,7 +1533,7 @@ const EC_METHOD *EC_GFp_nistp521_method(void)
1533static NISTP521_PRE_COMP *nistp521_pre_comp_new() 1533static NISTP521_PRE_COMP *nistp521_pre_comp_new()
1534 { 1534 {
1535 NISTP521_PRE_COMP *ret = NULL; 1535 NISTP521_PRE_COMP *ret = NULL;
1536 ret = (NISTP521_PRE_COMP *)OPENSSL_malloc(sizeof(NISTP521_PRE_COMP)); 1536 ret = (NISTP521_PRE_COMP *)malloc(sizeof(NISTP521_PRE_COMP));
1537 if (!ret) 1537 if (!ret)
1538 { 1538 {
1539 ECerr(EC_F_NISTP521_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE); 1539 ECerr(EC_F_NISTP521_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE);
@@ -1566,7 +1566,7 @@ static void nistp521_pre_comp_free(void *pre_)
1566 if (i > 0) 1566 if (i > 0)
1567 return; 1567 return;
1568 1568
1569 OPENSSL_free(pre); 1569 free(pre);
1570 } 1570 }
1571 1571
1572static void nistp521_pre_comp_clear_free(void *pre_) 1572static void nistp521_pre_comp_clear_free(void *pre_)
@@ -1582,7 +1582,7 @@ static void nistp521_pre_comp_clear_free(void *pre_)
1582 return; 1582 return;
1583 1583
1584 OPENSSL_cleanse(pre, sizeof(*pre)); 1584 OPENSSL_cleanse(pre, sizeof(*pre));
1585 OPENSSL_free(pre); 1585 free(pre);
1586 } 1586 }
1587 1587
1588/******************************************************************************/ 1588/******************************************************************************/
@@ -1766,10 +1766,10 @@ int ec_GFp_nistp521_points_mul(const EC_GROUP *group, EC_POINT *r,
1766 * converting those into affine form is time well spent */ 1766 * converting those into affine form is time well spent */
1767 mixed = 1; 1767 mixed = 1;
1768 } 1768 }
1769 secrets = OPENSSL_malloc(num_points * sizeof(felem_bytearray)); 1769 secrets = malloc(num_points * sizeof(felem_bytearray));
1770 pre_comp = OPENSSL_malloc(num_points * 17 * 3 * sizeof(felem)); 1770 pre_comp = malloc(num_points * 17 * 3 * sizeof(felem));
1771 if (mixed) 1771 if (mixed)
1772 tmp_felems = OPENSSL_malloc((num_points * 17 + 1) * sizeof(felem)); 1772 tmp_felems = malloc((num_points * 17 + 1) * sizeof(felem));
1773 if ((secrets == NULL) || (pre_comp == NULL) || (mixed && (tmp_felems == NULL))) 1773 if ((secrets == NULL) || (pre_comp == NULL) || (mixed && (tmp_felems == NULL)))
1774 { 1774 {
1775 ECerr(EC_F_EC_GFP_NISTP521_POINTS_MUL, ERR_R_MALLOC_FAILURE); 1775 ECerr(EC_F_EC_GFP_NISTP521_POINTS_MUL, ERR_R_MALLOC_FAILURE);
@@ -1891,11 +1891,11 @@ err:
1891 if (new_ctx != NULL) 1891 if (new_ctx != NULL)
1892 BN_CTX_free(new_ctx); 1892 BN_CTX_free(new_ctx);
1893 if (secrets != NULL) 1893 if (secrets != NULL)
1894 OPENSSL_free(secrets); 1894 free(secrets);
1895 if (pre_comp != NULL) 1895 if (pre_comp != NULL)
1896 OPENSSL_free(pre_comp); 1896 free(pre_comp);
1897 if (tmp_felems != NULL) 1897 if (tmp_felems != NULL)
1898 OPENSSL_free(tmp_felems); 1898 free(tmp_felems);
1899 return ret; 1899 return ret;
1900 } 1900 }
1901 1901
diff --git a/src/lib/libcrypto/ec/ecp_smpl.c b/src/lib/libcrypto/ec/ecp_smpl.c
index bf0ad998dd..a146752817 100644
--- a/src/lib/libcrypto/ec/ecp_smpl.c
+++ b/src/lib/libcrypto/ec/ecp_smpl.c
@@ -1205,7 +1205,7 @@ int ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num, EC_POINT
1205 * We need twice that. */ 1205 * We need twice that. */
1206 pow2 <<= 1; 1206 pow2 <<= 1;
1207 1207
1208 heap = OPENSSL_malloc(pow2 * sizeof heap[0]); 1208 heap = malloc(pow2 * sizeof heap[0]);
1209 if (heap == NULL) goto err; 1209 if (heap == NULL) goto err;
1210 1210
1211 /* The array is used as a binary tree, exactly as in heapsort: 1211 /* The array is used as a binary tree, exactly as in heapsort:
@@ -1333,7 +1333,7 @@ int ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num, EC_POINT
1333 if (heap[i] != NULL) 1333 if (heap[i] != NULL)
1334 BN_clear_free(heap[i]); 1334 BN_clear_free(heap[i]);
1335 } 1335 }
1336 OPENSSL_free(heap); 1336 free(heap);
1337 } 1337 }
1338 return ret; 1338 return ret;
1339 } 1339 }
diff --git a/src/lib/libcrypto/ecdh/ech_lib.c b/src/lib/libcrypto/ecdh/ech_lib.c
index ddf226b166..51fb7d6afb 100644
--- a/src/lib/libcrypto/ecdh/ech_lib.c
+++ b/src/lib/libcrypto/ecdh/ech_lib.c
@@ -129,7 +129,7 @@ static ECDH_DATA *ECDH_DATA_new_method(ENGINE *engine)
129 { 129 {
130 ECDH_DATA *ret; 130 ECDH_DATA *ret;
131 131
132 ret=(ECDH_DATA *)OPENSSL_malloc(sizeof(ECDH_DATA)); 132 ret=(ECDH_DATA *)malloc(sizeof(ECDH_DATA));
133 if (ret == NULL) 133 if (ret == NULL)
134 { 134 {
135 ECDHerr(ECDH_F_ECDH_DATA_NEW_METHOD, ERR_R_MALLOC_FAILURE); 135 ECDHerr(ECDH_F_ECDH_DATA_NEW_METHOD, ERR_R_MALLOC_FAILURE);
@@ -150,7 +150,7 @@ static ECDH_DATA *ECDH_DATA_new_method(ENGINE *engine)
150 { 150 {
151 ECDHerr(ECDH_F_ECDH_DATA_NEW_METHOD, ERR_R_ENGINE_LIB); 151 ECDHerr(ECDH_F_ECDH_DATA_NEW_METHOD, ERR_R_ENGINE_LIB);
152 ENGINE_finish(ret->engine); 152 ENGINE_finish(ret->engine);
153 OPENSSL_free(ret); 153 free(ret);
154 return NULL; 154 return NULL;
155 } 155 }
156 } 156 }
@@ -162,7 +162,7 @@ static ECDH_DATA *ECDH_DATA_new_method(ENGINE *engine)
162 if ((ret->meth->init != NULL) && !ret->meth->init(ret)) 162 if ((ret->meth->init != NULL) && !ret->meth->init(ret))
163 { 163 {
164 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ECDH, ret, &ret->ex_data); 164 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ECDH, ret, &ret->ex_data);
165 OPENSSL_free(ret); 165 free(ret);
166 ret=NULL; 166 ret=NULL;
167 } 167 }
168#endif 168#endif
@@ -198,7 +198,7 @@ void ecdh_data_free(void *data)
198 198
199 OPENSSL_cleanse((void *)r, sizeof(ECDH_DATA)); 199 OPENSSL_cleanse((void *)r, sizeof(ECDH_DATA));
200 200
201 OPENSSL_free(r); 201 free(r);
202 } 202 }
203 203
204ECDH_DATA *ecdh_check(EC_KEY *key) 204ECDH_DATA *ecdh_check(EC_KEY *key)
diff --git a/src/lib/libcrypto/ecdh/ech_ossl.c b/src/lib/libcrypto/ecdh/ech_ossl.c
index 4a30628fbc..a63eb4922d 100644
--- a/src/lib/libcrypto/ecdh/ech_ossl.c
+++ b/src/lib/libcrypto/ecdh/ech_ossl.c
@@ -175,7 +175,7 @@ static int ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
175 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_INTERNAL_ERROR); 175 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_INTERNAL_ERROR);
176 goto err; 176 goto err;
177 } 177 }
178 if ((buf = OPENSSL_malloc(buflen)) == NULL) 178 if ((buf = malloc(buflen)) == NULL)
179 { 179 {
180 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_MALLOC_FAILURE); 180 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_MALLOC_FAILURE);
181 goto err; 181 goto err;
@@ -210,6 +210,6 @@ err:
210 if (tmp) EC_POINT_free(tmp); 210 if (tmp) EC_POINT_free(tmp);
211 if (ctx) BN_CTX_end(ctx); 211 if (ctx) BN_CTX_end(ctx);
212 if (ctx) BN_CTX_free(ctx); 212 if (ctx) BN_CTX_free(ctx);
213 if (buf) OPENSSL_free(buf); 213 if (buf) free(buf);
214 return(ret); 214 return(ret);
215 } 215 }
diff --git a/src/lib/libcrypto/ecdsa/ecs_lib.c b/src/lib/libcrypto/ecdsa/ecs_lib.c
index 7b53969ffd..81842a11a6 100644
--- a/src/lib/libcrypto/ecdsa/ecs_lib.c
+++ b/src/lib/libcrypto/ecdsa/ecs_lib.c
@@ -108,7 +108,7 @@ static ECDSA_DATA *ECDSA_DATA_new_method(ENGINE *engine)
108{ 108{
109 ECDSA_DATA *ret; 109 ECDSA_DATA *ret;
110 110
111 ret=(ECDSA_DATA *)OPENSSL_malloc(sizeof(ECDSA_DATA)); 111 ret=(ECDSA_DATA *)malloc(sizeof(ECDSA_DATA));
112 if (ret == NULL) 112 if (ret == NULL)
113 { 113 {
114 ECDSAerr(ECDSA_F_ECDSA_DATA_NEW_METHOD, ERR_R_MALLOC_FAILURE); 114 ECDSAerr(ECDSA_F_ECDSA_DATA_NEW_METHOD, ERR_R_MALLOC_FAILURE);
@@ -129,7 +129,7 @@ static ECDSA_DATA *ECDSA_DATA_new_method(ENGINE *engine)
129 { 129 {
130 ECDSAerr(ECDSA_F_ECDSA_DATA_NEW_METHOD, ERR_R_ENGINE_LIB); 130 ECDSAerr(ECDSA_F_ECDSA_DATA_NEW_METHOD, ERR_R_ENGINE_LIB);
131 ENGINE_finish(ret->engine); 131 ENGINE_finish(ret->engine);
132 OPENSSL_free(ret); 132 free(ret);
133 return NULL; 133 return NULL;
134 } 134 }
135 } 135 }
@@ -141,7 +141,7 @@ static ECDSA_DATA *ECDSA_DATA_new_method(ENGINE *engine)
141 if ((ret->meth->init != NULL) && !ret->meth->init(ret)) 141 if ((ret->meth->init != NULL) && !ret->meth->init(ret))
142 { 142 {
143 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ECDSA, ret, &ret->ex_data); 143 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ECDSA, ret, &ret->ex_data);
144 OPENSSL_free(ret); 144 free(ret);
145 ret=NULL; 145 ret=NULL;
146 } 146 }
147#endif 147#endif
@@ -176,7 +176,7 @@ static void ecdsa_data_free(void *data)
176 176
177 OPENSSL_cleanse((void *)r, sizeof(ECDSA_DATA)); 177 OPENSSL_cleanse((void *)r, sizeof(ECDSA_DATA));
178 178
179 OPENSSL_free(r); 179 free(r);
180} 180}
181 181
182ECDSA_DATA *ecdsa_check(EC_KEY *key) 182ECDSA_DATA *ecdsa_check(EC_KEY *key)
diff --git a/src/lib/libcrypto/engine/eng_dyn.c b/src/lib/libcrypto/engine/eng_dyn.c
index 807da7a5eb..7878bd802e 100644
--- a/src/lib/libcrypto/engine/eng_dyn.c
+++ b/src/lib/libcrypto/engine/eng_dyn.c
@@ -153,7 +153,7 @@ struct st_dynamic_data_ctx
153 * structure. */ 153 * structure. */
154static int dynamic_ex_data_idx = -1; 154static int dynamic_ex_data_idx = -1;
155 155
156static void int_free_str(char *s) { OPENSSL_free(s); } 156static void int_free_str(char *s) { free(s); }
157/* Because our ex_data element may or may not get allocated depending on whether 157/* Because our ex_data element may or may not get allocated depending on whether
158 * a "first-use" occurs before the ENGINE is freed, we have a memory leak 158 * a "first-use" occurs before the ENGINE is freed, we have a memory leak
159 * problem to solve. We can't declare a "new" handler for the ex_data as we 159 * problem to solve. We can't declare a "new" handler for the ex_data as we
@@ -170,12 +170,12 @@ static void dynamic_data_ctx_free_func(void *parent, void *ptr,
170 if(ctx->dynamic_dso) 170 if(ctx->dynamic_dso)
171 DSO_free(ctx->dynamic_dso); 171 DSO_free(ctx->dynamic_dso);
172 if(ctx->DYNAMIC_LIBNAME) 172 if(ctx->DYNAMIC_LIBNAME)
173 OPENSSL_free((void*)ctx->DYNAMIC_LIBNAME); 173 free((void*)ctx->DYNAMIC_LIBNAME);
174 if(ctx->engine_id) 174 if(ctx->engine_id)
175 OPENSSL_free((void*)ctx->engine_id); 175 free((void*)ctx->engine_id);
176 if(ctx->dirs) 176 if(ctx->dirs)
177 sk_OPENSSL_STRING_pop_free(ctx->dirs, int_free_str); 177 sk_OPENSSL_STRING_pop_free(ctx->dirs, int_free_str);
178 OPENSSL_free(ctx); 178 free(ctx);
179 } 179 }
180 } 180 }
181 181
@@ -186,7 +186,7 @@ static void dynamic_data_ctx_free_func(void *parent, void *ptr,
186static int dynamic_set_data_ctx(ENGINE *e, dynamic_data_ctx **ctx) 186static int dynamic_set_data_ctx(ENGINE *e, dynamic_data_ctx **ctx)
187 { 187 {
188 dynamic_data_ctx *c; 188 dynamic_data_ctx *c;
189 c = OPENSSL_malloc(sizeof(dynamic_data_ctx)); 189 c = malloc(sizeof(dynamic_data_ctx));
190 if(!c) 190 if(!c)
191 { 191 {
192 ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX,ERR_R_MALLOC_FAILURE); 192 ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX,ERR_R_MALLOC_FAILURE);
@@ -207,7 +207,7 @@ static int dynamic_set_data_ctx(ENGINE *e, dynamic_data_ctx **ctx)
207 if(!c->dirs) 207 if(!c->dirs)
208 { 208 {
209 ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX,ERR_R_MALLOC_FAILURE); 209 ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX,ERR_R_MALLOC_FAILURE);
210 OPENSSL_free(c); 210 free(c);
211 return 0; 211 return 0;
212 } 212 }
213 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); 213 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
@@ -223,7 +223,7 @@ static int dynamic_set_data_ctx(ENGINE *e, dynamic_data_ctx **ctx)
223 /* If we lost the race to set the context, c is non-NULL and *ctx is the 223 /* If we lost the race to set the context, c is non-NULL and *ctx is the
224 * context of the thread that won. */ 224 * context of the thread that won. */
225 if(c) 225 if(c)
226 OPENSSL_free(c); 226 free(c);
227 return 1; 227 return 1;
228 } 228 }
229 229
@@ -337,7 +337,7 @@ static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
337 if(p && (strlen((const char *)p) < 1)) 337 if(p && (strlen((const char *)p) < 1))
338 p = NULL; 338 p = NULL;
339 if(ctx->DYNAMIC_LIBNAME) 339 if(ctx->DYNAMIC_LIBNAME)
340 OPENSSL_free((void*)ctx->DYNAMIC_LIBNAME); 340 free((void*)ctx->DYNAMIC_LIBNAME);
341 if(p) 341 if(p)
342 ctx->DYNAMIC_LIBNAME = BUF_strdup(p); 342 ctx->DYNAMIC_LIBNAME = BUF_strdup(p);
343 else 343 else
@@ -351,7 +351,7 @@ static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
351 if(p && (strlen((const char *)p) < 1)) 351 if(p && (strlen((const char *)p) < 1))
352 p = NULL; 352 p = NULL;
353 if(ctx->engine_id) 353 if(ctx->engine_id)
354 OPENSSL_free((void*)ctx->engine_id); 354 free((void*)ctx->engine_id);
355 if(p) 355 if(p)
356 ctx->engine_id = BUF_strdup(p); 356 ctx->engine_id = BUF_strdup(p);
357 else 357 else
@@ -422,10 +422,10 @@ static int int_load(dynamic_data_ctx *ctx)
422 if(DSO_load(ctx->dynamic_dso, merge, NULL, 0)) 422 if(DSO_load(ctx->dynamic_dso, merge, NULL, 0))
423 { 423 {
424 /* Found what we're looking for */ 424 /* Found what we're looking for */
425 OPENSSL_free(merge); 425 free(merge);
426 return 1; 426 return 1;
427 } 427 }
428 OPENSSL_free(merge); 428 free(merge);
429 } 429 }
430 return 0; 430 return 0;
431 } 431 }
diff --git a/src/lib/libcrypto/engine/eng_lib.c b/src/lib/libcrypto/engine/eng_lib.c
index 18a6664645..126bc02296 100644
--- a/src/lib/libcrypto/engine/eng_lib.c
+++ b/src/lib/libcrypto/engine/eng_lib.c
@@ -65,7 +65,7 @@ ENGINE *ENGINE_new(void)
65 { 65 {
66 ENGINE *ret; 66 ENGINE *ret;
67 67
68 ret = (ENGINE *)OPENSSL_malloc(sizeof(ENGINE)); 68 ret = (ENGINE *)malloc(sizeof(ENGINE));
69 if(ret == NULL) 69 if(ret == NULL)
70 { 70 {
71 ENGINEerr(ENGINE_F_ENGINE_NEW, ERR_R_MALLOC_FAILURE); 71 ENGINEerr(ENGINE_F_ENGINE_NEW, ERR_R_MALLOC_FAILURE);
@@ -133,7 +133,7 @@ int engine_free_util(ENGINE *e, int locked)
133 if(e->destroy) 133 if(e->destroy)
134 e->destroy(e); 134 e->destroy(e);
135 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ENGINE, e, &e->ex_data); 135 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ENGINE, e, &e->ex_data);
136 OPENSSL_free(e); 136 free(e);
137 return 1; 137 return 1;
138 } 138 }
139 139
@@ -158,7 +158,7 @@ static int int_cleanup_check(int create)
158 } 158 }
159static ENGINE_CLEANUP_ITEM *int_cleanup_item(ENGINE_CLEANUP_CB *cb) 159static ENGINE_CLEANUP_ITEM *int_cleanup_item(ENGINE_CLEANUP_CB *cb)
160 { 160 {
161 ENGINE_CLEANUP_ITEM *item = OPENSSL_malloc(sizeof( 161 ENGINE_CLEANUP_ITEM *item = malloc(sizeof(
162 ENGINE_CLEANUP_ITEM)); 162 ENGINE_CLEANUP_ITEM));
163 if(!item) return NULL; 163 if(!item) return NULL;
164 item->cb = cb; 164 item->cb = cb;
@@ -184,7 +184,7 @@ void engine_cleanup_add_last(ENGINE_CLEANUP_CB *cb)
184static void engine_cleanup_cb_free(ENGINE_CLEANUP_ITEM *item) 184static void engine_cleanup_cb_free(ENGINE_CLEANUP_ITEM *item)
185 { 185 {
186 (*(item->cb))(); 186 (*(item->cb))();
187 OPENSSL_free(item); 187 free(item);
188 } 188 }
189void ENGINE_cleanup(void) 189void ENGINE_cleanup(void)
190 { 190 {
diff --git a/src/lib/libcrypto/engine/eng_rsax.c b/src/lib/libcrypto/engine/eng_rsax.c
index 96e63477ee..fa9159499d 100644
--- a/src/lib/libcrypto/engine/eng_rsax.c
+++ b/src/lib/libcrypto/engine/eng_rsax.c
@@ -282,7 +282,7 @@ static E_RSAX_MOD_CTX *e_rsax_get_ctx(RSA *rsa, int idx, BIGNUM* m)
282 282
283 hptr = RSA_get_ex_data(rsa, rsax_ex_data_idx); 283 hptr = RSA_get_ex_data(rsa, rsax_ex_data_idx);
284 if (!hptr) { 284 if (!hptr) {
285 hptr = OPENSSL_malloc(3*sizeof(E_RSAX_MOD_CTX)); 285 hptr = malloc(3*sizeof(E_RSAX_MOD_CTX));
286 if (!hptr) return NULL; 286 if (!hptr) return NULL;
287 hptr[2].type = hptr[1].type= hptr[0].type = 0; 287 hptr[2].type = hptr[1].type= hptr[0].type = 0;
288 RSA_set_ex_data(rsa, rsax_ex_data_idx, hptr); 288 RSA_set_ex_data(rsa, rsax_ex_data_idx, hptr);
@@ -307,7 +307,7 @@ static int e_rsax_rsa_finish(RSA *rsa)
307 E_RSAX_MOD_CTX *hptr = RSA_get_ex_data(rsa, rsax_ex_data_idx); 307 E_RSAX_MOD_CTX *hptr = RSA_get_ex_data(rsa, rsax_ex_data_idx);
308 if(hptr) 308 if(hptr)
309 { 309 {
310 OPENSSL_free(hptr); 310 free(hptr);
311 RSA_set_ex_data(rsa, rsax_ex_data_idx, NULL); 311 RSA_set_ex_data(rsa, rsax_ex_data_idx, NULL);
312 } 312 }
313 if (rsa->_method_mod_n) 313 if (rsa->_method_mod_n)
diff --git a/src/lib/libcrypto/engine/eng_table.c b/src/lib/libcrypto/engine/eng_table.c
index 4fde948185..b7e77f7625 100644
--- a/src/lib/libcrypto/engine/eng_table.c
+++ b/src/lib/libcrypto/engine/eng_table.c
@@ -146,14 +146,14 @@ int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
146 fnd = lh_ENGINE_PILE_retrieve(&(*table)->piles, &tmplate); 146 fnd = lh_ENGINE_PILE_retrieve(&(*table)->piles, &tmplate);
147 if(!fnd) 147 if(!fnd)
148 { 148 {
149 fnd = OPENSSL_malloc(sizeof(ENGINE_PILE)); 149 fnd = malloc(sizeof(ENGINE_PILE));
150 if(!fnd) goto end; 150 if(!fnd) goto end;
151 fnd->uptodate = 1; 151 fnd->uptodate = 1;
152 fnd->nid = *nids; 152 fnd->nid = *nids;
153 fnd->sk = sk_ENGINE_new_null(); 153 fnd->sk = sk_ENGINE_new_null();
154 if(!fnd->sk) 154 if(!fnd->sk)
155 { 155 {
156 OPENSSL_free(fnd); 156 free(fnd);
157 goto end; 157 goto end;
158 } 158 }
159 fnd->funct = NULL; 159 fnd->funct = NULL;
@@ -218,7 +218,7 @@ static void int_cleanup_cb_doall(ENGINE_PILE *p)
218 sk_ENGINE_free(p->sk); 218 sk_ENGINE_free(p->sk);
219 if(p->funct) 219 if(p->funct)
220 engine_unlocked_finish(p->funct, 0); 220 engine_unlocked_finish(p->funct, 0);
221 OPENSSL_free(p); 221 free(p);
222 } 222 }
223static IMPLEMENT_LHASH_DOALL_FN(int_cleanup_cb, ENGINE_PILE) 223static IMPLEMENT_LHASH_DOALL_FN(int_cleanup_cb, ENGINE_PILE)
224 224
diff --git a/src/lib/libcrypto/err/err.c b/src/lib/libcrypto/err/err.c
index f6f9d2c080..93ed1da943 100644
--- a/src/lib/libcrypto/err/err.c
+++ b/src/lib/libcrypto/err/err.c
@@ -572,7 +572,7 @@ static ERR_STRING_DATA SYS_str_reasons[NUM_SYS_STR_REASONS + 1];
572 572
573static void build_SYS_str_reasons(void) 573static void build_SYS_str_reasons(void)
574 { 574 {
575 /* OPENSSL_malloc cannot be used here, use static storage instead */ 575 /* malloc cannot be used here, use static storage instead */
576 static char strerror_tab[NUM_SYS_STR_REASONS][LEN_SYS_STR_REASON]; 576 static char strerror_tab[NUM_SYS_STR_REASONS][LEN_SYS_STR_REASON];
577 int i; 577 int i;
578 static int init = 1; 578 static int init = 1;
@@ -625,7 +625,7 @@ static void build_SYS_str_reasons(void)
625 if (((p)->err_data[i] != NULL) && \ 625 if (((p)->err_data[i] != NULL) && \
626 (p)->err_data_flags[i] & ERR_TXT_MALLOCED) \ 626 (p)->err_data_flags[i] & ERR_TXT_MALLOCED) \
627 { \ 627 { \
628 OPENSSL_free((p)->err_data[i]); \ 628 free((p)->err_data[i]); \
629 (p)->err_data[i]=NULL; \ 629 (p)->err_data[i]=NULL; \
630 } \ 630 } \
631 (p)->err_data_flags[i]=0; \ 631 (p)->err_data_flags[i]=0; \
@@ -651,7 +651,7 @@ static void ERR_STATE_free(ERR_STATE *s)
651 { 651 {
652 err_clear_data(s,i); 652 err_clear_data(s,i);
653 } 653 }
654 OPENSSL_free(s); 654 free(s);
655 } 655 }
656 656
657void ERR_load_ERR_strings(void) 657void ERR_load_ERR_strings(void)
@@ -1015,7 +1015,7 @@ ERR_STATE *ERR_get_state(void)
1015 /* ret == the error state, if NULL, make a new one */ 1015 /* ret == the error state, if NULL, make a new one */
1016 if (ret == NULL) 1016 if (ret == NULL)
1017 { 1017 {
1018 ret=(ERR_STATE *)OPENSSL_malloc(sizeof(ERR_STATE)); 1018 ret=(ERR_STATE *)malloc(sizeof(ERR_STATE));
1019 if (ret == NULL) return(&fallback); 1019 if (ret == NULL) return(&fallback);
1020 CRYPTO_THREADID_cpy(&ret->tid, &tid); 1020 CRYPTO_THREADID_cpy(&ret->tid, &tid);
1021 ret->top=0; 1021 ret->top=0;
@@ -1076,7 +1076,7 @@ void ERR_add_error_vdata(int num, va_list args)
1076 char *str,*p,*a; 1076 char *str,*p,*a;
1077 1077
1078 s=80; 1078 s=80;
1079 str=OPENSSL_malloc(s+1); 1079 str=malloc(s+1);
1080 if (str == NULL) return; 1080 if (str == NULL) return;
1081 str[0]='\0'; 1081 str[0]='\0';
1082 1082
@@ -1091,10 +1091,10 @@ void ERR_add_error_vdata(int num, va_list args)
1091 if (n > s) 1091 if (n > s)
1092 { 1092 {
1093 s=n+20; 1093 s=n+20;
1094 p=OPENSSL_realloc(str,s+1); 1094 p=realloc(str,s+1);
1095 if (p == NULL) 1095 if (p == NULL)
1096 { 1096 {
1097 OPENSSL_free(str); 1097 free(str);
1098 return; 1098 return;
1099 } 1099 }
1100 else 1100 else
diff --git a/src/lib/libcrypto/evp/bio_b64.c b/src/lib/libcrypto/evp/bio_b64.c
index ac6d441aad..27fc587ca8 100644
--- a/src/lib/libcrypto/evp/bio_b64.c
+++ b/src/lib/libcrypto/evp/bio_b64.c
@@ -113,7 +113,7 @@ static int b64_new(BIO *bi)
113 { 113 {
114 BIO_B64_CTX *ctx; 114 BIO_B64_CTX *ctx;
115 115
116 ctx=(BIO_B64_CTX *)OPENSSL_malloc(sizeof(BIO_B64_CTX)); 116 ctx=(BIO_B64_CTX *)malloc(sizeof(BIO_B64_CTX));
117 if (ctx == NULL) return(0); 117 if (ctx == NULL) return(0);
118 118
119 ctx->buf_len=0; 119 ctx->buf_len=0;
@@ -134,7 +134,7 @@ static int b64_new(BIO *bi)
134static int b64_free(BIO *a) 134static int b64_free(BIO *a)
135 { 135 {
136 if (a == NULL) return(0); 136 if (a == NULL) return(0);
137 OPENSSL_free(a->ptr); 137 free(a->ptr);
138 a->ptr=NULL; 138 a->ptr=NULL;
139 a->init=0; 139 a->init=0;
140 a->flags=0; 140 a->flags=0;
diff --git a/src/lib/libcrypto/evp/bio_enc.c b/src/lib/libcrypto/evp/bio_enc.c
index b6efb5fbc4..8fe9a45e48 100644
--- a/src/lib/libcrypto/evp/bio_enc.c
+++ b/src/lib/libcrypto/evp/bio_enc.c
@@ -109,7 +109,7 @@ static int enc_new(BIO *bi)
109 { 109 {
110 BIO_ENC_CTX *ctx; 110 BIO_ENC_CTX *ctx;
111 111
112 ctx=(BIO_ENC_CTX *)OPENSSL_malloc(sizeof(BIO_ENC_CTX)); 112 ctx=(BIO_ENC_CTX *)malloc(sizeof(BIO_ENC_CTX));
113 if (ctx == NULL) return(0); 113 if (ctx == NULL) return(0);
114 EVP_CIPHER_CTX_init(&ctx->cipher); 114 EVP_CIPHER_CTX_init(&ctx->cipher);
115 115
@@ -133,7 +133,7 @@ static int enc_free(BIO *a)
133 b=(BIO_ENC_CTX *)a->ptr; 133 b=(BIO_ENC_CTX *)a->ptr;
134 EVP_CIPHER_CTX_cleanup(&(b->cipher)); 134 EVP_CIPHER_CTX_cleanup(&(b->cipher));
135 OPENSSL_cleanse(a->ptr,sizeof(BIO_ENC_CTX)); 135 OPENSSL_cleanse(a->ptr,sizeof(BIO_ENC_CTX));
136 OPENSSL_free(a->ptr); 136 free(a->ptr);
137 a->ptr=NULL; 137 a->ptr=NULL;
138 a->init=0; 138 a->init=0;
139 a->flags=0; 139 a->flags=0;
diff --git a/src/lib/libcrypto/evp/bio_ok.c b/src/lib/libcrypto/evp/bio_ok.c
index e64335353f..fdb742f554 100644
--- a/src/lib/libcrypto/evp/bio_ok.c
+++ b/src/lib/libcrypto/evp/bio_ok.c
@@ -178,7 +178,7 @@ static int ok_new(BIO *bi)
178 { 178 {
179 BIO_OK_CTX *ctx; 179 BIO_OK_CTX *ctx;
180 180
181 ctx=(BIO_OK_CTX *)OPENSSL_malloc(sizeof(BIO_OK_CTX)); 181 ctx=(BIO_OK_CTX *)malloc(sizeof(BIO_OK_CTX));
182 if (ctx == NULL) return(0); 182 if (ctx == NULL) return(0);
183 183
184 ctx->buf_len=0; 184 ctx->buf_len=0;
@@ -203,7 +203,7 @@ static int ok_free(BIO *a)
203 if (a == NULL) return(0); 203 if (a == NULL) return(0);
204 EVP_MD_CTX_cleanup(&((BIO_OK_CTX *)a->ptr)->md); 204 EVP_MD_CTX_cleanup(&((BIO_OK_CTX *)a->ptr)->md);
205 OPENSSL_cleanse(a->ptr,sizeof(BIO_OK_CTX)); 205 OPENSSL_cleanse(a->ptr,sizeof(BIO_OK_CTX));
206 OPENSSL_free(a->ptr); 206 free(a->ptr);
207 a->ptr=NULL; 207 a->ptr=NULL;
208 a->init=0; 208 a->init=0;
209 a->flags=0; 209 a->flags=0;
diff --git a/src/lib/libcrypto/evp/digest.c b/src/lib/libcrypto/evp/digest.c
index 782d3199a5..2fae68ef5e 100644
--- a/src/lib/libcrypto/evp/digest.c
+++ b/src/lib/libcrypto/evp/digest.c
@@ -124,7 +124,7 @@ void EVP_MD_CTX_init(EVP_MD_CTX *ctx)
124 124
125EVP_MD_CTX *EVP_MD_CTX_create(void) 125EVP_MD_CTX *EVP_MD_CTX_create(void)
126 { 126 {
127 EVP_MD_CTX *ctx=OPENSSL_malloc(sizeof *ctx); 127 EVP_MD_CTX *ctx=malloc(sizeof *ctx);
128 128
129 if (ctx) 129 if (ctx)
130 EVP_MD_CTX_init(ctx); 130 EVP_MD_CTX_init(ctx);
@@ -198,12 +198,12 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
198 if (ctx->digest != type) 198 if (ctx->digest != type)
199 { 199 {
200 if (ctx->digest && ctx->digest->ctx_size) 200 if (ctx->digest && ctx->digest->ctx_size)
201 OPENSSL_free(ctx->md_data); 201 free(ctx->md_data);
202 ctx->digest=type; 202 ctx->digest=type;
203 if (!(ctx->flags & EVP_MD_CTX_FLAG_NO_INIT) && type->ctx_size) 203 if (!(ctx->flags & EVP_MD_CTX_FLAG_NO_INIT) && type->ctx_size)
204 { 204 {
205 ctx->update = type->update; 205 ctx->update = type->update;
206 ctx->md_data=OPENSSL_malloc(type->ctx_size); 206 ctx->md_data=malloc(type->ctx_size);
207 if (ctx->md_data == NULL) 207 if (ctx->md_data == NULL)
208 { 208 {
209 EVPerr(EVP_F_EVP_DIGESTINIT_EX, 209 EVPerr(EVP_F_EVP_DIGESTINIT_EX,
@@ -298,7 +298,7 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
298 out->md_data = tmp_buf; 298 out->md_data = tmp_buf;
299 else 299 else
300 { 300 {
301 out->md_data=OPENSSL_malloc(out->digest->ctx_size); 301 out->md_data=malloc(out->digest->ctx_size);
302 if (!out->md_data) 302 if (!out->md_data)
303 { 303 {
304 EVPerr(EVP_F_EVP_MD_CTX_COPY_EX,ERR_R_MALLOC_FAILURE); 304 EVPerr(EVP_F_EVP_MD_CTX_COPY_EX,ERR_R_MALLOC_FAILURE);
@@ -347,7 +347,7 @@ void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx)
347 if (ctx) 347 if (ctx)
348 { 348 {
349 EVP_MD_CTX_cleanup(ctx); 349 EVP_MD_CTX_cleanup(ctx);
350 OPENSSL_free(ctx); 350 free(ctx);
351 } 351 }
352 } 352 }
353 353
@@ -364,7 +364,7 @@ int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
364 && !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE)) 364 && !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE))
365 { 365 {
366 OPENSSL_cleanse(ctx->md_data,ctx->digest->ctx_size); 366 OPENSSL_cleanse(ctx->md_data,ctx->digest->ctx_size);
367 OPENSSL_free(ctx->md_data); 367 free(ctx->md_data);
368 } 368 }
369 if (ctx->pctx) 369 if (ctx->pctx)
370 EVP_PKEY_CTX_free(ctx->pctx); 370 EVP_PKEY_CTX_free(ctx->pctx);
diff --git a/src/lib/libcrypto/evp/e_aes.c b/src/lib/libcrypto/evp/e_aes.c
index c7eaafe89b..d6f0124a94 100644
--- a/src/lib/libcrypto/evp/e_aes.c
+++ b/src/lib/libcrypto/evp/e_aes.c
@@ -679,7 +679,7 @@ static int aes_gcm_cleanup(EVP_CIPHER_CTX *c)
679 EVP_AES_GCM_CTX *gctx = c->cipher_data; 679 EVP_AES_GCM_CTX *gctx = c->cipher_data;
680 OPENSSL_cleanse(&gctx->gcm, sizeof(gctx->gcm)); 680 OPENSSL_cleanse(&gctx->gcm, sizeof(gctx->gcm));
681 if (gctx->iv != c->iv) 681 if (gctx->iv != c->iv)
682 OPENSSL_free(gctx->iv); 682 free(gctx->iv);
683 return 1; 683 return 1;
684 } 684 }
685 685
@@ -724,8 +724,8 @@ static int aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
724 if ((arg > EVP_MAX_IV_LENGTH) && (arg > gctx->ivlen)) 724 if ((arg > EVP_MAX_IV_LENGTH) && (arg > gctx->ivlen))
725 { 725 {
726 if (gctx->iv != c->iv) 726 if (gctx->iv != c->iv)
727 OPENSSL_free(gctx->iv); 727 free(gctx->iv);
728 gctx->iv = OPENSSL_malloc(arg); 728 gctx->iv = malloc(arg);
729 if (!gctx->iv) 729 if (!gctx->iv)
730 return 0; 730 return 0;
731 } 731 }
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c
index 50403a7578..e8ca502633 100644
--- a/src/lib/libcrypto/evp/evp_enc.c
+++ b/src/lib/libcrypto/evp/evp_enc.c
@@ -78,7 +78,7 @@ void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx)
78 78
79EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void) 79EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void)
80 { 80 {
81 EVP_CIPHER_CTX *ctx=OPENSSL_malloc(sizeof *ctx); 81 EVP_CIPHER_CTX *ctx=malloc(sizeof *ctx);
82 if (ctx) 82 if (ctx)
83 EVP_CIPHER_CTX_init(ctx); 83 EVP_CIPHER_CTX_init(ctx);
84 return ctx; 84 return ctx;
@@ -164,7 +164,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *imp
164 ctx->cipher=cipher; 164 ctx->cipher=cipher;
165 if (ctx->cipher->ctx_size) 165 if (ctx->cipher->ctx_size)
166 { 166 {
167 ctx->cipher_data=OPENSSL_malloc(ctx->cipher->ctx_size); 167 ctx->cipher_data=malloc(ctx->cipher->ctx_size);
168 if (!ctx->cipher_data) 168 if (!ctx->cipher_data)
169 { 169 {
170 EVPerr(EVP_F_EVP_CIPHERINIT_EX, ERR_R_MALLOC_FAILURE); 170 EVPerr(EVP_F_EVP_CIPHERINIT_EX, ERR_R_MALLOC_FAILURE);
@@ -546,7 +546,7 @@ void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx)
546 if (ctx) 546 if (ctx)
547 { 547 {
548 EVP_CIPHER_CTX_cleanup(ctx); 548 EVP_CIPHER_CTX_cleanup(ctx);
549 OPENSSL_free(ctx); 549 free(ctx);
550 } 550 }
551 } 551 }
552 552
@@ -561,7 +561,7 @@ int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c)
561 OPENSSL_cleanse(c->cipher_data, c->cipher->ctx_size); 561 OPENSSL_cleanse(c->cipher_data, c->cipher->ctx_size);
562 } 562 }
563 if (c->cipher_data) 563 if (c->cipher_data)
564 OPENSSL_free(c->cipher_data); 564 free(c->cipher_data);
565#ifndef OPENSSL_NO_ENGINE 565#ifndef OPENSSL_NO_ENGINE
566 if (c->engine) 566 if (c->engine)
567 /* The EVP_CIPHER we used belongs to an ENGINE, release the 567 /* The EVP_CIPHER we used belongs to an ENGINE, release the
@@ -644,7 +644,7 @@ int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in)
644 644
645 if (in->cipher_data && in->cipher->ctx_size) 645 if (in->cipher_data && in->cipher->ctx_size)
646 { 646 {
647 out->cipher_data=OPENSSL_malloc(in->cipher->ctx_size); 647 out->cipher_data=malloc(in->cipher->ctx_size);
648 if (!out->cipher_data) 648 if (!out->cipher_data)
649 { 649 {
650 EVPerr(EVP_F_EVP_CIPHER_CTX_COPY,ERR_R_MALLOC_FAILURE); 650 EVPerr(EVP_F_EVP_CIPHER_CTX_COPY,ERR_R_MALLOC_FAILURE);
diff --git a/src/lib/libcrypto/evp/evp_pbe.c b/src/lib/libcrypto/evp/evp_pbe.c
index f8c32d825e..c808b96fef 100644
--- a/src/lib/libcrypto/evp/evp_pbe.c
+++ b/src/lib/libcrypto/evp/evp_pbe.c
@@ -238,7 +238,7 @@ int EVP_PBE_alg_add_type(int pbe_type, int pbe_nid, int cipher_nid, int md_nid,
238 EVP_PBE_CTL *pbe_tmp; 238 EVP_PBE_CTL *pbe_tmp;
239 if (!pbe_algs) 239 if (!pbe_algs)
240 pbe_algs = sk_EVP_PBE_CTL_new(pbe_cmp); 240 pbe_algs = sk_EVP_PBE_CTL_new(pbe_cmp);
241 if (!(pbe_tmp = (EVP_PBE_CTL*) OPENSSL_malloc (sizeof(EVP_PBE_CTL)))) 241 if (!(pbe_tmp = (EVP_PBE_CTL*) malloc (sizeof(EVP_PBE_CTL))))
242 { 242 {
243 EVPerr(EVP_F_EVP_PBE_ALG_ADD_TYPE,ERR_R_MALLOC_FAILURE); 243 EVPerr(EVP_F_EVP_PBE_ALG_ADD_TYPE,ERR_R_MALLOC_FAILURE);
244 return 0; 244 return 0;
@@ -306,7 +306,7 @@ int EVP_PBE_find(int type, int pbe_nid,
306 306
307static void free_evp_pbe_ctl(EVP_PBE_CTL *pbe) 307static void free_evp_pbe_ctl(EVP_PBE_CTL *pbe)
308 { 308 {
309 OPENSSL_freeFunc(pbe); 309 free(pbe);
310 } 310 }
311 311
312void EVP_PBE_cleanup(void) 312void EVP_PBE_cleanup(void)
diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c
index e26ccd0d08..7a9da3487a 100644
--- a/src/lib/libcrypto/evp/p_lib.c
+++ b/src/lib/libcrypto/evp/p_lib.c
@@ -183,7 +183,7 @@ EVP_PKEY *EVP_PKEY_new(void)
183 { 183 {
184 EVP_PKEY *ret; 184 EVP_PKEY *ret;
185 185
186 ret=(EVP_PKEY *)OPENSSL_malloc(sizeof(EVP_PKEY)); 186 ret=(EVP_PKEY *)malloc(sizeof(EVP_PKEY));
187 if (ret == NULL) 187 if (ret == NULL)
188 { 188 {
189 EVPerr(EVP_F_EVP_PKEY_NEW,ERR_R_MALLOC_FAILURE); 189 EVPerr(EVP_F_EVP_PKEY_NEW,ERR_R_MALLOC_FAILURE);
@@ -405,7 +405,7 @@ void EVP_PKEY_free(EVP_PKEY *x)
405 EVP_PKEY_free_it(x); 405 EVP_PKEY_free_it(x);
406 if (x->attributes) 406 if (x->attributes)
407 sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free); 407 sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free);
408 OPENSSL_free(x); 408 free(x);
409 } 409 }
410 410
411static void EVP_PKEY_free_it(EVP_PKEY *x) 411static void EVP_PKEY_free_it(EVP_PKEY *x)
diff --git a/src/lib/libcrypto/evp/p_open.c b/src/lib/libcrypto/evp/p_open.c
index c748fbea87..2a5ab2b6cc 100644
--- a/src/lib/libcrypto/evp/p_open.c
+++ b/src/lib/libcrypto/evp/p_open.c
@@ -87,7 +87,7 @@ int EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
87 } 87 }
88 88
89 size=RSA_size(priv->pkey.rsa); 89 size=RSA_size(priv->pkey.rsa);
90 key=(unsigned char *)OPENSSL_malloc(size+2); 90 key=(unsigned char *)malloc(size+2);
91 if (key == NULL) 91 if (key == NULL)
92 { 92 {
93 /* ERROR */ 93 /* ERROR */
@@ -106,7 +106,7 @@ int EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
106 ret=1; 106 ret=1;
107err: 107err:
108 if (key != NULL) OPENSSL_cleanse(key,size); 108 if (key != NULL) OPENSSL_cleanse(key,size);
109 OPENSSL_free(key); 109 free(key);
110 return(ret); 110 return(ret);
111 } 111 }
112 112
diff --git a/src/lib/libcrypto/evp/pmeth_lib.c b/src/lib/libcrypto/evp/pmeth_lib.c
index acfa7b6f87..a9fb15fdfe 100644
--- a/src/lib/libcrypto/evp/pmeth_lib.c
+++ b/src/lib/libcrypto/evp/pmeth_lib.c
@@ -165,7 +165,7 @@ static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
165 return NULL; 165 return NULL;
166 } 166 }
167 167
168 ret = OPENSSL_malloc(sizeof(EVP_PKEY_CTX)); 168 ret = malloc(sizeof(EVP_PKEY_CTX));
169 if (!ret) 169 if (!ret)
170 { 170 {
171#ifndef OPENSSL_NO_ENGINE 171#ifndef OPENSSL_NO_ENGINE
@@ -200,7 +200,7 @@ static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
200EVP_PKEY_METHOD* EVP_PKEY_meth_new(int id, int flags) 200EVP_PKEY_METHOD* EVP_PKEY_meth_new(int id, int flags)
201 { 201 {
202 EVP_PKEY_METHOD *pmeth; 202 EVP_PKEY_METHOD *pmeth;
203 pmeth = OPENSSL_malloc(sizeof(EVP_PKEY_METHOD)); 203 pmeth = malloc(sizeof(EVP_PKEY_METHOD));
204 if (!pmeth) 204 if (!pmeth)
205 return NULL; 205 return NULL;
206 206
@@ -291,7 +291,7 @@ void EVP_PKEY_meth_copy(EVP_PKEY_METHOD *dst, const EVP_PKEY_METHOD *src)
291void EVP_PKEY_meth_free(EVP_PKEY_METHOD *pmeth) 291void EVP_PKEY_meth_free(EVP_PKEY_METHOD *pmeth)
292 { 292 {
293 if (pmeth && (pmeth->flags & EVP_PKEY_FLAG_DYNAMIC)) 293 if (pmeth && (pmeth->flags & EVP_PKEY_FLAG_DYNAMIC))
294 OPENSSL_free(pmeth); 294 free(pmeth);
295 } 295 }
296 296
297EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e) 297EVP_PKEY_CTX *EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e)
@@ -317,7 +317,7 @@ EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *pctx)
317 return 0; 317 return 0;
318 } 318 }
319#endif 319#endif
320 rctx = OPENSSL_malloc(sizeof(EVP_PKEY_CTX)); 320 rctx = malloc(sizeof(EVP_PKEY_CTX));
321 if (!rctx) 321 if (!rctx)
322 return NULL; 322 return NULL;
323 323
@@ -378,7 +378,7 @@ void EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx)
378 * functional reference we held for this reason. */ 378 * functional reference we held for this reason. */
379 ENGINE_finish(ctx->engine); 379 ENGINE_finish(ctx->engine);
380#endif 380#endif
381 OPENSSL_free(ctx); 381 free(ctx);
382 } 382 }
383 383
384int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype, 384int EVP_PKEY_CTX_ctrl(EVP_PKEY_CTX *ctx, int keytype, int optype,
diff --git a/src/lib/libcrypto/ex_data.c b/src/lib/libcrypto/ex_data.c
index 44bad59527..4c09f9ee02 100644
--- a/src/lib/libcrypto/ex_data.c
+++ b/src/lib/libcrypto/ex_data.c
@@ -290,7 +290,7 @@ ex_data_check(void)
290static void 290static void
291def_cleanup_util_cb(CRYPTO_EX_DATA_FUNCS *funcs) 291def_cleanup_util_cb(CRYPTO_EX_DATA_FUNCS *funcs)
292{ 292{
293 OPENSSL_free(funcs); 293 free(funcs);
294} 294}
295 295
296/* This callback is used in lh_doall to destroy all EX_CLASS_ITEM values from 296/* This callback is used in lh_doall to destroy all EX_CLASS_ITEM values from
@@ -301,7 +301,7 @@ def_cleanup_cb(void *a_void)
301{ 301{
302 EX_CLASS_ITEM *item = (EX_CLASS_ITEM *)a_void; 302 EX_CLASS_ITEM *item = (EX_CLASS_ITEM *)a_void;
303 sk_CRYPTO_EX_DATA_FUNCS_pop_free(item->meth, def_cleanup_util_cb); 303 sk_CRYPTO_EX_DATA_FUNCS_pop_free(item->meth, def_cleanup_util_cb);
304 OPENSSL_free(item); 304 free(item);
305} 305}
306 306
307/* Return the EX_CLASS_ITEM from the "ex_data" hash table that corresponds to a 307/* Return the EX_CLASS_ITEM from the "ex_data" hash table that corresponds to a
@@ -315,13 +315,13 @@ static EX_CLASS_ITEM
315 CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA); 315 CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA);
316 p = lh_EX_CLASS_ITEM_retrieve(ex_data, &d); 316 p = lh_EX_CLASS_ITEM_retrieve(ex_data, &d);
317 if (!p) { 317 if (!p) {
318 gen = OPENSSL_malloc(sizeof(EX_CLASS_ITEM)); 318 gen = malloc(sizeof(EX_CLASS_ITEM));
319 if (gen) { 319 if (gen) {
320 gen->class_index = class_index; 320 gen->class_index = class_index;
321 gen->meth_num = 0; 321 gen->meth_num = 0;
322 gen->meth = sk_CRYPTO_EX_DATA_FUNCS_new_null(); 322 gen->meth = sk_CRYPTO_EX_DATA_FUNCS_new_null();
323 if (!gen->meth) 323 if (!gen->meth)
324 OPENSSL_free(gen); 324 free(gen);
325 else { 325 else {
326 /* Because we're inside the ex_data lock, the 326 /* Because we're inside the ex_data lock, the
327 * return value from the insert will be NULL */ 327 * return value from the insert will be NULL */
@@ -343,7 +343,7 @@ def_add_index(EX_CLASS_ITEM *item, long argl, void *argp,
343 CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) 343 CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
344{ 344{
345 int toret = -1; 345 int toret = -1;
346 CRYPTO_EX_DATA_FUNCS *a = (CRYPTO_EX_DATA_FUNCS *)OPENSSL_malloc( 346 CRYPTO_EX_DATA_FUNCS *a = (CRYPTO_EX_DATA_FUNCS *)malloc(
347 sizeof(CRYPTO_EX_DATA_FUNCS)); 347 sizeof(CRYPTO_EX_DATA_FUNCS));
348 if (!a) { 348 if (!a) {
349 CRYPTOerr(CRYPTO_F_DEF_ADD_INDEX, ERR_R_MALLOC_FAILURE); 349 CRYPTOerr(CRYPTO_F_DEF_ADD_INDEX, ERR_R_MALLOC_FAILURE);
@@ -358,7 +358,7 @@ def_add_index(EX_CLASS_ITEM *item, long argl, void *argp,
358 while (sk_CRYPTO_EX_DATA_FUNCS_num(item->meth) <= item->meth_num) { 358 while (sk_CRYPTO_EX_DATA_FUNCS_num(item->meth) <= item->meth_num) {
359 if (!sk_CRYPTO_EX_DATA_FUNCS_push(item->meth, NULL)) { 359 if (!sk_CRYPTO_EX_DATA_FUNCS_push(item->meth, NULL)) {
360 CRYPTOerr(CRYPTO_F_DEF_ADD_INDEX, ERR_R_MALLOC_FAILURE); 360 CRYPTOerr(CRYPTO_F_DEF_ADD_INDEX, ERR_R_MALLOC_FAILURE);
361 OPENSSL_free(a); 361 free(a);
362 goto err; 362 goto err;
363 } 363 }
364 } 364 }
@@ -422,7 +422,7 @@ int_new_ex_data(int class_index, void *obj,
422 CRYPTO_r_lock(CRYPTO_LOCK_EX_DATA); 422 CRYPTO_r_lock(CRYPTO_LOCK_EX_DATA);
423 mx = sk_CRYPTO_EX_DATA_FUNCS_num(item->meth); 423 mx = sk_CRYPTO_EX_DATA_FUNCS_num(item->meth);
424 if (mx > 0) { 424 if (mx > 0) {
425 storage = OPENSSL_malloc(mx * sizeof(CRYPTO_EX_DATA_FUNCS*)); 425 storage = malloc(mx * sizeof(CRYPTO_EX_DATA_FUNCS*));
426 if (!storage) 426 if (!storage)
427 goto skip; 427 goto skip;
428 for (i = 0; i < mx; i++) 428 for (i = 0; i < mx; i++)
@@ -442,7 +442,7 @@ skip:
442 } 442 }
443 } 443 }
444 if (storage) 444 if (storage)
445 OPENSSL_free(storage); 445 free(storage);
446 return 1; 446 return 1;
447} 447}
448 448
@@ -466,7 +466,7 @@ int_dup_ex_data(int class_index, CRYPTO_EX_DATA *to,
466 if (j < mx) 466 if (j < mx)
467 mx = j; 467 mx = j;
468 if (mx > 0) { 468 if (mx > 0) {
469 storage = OPENSSL_malloc(mx * sizeof(CRYPTO_EX_DATA_FUNCS*)); 469 storage = malloc(mx * sizeof(CRYPTO_EX_DATA_FUNCS*));
470 if (!storage) 470 if (!storage)
471 goto skip; 471 goto skip;
472 for (i = 0; i < mx; i++) 472 for (i = 0; i < mx; i++)
@@ -486,7 +486,7 @@ skip:
486 CRYPTO_set_ex_data(to, i, ptr); 486 CRYPTO_set_ex_data(to, i, ptr);
487 } 487 }
488 if (storage) 488 if (storage)
489 OPENSSL_free(storage); 489 free(storage);
490 return 1; 490 return 1;
491} 491}
492 492
@@ -503,7 +503,7 @@ int_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad)
503 CRYPTO_r_lock(CRYPTO_LOCK_EX_DATA); 503 CRYPTO_r_lock(CRYPTO_LOCK_EX_DATA);
504 mx = sk_CRYPTO_EX_DATA_FUNCS_num(item->meth); 504 mx = sk_CRYPTO_EX_DATA_FUNCS_num(item->meth);
505 if (mx > 0) { 505 if (mx > 0) {
506 storage = OPENSSL_malloc(mx * sizeof(CRYPTO_EX_DATA_FUNCS*)); 506 storage = malloc(mx * sizeof(CRYPTO_EX_DATA_FUNCS*));
507 if (!storage) 507 if (!storage)
508 goto skip; 508 goto skip;
509 for (i = 0; i < mx; i++) 509 for (i = 0; i < mx; i++)
@@ -523,7 +523,7 @@ skip:
523 } 523 }
524 } 524 }
525 if (storage) 525 if (storage)
526 OPENSSL_free(storage); 526 free(storage);
527 if (ad->sk) { 527 if (ad->sk) {
528 sk_void_free(ad->sk); 528 sk_void_free(ad->sk);
529 ad->sk = NULL; 529 ad->sk = NULL;
diff --git a/src/lib/libcrypto/hmac/hm_ameth.c b/src/lib/libcrypto/hmac/hm_ameth.c
index e03f24aeda..fbada40d9c 100644
--- a/src/lib/libcrypto/hmac/hm_ameth.c
+++ b/src/lib/libcrypto/hmac/hm_ameth.c
@@ -122,7 +122,7 @@ static int old_hmac_encode(const EVP_PKEY *pkey, unsigned char **pder)
122 { 122 {
123 if (!*pder) 123 if (!*pder)
124 { 124 {
125 *pder = OPENSSL_malloc(os->length); 125 *pder = malloc(os->length);
126 inc = 0; 126 inc = 0;
127 } 127 }
128 else inc = 1; 128 else inc = 1;
diff --git a/src/lib/libcrypto/hmac/hm_pmeth.c b/src/lib/libcrypto/hmac/hm_pmeth.c
index 0daa44511d..f1c67329d0 100644
--- a/src/lib/libcrypto/hmac/hm_pmeth.c
+++ b/src/lib/libcrypto/hmac/hm_pmeth.c
@@ -75,7 +75,7 @@ typedef struct
75static int pkey_hmac_init(EVP_PKEY_CTX *ctx) 75static int pkey_hmac_init(EVP_PKEY_CTX *ctx)
76 { 76 {
77 HMAC_PKEY_CTX *hctx; 77 HMAC_PKEY_CTX *hctx;
78 hctx = OPENSSL_malloc(sizeof(HMAC_PKEY_CTX)); 78 hctx = malloc(sizeof(HMAC_PKEY_CTX));
79 if (!hctx) 79 if (!hctx)
80 return 0; 80 return 0;
81 hctx->md = NULL; 81 hctx->md = NULL;
@@ -119,10 +119,10 @@ static void pkey_hmac_cleanup(EVP_PKEY_CTX *ctx)
119 { 119 {
120 if (hctx->ktmp.length) 120 if (hctx->ktmp.length)
121 OPENSSL_cleanse(hctx->ktmp.data, hctx->ktmp.length); 121 OPENSSL_cleanse(hctx->ktmp.data, hctx->ktmp.length);
122 OPENSSL_free(hctx->ktmp.data); 122 free(hctx->ktmp.data);
123 hctx->ktmp.data = NULL; 123 hctx->ktmp.data = NULL;
124 } 124 }
125 OPENSSL_free(hctx); 125 free(hctx);
126 } 126 }
127 127
128static int pkey_hmac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) 128static int pkey_hmac_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
@@ -229,7 +229,7 @@ static int pkey_hmac_ctrl_str(EVP_PKEY_CTX *ctx,
229 if (!key) 229 if (!key)
230 return 0; 230 return 0;
231 r = pkey_hmac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, keylen, key); 231 r = pkey_hmac_ctrl(ctx, EVP_PKEY_CTRL_SET_MAC_KEY, keylen, key);
232 OPENSSL_free(key); 232 free(key);
233 return r; 233 return r;
234 } 234 }
235 return -2; 235 return -2;
diff --git a/src/lib/libcrypto/lhash/lh_test.c b/src/lib/libcrypto/lhash/lh_test.c
index 85700c859b..2224a216ab 100644
--- a/src/lib/libcrypto/lhash/lh_test.c
+++ b/src/lib/libcrypto/lhash/lh_test.c
@@ -76,7 +76,7 @@ main()
76 fgets(buf,256,stdin); 76 fgets(buf,256,stdin);
77 if (buf[0] == '\0') break; 77 if (buf[0] == '\0') break;
78 i=strlen(buf); 78 i=strlen(buf);
79 p=OPENSSL_malloc(i+1); 79 p=malloc(i+1);
80 memcpy(p,buf,i+1); 80 memcpy(p,buf,i+1);
81 lh_insert(conf,p); 81 lh_insert(conf,p);
82 } 82 }
diff --git a/src/lib/libcrypto/lhash/lhash.c b/src/lib/libcrypto/lhash/lhash.c
index 47f748081b..78ba26db83 100644
--- a/src/lib/libcrypto/lhash/lhash.c
+++ b/src/lib/libcrypto/lhash/lhash.c
@@ -116,9 +116,9 @@ _LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c)
116 _LHASH *ret; 116 _LHASH *ret;
117 int i; 117 int i;
118 118
119 if ((ret=OPENSSL_malloc(sizeof(_LHASH))) == NULL) 119 if ((ret=malloc(sizeof(_LHASH))) == NULL)
120 goto err0; 120 goto err0;
121 if ((ret->b=OPENSSL_malloc(sizeof(LHASH_NODE *)*MIN_NODES)) == NULL) 121 if ((ret->b=malloc(sizeof(LHASH_NODE *)*MIN_NODES)) == NULL)
122 goto err1; 122 goto err1;
123 for (i=0; i<MIN_NODES; i++) 123 for (i=0; i<MIN_NODES; i++)
124 ret->b[i]=NULL; 124 ret->b[i]=NULL;
@@ -149,7 +149,7 @@ _LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c)
149 ret->error=0; 149 ret->error=0;
150 return(ret); 150 return(ret);
151err1: 151err1:
152 OPENSSL_free(ret); 152 free(ret);
153err0: 153err0:
154 return(NULL); 154 return(NULL);
155 } 155 }
@@ -168,12 +168,12 @@ void lh_free(_LHASH *lh)
168 while (n != NULL) 168 while (n != NULL)
169 { 169 {
170 nn=n->next; 170 nn=n->next;
171 OPENSSL_free(n); 171 free(n);
172 n=nn; 172 n=nn;
173 } 173 }
174 } 174 }
175 OPENSSL_free(lh->b); 175 free(lh->b);
176 OPENSSL_free(lh); 176 free(lh);
177 } 177 }
178 178
179void *lh_insert(_LHASH *lh, void *data) 179void *lh_insert(_LHASH *lh, void *data)
@@ -190,7 +190,7 @@ void *lh_insert(_LHASH *lh, void *data)
190 190
191 if (*rn == NULL) 191 if (*rn == NULL)
192 { 192 {
193 if ((nn=(LHASH_NODE *)OPENSSL_malloc(sizeof(LHASH_NODE))) == NULL) 193 if ((nn=(LHASH_NODE *)malloc(sizeof(LHASH_NODE))) == NULL)
194 { 194 {
195 lh->error++; 195 lh->error++;
196 return(NULL); 196 return(NULL);
@@ -233,7 +233,7 @@ void *lh_delete(_LHASH *lh, const void *data)
233 nn= *rn; 233 nn= *rn;
234 *rn=nn->next; 234 *rn=nn->next;
235 ret=nn->data; 235 ret=nn->data;
236 OPENSSL_free(nn); 236 free(nn);
237 lh->num_delete++; 237 lh->num_delete++;
238 } 238 }
239 239
@@ -343,7 +343,7 @@ static void expand(_LHASH *lh)
343 if ((lh->p) >= lh->pmax) 343 if ((lh->p) >= lh->pmax)
344 { 344 {
345 j=(int)lh->num_alloc_nodes*2; 345 j=(int)lh->num_alloc_nodes*2;
346 n=(LHASH_NODE **)OPENSSL_realloc(lh->b, 346 n=(LHASH_NODE **)realloc(lh->b,
347 (int)(sizeof(LHASH_NODE *)*j)); 347 (int)(sizeof(LHASH_NODE *)*j));
348 if (n == NULL) 348 if (n == NULL)
349 { 349 {
@@ -371,7 +371,7 @@ static void contract(_LHASH *lh)
371 lh->b[lh->p+lh->pmax-1]=NULL; /* 24/07-92 - eay - weird but :-( */ 371 lh->b[lh->p+lh->pmax-1]=NULL; /* 24/07-92 - eay - weird but :-( */
372 if (lh->p == 0) 372 if (lh->p == 0)
373 { 373 {
374 n=(LHASH_NODE **)OPENSSL_realloc(lh->b, 374 n=(LHASH_NODE **)realloc(lh->b,
375 (unsigned int)(sizeof(LHASH_NODE *)*lh->pmax)); 375 (unsigned int)(sizeof(LHASH_NODE *)*lh->pmax));
376 if (n == NULL) 376 if (n == NULL)
377 { 377 {
diff --git a/src/lib/libcrypto/modes/gcm128.c b/src/lib/libcrypto/modes/gcm128.c
index e1dc2b0f47..52de084318 100644
--- a/src/lib/libcrypto/modes/gcm128.c
+++ b/src/lib/libcrypto/modes/gcm128.c
@@ -1540,7 +1540,7 @@ GCM128_CONTEXT *CRYPTO_gcm128_new(void *key, block128_f block)
1540{ 1540{
1541 GCM128_CONTEXT *ret; 1541 GCM128_CONTEXT *ret;
1542 1542
1543 if ((ret = (GCM128_CONTEXT *)OPENSSL_malloc(sizeof(GCM128_CONTEXT)))) 1543 if ((ret = (GCM128_CONTEXT *)malloc(sizeof(GCM128_CONTEXT))))
1544 CRYPTO_gcm128_init(ret,key,block); 1544 CRYPTO_gcm128_init(ret,key,block);
1545 1545
1546 return ret; 1546 return ret;
@@ -1550,7 +1550,7 @@ void CRYPTO_gcm128_release(GCM128_CONTEXT *ctx)
1550{ 1550{
1551 if (ctx) { 1551 if (ctx) {
1552 OPENSSL_cleanse(ctx,sizeof(*ctx)); 1552 OPENSSL_cleanse(ctx,sizeof(*ctx));
1553 OPENSSL_free(ctx); 1553 free(ctx);
1554 } 1554 }
1555} 1555}
1556 1556
diff --git a/src/lib/libcrypto/objects/o_names.c b/src/lib/libcrypto/objects/o_names.c
index 4a548c2ed4..4c959db2da 100644
--- a/src/lib/libcrypto/objects/o_names.c
+++ b/src/lib/libcrypto/objects/o_names.c
@@ -83,7 +83,7 @@ int OBJ_NAME_new_index(unsigned long (*hash_func)(const char *),
83 for (i=sk_NAME_FUNCS_num(name_funcs_stack); i<names_type_num; i++) 83 for (i=sk_NAME_FUNCS_num(name_funcs_stack); i<names_type_num; i++)
84 { 84 {
85 MemCheck_off(); 85 MemCheck_off();
86 name_funcs = OPENSSL_malloc(sizeof(NAME_FUNCS)); 86 name_funcs = malloc(sizeof(NAME_FUNCS));
87 MemCheck_on(); 87 MemCheck_on();
88 if (!name_funcs) 88 if (!name_funcs)
89 { 89 {
@@ -192,7 +192,7 @@ int OBJ_NAME_add(const char *name, int type, const char *data)
192 alias=type&OBJ_NAME_ALIAS; 192 alias=type&OBJ_NAME_ALIAS;
193 type&= ~OBJ_NAME_ALIAS; 193 type&= ~OBJ_NAME_ALIAS;
194 194
195 onp=(OBJ_NAME *)OPENSSL_malloc(sizeof(OBJ_NAME)); 195 onp=(OBJ_NAME *)malloc(sizeof(OBJ_NAME));
196 if (onp == NULL) 196 if (onp == NULL)
197 { 197 {
198 /* ERROR */ 198 /* ERROR */
@@ -217,7 +217,7 @@ int OBJ_NAME_add(const char *name, int type, const char *data)
217 sk_NAME_FUNCS_value(name_funcs_stack, 217 sk_NAME_FUNCS_value(name_funcs_stack,
218 ret->type)->free_func(ret->name,ret->type,ret->data); 218 ret->type)->free_func(ret->name,ret->type,ret->data);
219 } 219 }
220 OPENSSL_free(ret); 220 free(ret);
221 } 221 }
222 else 222 else
223 { 223 {
@@ -252,7 +252,7 @@ int OBJ_NAME_remove(const char *name, int type)
252 sk_NAME_FUNCS_value(name_funcs_stack, 252 sk_NAME_FUNCS_value(name_funcs_stack,
253 ret->type)->free_func(ret->name,ret->type,ret->data); 253 ret->type)->free_func(ret->name,ret->type,ret->data);
254 } 254 }
255 OPENSSL_free(ret); 255 free(ret);
256 return(1); 256 return(1);
257 } 257 }
258 else 258 else
@@ -318,7 +318,7 @@ void OBJ_NAME_do_all_sorted(int type,void (*fn)(const OBJ_NAME *,void *arg),
318 int n; 318 int n;
319 319
320 d.type=type; 320 d.type=type;
321 d.names=OPENSSL_malloc(lh_OBJ_NAME_num_items(names_lh)*sizeof *d.names); 321 d.names=malloc(lh_OBJ_NAME_num_items(names_lh)*sizeof *d.names);
322 d.n=0; 322 d.n=0;
323 OBJ_NAME_do_all(type,do_all_sorted_fn,&d); 323 OBJ_NAME_do_all(type,do_all_sorted_fn,&d);
324 324
@@ -327,7 +327,7 @@ void OBJ_NAME_do_all_sorted(int type,void (*fn)(const OBJ_NAME *,void *arg),
327 for(n=0 ; n < d.n ; ++n) 327 for(n=0 ; n < d.n ; ++n)
328 fn(d.names[n],arg); 328 fn(d.names[n],arg);
329 329
330 OPENSSL_free((void *)d.names); 330 free((void *)d.names);
331 } 331 }
332 332
333static int free_type; 333static int free_type;
@@ -345,7 +345,7 @@ static IMPLEMENT_LHASH_DOALL_FN(names_lh_free, OBJ_NAME)
345 345
346static void name_funcs_free(NAME_FUNCS *ptr) 346static void name_funcs_free(NAME_FUNCS *ptr)
347 { 347 {
348 OPENSSL_free(ptr); 348 free(ptr);
349 } 349 }
350 350
351void OBJ_NAME_cleanup(int type) 351void OBJ_NAME_cleanup(int type)
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c
index bced796e62..641a97c8aa 100644
--- a/src/lib/libcrypto/objects/obj_dat.c
+++ b/src/lib/libcrypto/objects/obj_dat.c
@@ -199,7 +199,7 @@ static void cleanup3_doall(ADDED_OBJ *a)
199 { 199 {
200 if (--a->obj->nid == 0) 200 if (--a->obj->nid == 0)
201 ASN1_OBJECT_free(a->obj); 201 ASN1_OBJECT_free(a->obj);
202 OPENSSL_free(a); 202 free(a);
203 } 203 }
204 204
205static IMPLEMENT_LHASH_DOALL_FN(cleanup1, ADDED_OBJ) 205static IMPLEMENT_LHASH_DOALL_FN(cleanup1, ADDED_OBJ)
@@ -253,13 +253,13 @@ int OBJ_add_object(const ASN1_OBJECT *obj)
253 if (added == NULL) 253 if (added == NULL)
254 if (!init_added()) return(0); 254 if (!init_added()) return(0);
255 if ((o=OBJ_dup(obj)) == NULL) goto err; 255 if ((o=OBJ_dup(obj)) == NULL) goto err;
256 if (!(ao[ADDED_NID]=(ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_OBJ)))) goto err2; 256 if (!(ao[ADDED_NID]=(ADDED_OBJ *)malloc(sizeof(ADDED_OBJ)))) goto err2;
257 if ((o->length != 0) && (obj->data != NULL)) 257 if ((o->length != 0) && (obj->data != NULL))
258 if (!(ao[ADDED_DATA]=(ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_OBJ)))) goto err2; 258 if (!(ao[ADDED_DATA]=(ADDED_OBJ *)malloc(sizeof(ADDED_OBJ)))) goto err2;
259 if (o->sn != NULL) 259 if (o->sn != NULL)
260 if (!(ao[ADDED_SNAME]=(ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_OBJ)))) goto err2; 260 if (!(ao[ADDED_SNAME]=(ADDED_OBJ *)malloc(sizeof(ADDED_OBJ)))) goto err2;
261 if (o->ln != NULL) 261 if (o->ln != NULL)
262 if (!(ao[ADDED_LNAME]=(ADDED_OBJ *)OPENSSL_malloc(sizeof(ADDED_OBJ)))) goto err2; 262 if (!(ao[ADDED_LNAME]=(ADDED_OBJ *)malloc(sizeof(ADDED_OBJ)))) goto err2;
263 263
264 for (i=ADDED_DATA; i<=ADDED_NID; i++) 264 for (i=ADDED_DATA; i<=ADDED_NID; i++)
265 { 265 {
@@ -270,7 +270,7 @@ int OBJ_add_object(const ASN1_OBJECT *obj)
270 aop=lh_ADDED_OBJ_insert(added,ao[i]); 270 aop=lh_ADDED_OBJ_insert(added,ao[i]);
271 /* memory leak, buit should not normally matter */ 271 /* memory leak, buit should not normally matter */
272 if (aop != NULL) 272 if (aop != NULL)
273 OPENSSL_free(aop); 273 free(aop);
274 } 274 }
275 } 275 }
276 o->flags&= ~(ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS| 276 o->flags&= ~(ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS|
@@ -281,8 +281,8 @@ err2:
281 OBJerr(OBJ_F_OBJ_ADD_OBJECT,ERR_R_MALLOC_FAILURE); 281 OBJerr(OBJ_F_OBJ_ADD_OBJECT,ERR_R_MALLOC_FAILURE);
282err: 282err:
283 for (i=ADDED_DATA; i<=ADDED_NID; i++) 283 for (i=ADDED_DATA; i<=ADDED_NID; i++)
284 if (ao[i] != NULL) OPENSSL_free(ao[i]); 284 if (ao[i] != NULL) free(ao[i]);
285 if (o != NULL) OPENSSL_free(o); 285 if (o != NULL) free(o);
286 return(NID_undef); 286 return(NID_undef);
287 } 287 }
288 288
@@ -449,7 +449,7 @@ ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name)
449 /* Work out total size */ 449 /* Work out total size */
450 j = ASN1_object_size(0,i,V_ASN1_OBJECT); 450 j = ASN1_object_size(0,i,V_ASN1_OBJECT);
451 451
452 if((buf=(unsigned char *)OPENSSL_malloc(j)) == NULL) return NULL; 452 if((buf=(unsigned char *)malloc(j)) == NULL) return NULL;
453 453
454 p = buf; 454 p = buf;
455 /* Write out tag+length */ 455 /* Write out tag+length */
@@ -459,7 +459,7 @@ ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name)
459 459
460 cp=buf; 460 cp=buf;
461 op=d2i_ASN1_OBJECT(NULL,&cp,j); 461 op=d2i_ASN1_OBJECT(NULL,&cp,j);
462 OPENSSL_free(buf); 462 free(buf);
463 return op; 463 return op;
464 } 464 }
465 465
@@ -590,7 +590,7 @@ int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)
590 } 590 }
591 n++; 591 n++;
592 n += i; 592 n += i;
593 OPENSSL_free(bndec); 593 free(bndec);
594 } 594 }
595 else 595 else
596 { 596 {
@@ -774,7 +774,7 @@ int OBJ_create(const char *oid, const char *sn, const char *ln)
774 i=a2d_ASN1_OBJECT(NULL,0,oid,-1); 774 i=a2d_ASN1_OBJECT(NULL,0,oid,-1);
775 if (i <= 0) return(0); 775 if (i <= 0) return(0);
776 776
777 if ((buf=(unsigned char *)OPENSSL_malloc(i)) == NULL) 777 if ((buf=(unsigned char *)malloc(i)) == NULL)
778 { 778 {
779 OBJerr(OBJ_F_OBJ_CREATE,ERR_R_MALLOC_FAILURE); 779 OBJerr(OBJ_F_OBJ_CREATE,ERR_R_MALLOC_FAILURE);
780 return(0); 780 return(0);
@@ -788,7 +788,7 @@ int OBJ_create(const char *oid, const char *sn, const char *ln)
788 ok=OBJ_add_object(op); 788 ok=OBJ_add_object(op);
789err: 789err:
790 ASN1_OBJECT_free(op); 790 ASN1_OBJECT_free(op);
791 OPENSSL_free(buf); 791 free(buf);
792 return(ok); 792 return(ok);
793 } 793 }
794 794
diff --git a/src/lib/libcrypto/objects/obj_lib.c b/src/lib/libcrypto/objects/obj_lib.c
index 23e9d48cdf..338fe851fc 100644
--- a/src/lib/libcrypto/objects/obj_lib.c
+++ b/src/lib/libcrypto/objects/obj_lib.c
@@ -80,7 +80,7 @@ ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o)
80 OBJerr(OBJ_F_OBJ_DUP,ERR_R_ASN1_LIB); 80 OBJerr(OBJ_F_OBJ_DUP,ERR_R_ASN1_LIB);
81 return(NULL); 81 return(NULL);
82 } 82 }
83 data=OPENSSL_malloc(o->length); 83 data=malloc(o->length);
84 if (data == NULL) 84 if (data == NULL)
85 goto err; 85 goto err;
86 if (o->data != NULL) 86 if (o->data != NULL)
@@ -93,7 +93,7 @@ ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o)
93 if (o->ln != NULL) 93 if (o->ln != NULL)
94 { 94 {
95 i=strlen(o->ln)+1; 95 i=strlen(o->ln)+1;
96 ln=OPENSSL_malloc(i); 96 ln=malloc(i);
97 if (ln == NULL) goto err; 97 if (ln == NULL) goto err;
98 memcpy(ln,o->ln,i); 98 memcpy(ln,o->ln,i);
99 r->ln=ln; 99 r->ln=ln;
@@ -102,7 +102,7 @@ ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o)
102 if (o->sn != NULL) 102 if (o->sn != NULL)
103 { 103 {
104 i=strlen(o->sn)+1; 104 i=strlen(o->sn)+1;
105 sn=OPENSSL_malloc(i); 105 sn=malloc(i);
106 if (sn == NULL) goto err; 106 if (sn == NULL) goto err;
107 memcpy(sn,o->sn,i); 107 memcpy(sn,o->sn,i);
108 r->sn=sn; 108 r->sn=sn;
@@ -112,10 +112,10 @@ ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o)
112 return(r); 112 return(r);
113err: 113err:
114 OBJerr(OBJ_F_OBJ_DUP,ERR_R_MALLOC_FAILURE); 114 OBJerr(OBJ_F_OBJ_DUP,ERR_R_MALLOC_FAILURE);
115 if (ln != NULL) OPENSSL_free(ln); 115 if (ln != NULL) free(ln);
116 if (sn != NULL) OPENSSL_free(sn); 116 if (sn != NULL) free(sn);
117 if (data != NULL) OPENSSL_free(data); 117 if (data != NULL) free(data);
118 if (r != NULL) OPENSSL_free(r); 118 if (r != NULL) free(r);
119 return(NULL); 119 return(NULL);
120 } 120 }
121 121
diff --git a/src/lib/libcrypto/objects/obj_xref.c b/src/lib/libcrypto/objects/obj_xref.c
index 9f744bcede..797adc8d10 100644
--- a/src/lib/libcrypto/objects/obj_xref.c
+++ b/src/lib/libcrypto/objects/obj_xref.c
@@ -162,7 +162,7 @@ int OBJ_add_sigid(int signid, int dig_id, int pkey_id)
162 sigx_app = sk_nid_triple_new(sigx_cmp); 162 sigx_app = sk_nid_triple_new(sigx_cmp);
163 if (!sigx_app) 163 if (!sigx_app)
164 return 0; 164 return 0;
165 ntr = OPENSSL_malloc(sizeof(int) * 3); 165 ntr = malloc(sizeof(int) * 3);
166 if (!ntr) 166 if (!ntr)
167 return 0; 167 return 0;
168 ntr->sign_id = signid; 168 ntr->sign_id = signid;
@@ -171,7 +171,7 @@ int OBJ_add_sigid(int signid, int dig_id, int pkey_id)
171 171
172 if (!sk_nid_triple_push(sig_app, ntr)) 172 if (!sk_nid_triple_push(sig_app, ntr))
173 { 173 {
174 OPENSSL_free(ntr); 174 free(ntr);
175 return 0; 175 return 0;
176 } 176 }
177 177
@@ -186,7 +186,7 @@ int OBJ_add_sigid(int signid, int dig_id, int pkey_id)
186 186
187static void sid_free(nid_triple *tt) 187static void sid_free(nid_triple *tt)
188 { 188 {
189 OPENSSL_free(tt); 189 free(tt);
190 } 190 }
191 191
192void OBJ_sigid_free(void) 192void OBJ_sigid_free(void)
diff --git a/src/lib/libcrypto/ocsp/ocsp_ext.c b/src/lib/libcrypto/ocsp/ocsp_ext.c
index ec884cb08f..9c7832b301 100644
--- a/src/lib/libcrypto/ocsp/ocsp_ext.c
+++ b/src/lib/libcrypto/ocsp/ocsp_ext.c
@@ -274,7 +274,7 @@ ASN1_STRING *ASN1_STRING_encode(ASN1_STRING *s, i2d_of_void *i2d,
274 if (data) 274 if (data)
275 { 275 {
276 if ((i=i2d(data,NULL)) <= 0) goto err; 276 if ((i=i2d(data,NULL)) <= 0) goto err;
277 if (!(b=p=OPENSSL_malloc((unsigned int)i))) 277 if (!(b=p=malloc((unsigned int)i)))
278 goto err; 278 goto err;
279 if (i2d(data, &p) <= 0) goto err; 279 if (i2d(data, &p) <= 0) goto err;
280 } 280 }
@@ -285,7 +285,7 @@ ASN1_STRING *ASN1_STRING_encode(ASN1_STRING *s, i2d_of_void *i2d,
285 V_ASN1_SEQUENCE, 285 V_ASN1_SEQUENCE,
286 V_ASN1_UNIVERSAL, 286 V_ASN1_UNIVERSAL,
287 IS_SEQUENCE))<=0) goto err; 287 IS_SEQUENCE))<=0) goto err;
288 if (!(b=p=OPENSSL_malloc((unsigned int)i))) 288 if (!(b=p=malloc((unsigned int)i)))
289 goto err; 289 goto err;
290 if (i2d_ASN1_SET_OF_ASN1_OBJECT(sk,&p,(I2D_OF(ASN1_OBJECT))i2d, 290 if (i2d_ASN1_SET_OF_ASN1_OBJECT(sk,&p,(I2D_OF(ASN1_OBJECT))i2d,
291 V_ASN1_SEQUENCE, 291 V_ASN1_SEQUENCE,
@@ -299,10 +299,10 @@ ASN1_STRING *ASN1_STRING_encode(ASN1_STRING *s, i2d_of_void *i2d,
299 } 299 }
300 if (!s && !(s = ASN1_STRING_new())) goto err; 300 if (!s && !(s = ASN1_STRING_new())) goto err;
301 if (!(ASN1_STRING_set(s, b, i))) goto err; 301 if (!(ASN1_STRING_set(s, b, i))) goto err;
302 OPENSSL_free(b); 302 free(b);
303 return s; 303 return s;
304err: 304err:
305 if (b) OPENSSL_free(b); 305 if (b) free(b);
306 return NULL; 306 return NULL;
307 } 307 }
308#endif 308#endif
@@ -327,7 +327,7 @@ static int ocsp_add1_nonce(STACK_OF(X509_EXTENSION) **exts, unsigned char *val,
327 * it relies on library internals. 327 * it relies on library internals.
328 */ 328 */
329 os.length = ASN1_object_size(0, len, V_ASN1_OCTET_STRING); 329 os.length = ASN1_object_size(0, len, V_ASN1_OCTET_STRING);
330 os.data = OPENSSL_malloc(os.length); 330 os.data = malloc(os.length);
331 if (os.data == NULL) 331 if (os.data == NULL)
332 goto err; 332 goto err;
333 tmpval = os.data; 333 tmpval = os.data;
@@ -342,7 +342,7 @@ static int ocsp_add1_nonce(STACK_OF(X509_EXTENSION) **exts, unsigned char *val,
342 ret = 1; 342 ret = 1;
343 err: 343 err:
344 if (os.data) 344 if (os.data)
345 OPENSSL_free(os.data); 345 free(os.data);
346 return ret; 346 return ret;
347 } 347 }
348 348
diff --git a/src/lib/libcrypto/ocsp/ocsp_ht.c b/src/lib/libcrypto/ocsp/ocsp_ht.c
index af5fc16691..17b252d6a8 100644
--- a/src/lib/libcrypto/ocsp/ocsp_ht.c
+++ b/src/lib/libcrypto/ocsp/ocsp_ht.c
@@ -114,8 +114,8 @@ void OCSP_REQ_CTX_free(OCSP_REQ_CTX *rctx)
114 if (rctx->mem) 114 if (rctx->mem)
115 BIO_free(rctx->mem); 115 BIO_free(rctx->mem);
116 if (rctx->iobuf) 116 if (rctx->iobuf)
117 OPENSSL_free(rctx->iobuf); 117 free(rctx->iobuf);
118 OPENSSL_free(rctx); 118 free(rctx);
119 } 119 }
120 120
121int OCSP_REQ_CTX_set1_req(OCSP_REQ_CTX *rctx, OCSP_REQUEST *req) 121int OCSP_REQ_CTX_set1_req(OCSP_REQ_CTX *rctx, OCSP_REQUEST *req)
@@ -157,7 +157,7 @@ OCSP_REQ_CTX *OCSP_sendreq_new(BIO *io, char *path, OCSP_REQUEST *req,
157 static const char post_hdr[] = "POST %s HTTP/1.0\r\n"; 157 static const char post_hdr[] = "POST %s HTTP/1.0\r\n";
158 158
159 OCSP_REQ_CTX *rctx; 159 OCSP_REQ_CTX *rctx;
160 rctx = OPENSSL_malloc(sizeof(OCSP_REQ_CTX)); 160 rctx = malloc(sizeof(OCSP_REQ_CTX));
161 rctx->state = OHS_ERROR; 161 rctx->state = OHS_ERROR;
162 rctx->mem = BIO_new(BIO_s_mem()); 162 rctx->mem = BIO_new(BIO_s_mem());
163 rctx->io = io; 163 rctx->io = io;
@@ -166,7 +166,7 @@ OCSP_REQ_CTX *OCSP_sendreq_new(BIO *io, char *path, OCSP_REQUEST *req,
166 rctx->iobuflen = maxline; 166 rctx->iobuflen = maxline;
167 else 167 else
168 rctx->iobuflen = OCSP_MAX_LINE_LEN; 168 rctx->iobuflen = OCSP_MAX_LINE_LEN;
169 rctx->iobuf = OPENSSL_malloc(rctx->iobuflen); 169 rctx->iobuf = malloc(rctx->iobuflen);
170 if (!rctx->iobuf) 170 if (!rctx->iobuf)
171 return 0; 171 return 0;
172 if (!path) 172 if (!path)
diff --git a/src/lib/libcrypto/ocsp/ocsp_lib.c b/src/lib/libcrypto/ocsp/ocsp_lib.c
index a94dc838ee..514cdabf2d 100644
--- a/src/lib/libcrypto/ocsp/ocsp_lib.c
+++ b/src/lib/libcrypto/ocsp/ocsp_lib.c
@@ -242,7 +242,7 @@ int OCSP_parse_url(char *url, char **phost, char **pport, char **ppath, int *pss
242 242
243 if (!*phost) goto mem_err; 243 if (!*phost) goto mem_err;
244 244
245 OPENSSL_free(buf); 245 free(buf);
246 246
247 return 1; 247 return 1;
248 248
@@ -255,10 +255,10 @@ int OCSP_parse_url(char *url, char **phost, char **pport, char **ppath, int *pss
255 255
256 256
257 err: 257 err:
258 if (buf) OPENSSL_free(buf); 258 if (buf) free(buf);
259 if (*ppath) OPENSSL_free(*ppath); 259 if (*ppath) free(*ppath);
260 if (*pport) OPENSSL_free(*pport); 260 if (*pport) free(*pport);
261 if (*phost) OPENSSL_free(*phost); 261 if (*phost) free(*phost);
262 return 0; 262 return 0;
263 263
264 } 264 }
diff --git a/src/lib/libcrypto/pem/pem_info.c b/src/lib/libcrypto/pem/pem_info.c
index cc7f24a9c1..4351260dfb 100644
--- a/src/lib/libcrypto/pem/pem_info.c
+++ b/src/lib/libcrypto/pem/pem_info.c
@@ -272,9 +272,9 @@ start:
272 else { 272 else {
273 /* unknown */ 273 /* unknown */
274 } 274 }
275 if (name != NULL) OPENSSL_free(name); 275 if (name != NULL) free(name);
276 if (header != NULL) OPENSSL_free(header); 276 if (header != NULL) free(header);
277 if (data != NULL) OPENSSL_free(data); 277 if (data != NULL) free(data);
278 name=NULL; 278 name=NULL;
279 header=NULL; 279 header=NULL;
280 data=NULL; 280 data=NULL;
@@ -303,9 +303,9 @@ err:
303 ret=NULL; 303 ret=NULL;
304 } 304 }
305 305
306 if (name != NULL) OPENSSL_free(name); 306 if (name != NULL) free(name);
307 if (header != NULL) OPENSSL_free(header); 307 if (header != NULL) free(header);
308 if (data != NULL) OPENSSL_free(data); 308 if (data != NULL) free(data);
309 return(ret); 309 return(ret);
310 } 310 }
311 311
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c
index 0dfa7c7376..aa6a4c9387 100644
--- a/src/lib/libcrypto/pem/pem_lib.c
+++ b/src/lib/libcrypto/pem/pem_lib.c
@@ -288,9 +288,9 @@ int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char
288 return 0; 288 return 0;
289 } 289 }
290 if(check_pem(nm, name)) break; 290 if(check_pem(nm, name)) break;
291 OPENSSL_free(nm); 291 free(nm);
292 OPENSSL_free(header); 292 free(header);
293 OPENSSL_free(data); 293 free(data);
294 } 294 }
295 if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) goto err; 295 if (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) goto err;
296 if (!PEM_do_header(&cipher,data,&len,cb,u)) goto err; 296 if (!PEM_do_header(&cipher,data,&len,cb,u)) goto err;
@@ -304,9 +304,9 @@ int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char
304 ret = 1; 304 ret = 1;
305 305
306err: 306err:
307 if (!ret || !pnm) OPENSSL_free(nm); 307 if (!ret || !pnm) free(nm);
308 OPENSSL_free(header); 308 free(header);
309 if (!ret) OPENSSL_free(data); 309 if (!ret) free(data);
310 return ret; 310 return ret;
311 } 311 }
312 312
@@ -360,7 +360,7 @@ int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp,
360 } 360 }
361 /* dzise + 8 bytes are needed */ 361 /* dzise + 8 bytes are needed */
362 /* actually it needs the cipher block size extra... */ 362 /* actually it needs the cipher block size extra... */
363 data=(unsigned char *)OPENSSL_malloc((unsigned int)dsize+20); 363 data=(unsigned char *)malloc((unsigned int)dsize+20);
364 if (data == NULL) 364 if (data == NULL)
365 { 365 {
366 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,ERR_R_MALLOC_FAILURE); 366 PEMerr(PEM_F_PEM_ASN1_WRITE_BIO,ERR_R_MALLOC_FAILURE);
@@ -427,7 +427,7 @@ err:
427 if (data != NULL) 427 if (data != NULL)
428 { 428 {
429 OPENSSL_cleanse(data,(unsigned int)dsize); 429 OPENSSL_cleanse(data,(unsigned int)dsize);
430 OPENSSL_free(data); 430 free(data);
431 } 431 }
432 return(ret); 432 return(ret);
433 } 433 }
@@ -599,7 +599,7 @@ int PEM_write_bio(BIO *bp, const char *name, char *header, unsigned char *data,
599 goto err; 599 goto err;
600 } 600 }
601 601
602 buf = OPENSSL_malloc(PEM_BUFSIZE*8); 602 buf = malloc(PEM_BUFSIZE*8);
603 if (buf == NULL) 603 if (buf == NULL)
604 { 604 {
605 reason=ERR_R_MALLOC_FAILURE; 605 reason=ERR_R_MALLOC_FAILURE;
@@ -620,7 +620,7 @@ int PEM_write_bio(BIO *bp, const char *name, char *header, unsigned char *data,
620 EVP_EncodeFinal(&ctx,buf,&outl); 620 EVP_EncodeFinal(&ctx,buf,&outl);
621 if ((outl > 0) && (BIO_write(bp,(char *)buf,outl) != outl)) goto err; 621 if ((outl > 0) && (BIO_write(bp,(char *)buf,outl) != outl)) goto err;
622 OPENSSL_cleanse(buf, PEM_BUFSIZE*8); 622 OPENSSL_cleanse(buf, PEM_BUFSIZE*8);
623 OPENSSL_free(buf); 623 free(buf);
624 buf = NULL; 624 buf = NULL;
625 if ( (BIO_write(bp,"-----END ",9) != 9) || 625 if ( (BIO_write(bp,"-----END ",9) != 9) ||
626 (BIO_write(bp,name,nlen) != nlen) || 626 (BIO_write(bp,name,nlen) != nlen) ||
@@ -630,7 +630,7 @@ int PEM_write_bio(BIO *bp, const char *name, char *header, unsigned char *data,
630err: 630err:
631 if (buf) { 631 if (buf) {
632 OPENSSL_cleanse(buf, PEM_BUFSIZE*8); 632 OPENSSL_cleanse(buf, PEM_BUFSIZE*8);
633 OPENSSL_free(buf); 633 free(buf);
634 } 634 }
635 PEMerr(PEM_F_PEM_WRITE_BIO,reason); 635 PEMerr(PEM_F_PEM_WRITE_BIO,reason);
636 return(0); 636 return(0);
@@ -809,9 +809,9 @@ int PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,
809 *header=headerB->data; 809 *header=headerB->data;
810 *data=(unsigned char *)dataB->data; 810 *data=(unsigned char *)dataB->data;
811 *len=bl; 811 *len=bl;
812 OPENSSL_free(nameB); 812 free(nameB);
813 OPENSSL_free(headerB); 813 free(headerB);
814 OPENSSL_free(dataB); 814 free(dataB);
815 return(1); 815 return(1);
816err: 816err:
817 BUF_MEM_free(nameB); 817 BUF_MEM_free(nameB);
diff --git a/src/lib/libcrypto/pem/pem_oth.c b/src/lib/libcrypto/pem/pem_oth.c
index b33868d25a..69d281aa9d 100644
--- a/src/lib/libcrypto/pem/pem_oth.c
+++ b/src/lib/libcrypto/pem/pem_oth.c
@@ -81,6 +81,6 @@ void *PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x,
81 ret=d2i(x,&p,len); 81 ret=d2i(x,&p,len);
82 if (ret == NULL) 82 if (ret == NULL)
83 PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB); 83 PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB);
84 OPENSSL_free(data); 84 free(data);
85 return(ret); 85 return(ret);
86 } 86 }
diff --git a/src/lib/libcrypto/pem/pem_pkey.c b/src/lib/libcrypto/pem/pem_pkey.c
index ef152be264..a3b609b2f3 100644
--- a/src/lib/libcrypto/pem/pem_pkey.c
+++ b/src/lib/libcrypto/pem/pem_pkey.c
@@ -131,9 +131,9 @@ p8err:
131 if (ret == NULL) 131 if (ret == NULL)
132 PEMerr(PEM_F_PEM_READ_BIO_PRIVATEKEY,ERR_R_ASN1_LIB); 132 PEMerr(PEM_F_PEM_READ_BIO_PRIVATEKEY,ERR_R_ASN1_LIB);
133err: 133err:
134 OPENSSL_free(nm); 134 free(nm);
135 OPENSSL_cleanse(data, len); 135 OPENSSL_cleanse(data, len);
136 OPENSSL_free(data); 136 free(data);
137 return(ret); 137 return(ret);
138 } 138 }
139 139
@@ -188,8 +188,8 @@ EVP_PKEY *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x)
188err: 188err:
189 if (ret == NULL) 189 if (ret == NULL)
190 PEMerr(PEM_F_PEM_READ_BIO_PARAMETERS,ERR_R_ASN1_LIB); 190 PEMerr(PEM_F_PEM_READ_BIO_PARAMETERS,ERR_R_ASN1_LIB);
191 OPENSSL_free(nm); 191 free(nm);
192 OPENSSL_free(data); 192 free(data);
193 return(ret); 193 return(ret);
194 } 194 }
195 195
diff --git a/src/lib/libcrypto/pem/pem_seal.c b/src/lib/libcrypto/pem/pem_seal.c
index b6b4e13498..bac7b16b44 100644
--- a/src/lib/libcrypto/pem/pem_seal.c
+++ b/src/lib/libcrypto/pem/pem_seal.c
@@ -86,7 +86,7 @@ int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type,
86 j=RSA_size(pubk[i]->pkey.rsa); 86 j=RSA_size(pubk[i]->pkey.rsa);
87 if (j > max) max=j; 87 if (j > max) max=j;
88 } 88 }
89 s=(char *)OPENSSL_malloc(max*2); 89 s=(char *)malloc(max*2);
90 if (s == NULL) 90 if (s == NULL)
91 { 91 {
92 PEMerr(PEM_F_PEM_SEALINIT,ERR_R_MALLOC_FAILURE); 92 PEMerr(PEM_F_PEM_SEALINIT,ERR_R_MALLOC_FAILURE);
@@ -114,7 +114,7 @@ int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type,
114 114
115 ret=npubk; 115 ret=npubk;
116err: 116err:
117 if (s != NULL) OPENSSL_free(s); 117 if (s != NULL) free(s);
118 OPENSSL_cleanse(key,EVP_MAX_KEY_LENGTH); 118 OPENSSL_cleanse(key,EVP_MAX_KEY_LENGTH);
119 return(ret); 119 return(ret);
120 } 120 }
@@ -157,7 +157,7 @@ int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig, int *sigl,
157 } 157 }
158 i=RSA_size(priv->pkey.rsa); 158 i=RSA_size(priv->pkey.rsa);
159 if (i < 100) i=100; 159 if (i < 100) i=100;
160 s=(unsigned char *)OPENSSL_malloc(i*2); 160 s=(unsigned char *)malloc(i*2);
161 if (s == NULL) 161 if (s == NULL)
162 { 162 {
163 PEMerr(PEM_F_PEM_SEALFINAL,ERR_R_MALLOC_FAILURE); 163 PEMerr(PEM_F_PEM_SEALFINAL,ERR_R_MALLOC_FAILURE);
@@ -179,7 +179,7 @@ int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig, int *sigl,
179err: 179err:
180 EVP_MD_CTX_cleanup(&ctx->md); 180 EVP_MD_CTX_cleanup(&ctx->md);
181 EVP_CIPHER_CTX_cleanup(&ctx->cipher); 181 EVP_CIPHER_CTX_cleanup(&ctx->cipher);
182 if (s != NULL) OPENSSL_free(s); 182 if (s != NULL) free(s);
183 return(ret); 183 return(ret);
184 } 184 }
185#else /* !OPENSSL_NO_RSA */ 185#else /* !OPENSSL_NO_RSA */
diff --git a/src/lib/libcrypto/pem/pem_sign.c b/src/lib/libcrypto/pem/pem_sign.c
index c3b9808cb2..cbd3cd0793 100644
--- a/src/lib/libcrypto/pem/pem_sign.c
+++ b/src/lib/libcrypto/pem/pem_sign.c
@@ -82,7 +82,7 @@ int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen,
82 int i,ret=0; 82 int i,ret=0;
83 unsigned int m_len; 83 unsigned int m_len;
84 84
85 m=(unsigned char *)OPENSSL_malloc(EVP_PKEY_size(pkey)+2); 85 m=(unsigned char *)malloc(EVP_PKEY_size(pkey)+2);
86 if (m == NULL) 86 if (m == NULL)
87 { 87 {
88 PEMerr(PEM_F_PEM_SIGNFINAL,ERR_R_MALLOC_FAILURE); 88 PEMerr(PEM_F_PEM_SIGNFINAL,ERR_R_MALLOC_FAILURE);
@@ -96,7 +96,7 @@ int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen,
96 ret=1; 96 ret=1;
97err: 97err:
98 /* ctx has been zeroed by EVP_SignFinal() */ 98 /* ctx has been zeroed by EVP_SignFinal() */
99 if (m != NULL) OPENSSL_free(m); 99 if (m != NULL) free(m);
100 return(ret); 100 return(ret);
101 } 101 }
102 102
diff --git a/src/lib/libcrypto/pem/pvkfmt.c b/src/lib/libcrypto/pem/pvkfmt.c
index b1bf71a5da..8da8e77973 100644
--- a/src/lib/libcrypto/pem/pvkfmt.c
+++ b/src/lib/libcrypto/pem/pvkfmt.c
@@ -93,14 +93,14 @@ static int read_lebn(const unsigned char **in, unsigned int nbyte, BIGNUM **r)
93 unsigned char *tmpbuf, *q; 93 unsigned char *tmpbuf, *q;
94 unsigned int i; 94 unsigned int i;
95 p = *in + nbyte - 1; 95 p = *in + nbyte - 1;
96 tmpbuf = OPENSSL_malloc(nbyte); 96 tmpbuf = malloc(nbyte);
97 if (!tmpbuf) 97 if (!tmpbuf)
98 return 0; 98 return 0;
99 q = tmpbuf; 99 q = tmpbuf;
100 for (i = 0; i < nbyte; i++) 100 for (i = 0; i < nbyte; i++)
101 *q++ = *p--; 101 *q++ = *p--;
102 *r = BN_bin2bn(tmpbuf, nbyte, NULL); 102 *r = BN_bin2bn(tmpbuf, nbyte, NULL);
103 OPENSSL_free(tmpbuf); 103 free(tmpbuf);
104 if (*r) 104 if (*r)
105 { 105 {
106 *in += nbyte; 106 *in += nbyte;
@@ -284,7 +284,7 @@ static EVP_PKEY *do_b2i_bio(BIO *in, int ispub)
284 return NULL; 284 return NULL;
285 285
286 length = blob_length(bitlen, isdss, ispub); 286 length = blob_length(bitlen, isdss, ispub);
287 buf = OPENSSL_malloc(length); 287 buf = malloc(length);
288 if (!buf) 288 if (!buf)
289 { 289 {
290 PEMerr(PEM_F_DO_B2I_BIO, ERR_R_MALLOC_FAILURE); 290 PEMerr(PEM_F_DO_B2I_BIO, ERR_R_MALLOC_FAILURE);
@@ -304,7 +304,7 @@ static EVP_PKEY *do_b2i_bio(BIO *in, int ispub)
304 304
305 err: 305 err:
306 if (buf) 306 if (buf)
307 OPENSSL_free(buf); 307 free(buf);
308 return ret; 308 return ret;
309 } 309 }
310 310
@@ -508,7 +508,7 @@ static int do_i2b(unsigned char **out, EVP_PKEY *pk, int ispub)
508 p = *out; 508 p = *out;
509 else 509 else
510 { 510 {
511 p = OPENSSL_malloc(outlen); 511 p = malloc(outlen);
512 if (!p) 512 if (!p)
513 return -1; 513 return -1;
514 *out = p; 514 *out = p;
@@ -541,7 +541,7 @@ static int do_i2b_bio(BIO *out, EVP_PKEY *pk, int ispub)
541 if (outlen < 0) 541 if (outlen < 0)
542 return -1; 542 return -1;
543 wrlen = BIO_write(out, tmp, outlen); 543 wrlen = BIO_write(out, tmp, outlen);
544 OPENSSL_free(tmp); 544 free(tmp);
545 if (wrlen == outlen) 545 if (wrlen == outlen)
546 return outlen; 546 return outlen;
547 return -1; 547 return -1;
@@ -746,7 +746,7 @@ static EVP_PKEY *do_PVK_body(const unsigned char **in,
746 PEMerr(PEM_F_DO_PVK_BODY,PEM_R_BAD_PASSWORD_READ); 746 PEMerr(PEM_F_DO_PVK_BODY,PEM_R_BAD_PASSWORD_READ);
747 return NULL; 747 return NULL;
748 } 748 }
749 enctmp = OPENSSL_malloc(keylen + 8); 749 enctmp = malloc(keylen + 8);
750 if (!enctmp) 750 if (!enctmp)
751 { 751 {
752 PEMerr(PEM_F_DO_PVK_BODY, ERR_R_MALLOC_FAILURE); 752 PEMerr(PEM_F_DO_PVK_BODY, ERR_R_MALLOC_FAILURE);
@@ -797,7 +797,7 @@ static EVP_PKEY *do_PVK_body(const unsigned char **in,
797 err: 797 err:
798 EVP_CIPHER_CTX_cleanup(&cctx); 798 EVP_CIPHER_CTX_cleanup(&cctx);
799 if (enctmp && saltlen) 799 if (enctmp && saltlen)
800 OPENSSL_free(enctmp); 800 free(enctmp);
801 return ret; 801 return ret;
802 } 802 }
803 803
@@ -819,7 +819,7 @@ EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u)
819 if (!do_PVK_header(&p, 24, 0, &saltlen, &keylen)) 819 if (!do_PVK_header(&p, 24, 0, &saltlen, &keylen))
820 return 0; 820 return 0;
821 buflen = (int) keylen + saltlen; 821 buflen = (int) keylen + saltlen;
822 buf = OPENSSL_malloc(buflen); 822 buf = malloc(buflen);
823 if (!buf) 823 if (!buf)
824 { 824 {
825 PEMerr(PEM_F_B2I_PVK_BIO, ERR_R_MALLOC_FAILURE); 825 PEMerr(PEM_F_B2I_PVK_BIO, ERR_R_MALLOC_FAILURE);
@@ -837,7 +837,7 @@ EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u)
837 if (buf) 837 if (buf)
838 { 838 {
839 OPENSSL_cleanse(buf, buflen); 839 OPENSSL_cleanse(buf, buflen);
840 OPENSSL_free(buf); 840 free(buf);
841 } 841 }
842 return ret; 842 return ret;
843 } 843 }
@@ -863,7 +863,7 @@ static int i2b_PVK(unsigned char **out, EVP_PKEY*pk, int enclevel,
863 p = *out; 863 p = *out;
864 else 864 else
865 { 865 {
866 p = OPENSSL_malloc(outlen); 866 p = malloc(outlen);
867 if (!p) 867 if (!p)
868 { 868 {
869 PEMerr(PEM_F_I2B_PVK,ERR_R_MALLOC_FAILURE); 869 PEMerr(PEM_F_I2B_PVK,ERR_R_MALLOC_FAILURE);
@@ -936,7 +936,7 @@ int i2b_PVK_bio(BIO *out, EVP_PKEY *pk, int enclevel,
936 if (outlen < 0) 936 if (outlen < 0)
937 return -1; 937 return -1;
938 wrlen = BIO_write(out, tmp, outlen); 938 wrlen = BIO_write(out, tmp, outlen);
939 OPENSSL_free(tmp); 939 free(tmp);
940 if (wrlen == outlen) 940 if (wrlen == outlen)
941 { 941 {
942 PEMerr(PEM_F_I2B_PVK_BIO, PEM_R_BIO_WRITE_FAILURE); 942 PEMerr(PEM_F_I2B_PVK_BIO, PEM_R_BIO_WRITE_FAILURE);
diff --git a/src/lib/libcrypto/pkcs12/p12_decr.c b/src/lib/libcrypto/pkcs12/p12_decr.c
index 9d3557e8d7..9a73c21866 100644
--- a/src/lib/libcrypto/pkcs12/p12_decr.c
+++ b/src/lib/libcrypto/pkcs12/p12_decr.c
@@ -65,7 +65,7 @@
65 65
66 66
67/* Encrypt/Decrypt a buffer based on password and algor, result in a 67/* Encrypt/Decrypt a buffer based on password and algor, result in a
68 * OPENSSL_malloc'ed buffer 68 * malloc'ed buffer
69 */ 69 */
70 70
71unsigned char * PKCS12_pbe_crypt(X509_ALGOR *algor, const char *pass, 71unsigned char * PKCS12_pbe_crypt(X509_ALGOR *algor, const char *pass,
@@ -84,14 +84,14 @@ unsigned char * PKCS12_pbe_crypt(X509_ALGOR *algor, const char *pass,
84 return NULL; 84 return NULL;
85 } 85 }
86 86
87 if(!(out = OPENSSL_malloc(inlen + EVP_CIPHER_CTX_block_size(&ctx)))) { 87 if(!(out = malloc(inlen + EVP_CIPHER_CTX_block_size(&ctx)))) {
88 PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,ERR_R_MALLOC_FAILURE); 88 PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,ERR_R_MALLOC_FAILURE);
89 goto err; 89 goto err;
90 } 90 }
91 91
92 if (!EVP_CipherUpdate(&ctx, out, &i, in, inlen)) 92 if (!EVP_CipherUpdate(&ctx, out, &i, in, inlen))
93 { 93 {
94 OPENSSL_free(out); 94 free(out);
95 out = NULL; 95 out = NULL;
96 PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,ERR_R_EVP_LIB); 96 PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,ERR_R_EVP_LIB);
97 goto err; 97 goto err;
@@ -99,7 +99,7 @@ unsigned char * PKCS12_pbe_crypt(X509_ALGOR *algor, const char *pass,
99 99
100 outlen = i; 100 outlen = i;
101 if(!EVP_CipherFinal_ex(&ctx, out + i, &i)) { 101 if(!EVP_CipherFinal_ex(&ctx, out + i, &i)) {
102 OPENSSL_free(out); 102 free(out);
103 out = NULL; 103 out = NULL;
104 PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,PKCS12_R_PKCS12_CIPHERFINAL_ERROR); 104 PKCS12err(PKCS12_F_PKCS12_PBE_CRYPT,PKCS12_R_PKCS12_CIPHERFINAL_ERROR);
105 goto err; 105 goto err;
@@ -146,7 +146,7 @@ void * PKCS12_item_decrypt_d2i(X509_ALGOR *algor, const ASN1_ITEM *it,
146 ret = ASN1_item_d2i(NULL, &p, outlen, it); 146 ret = ASN1_item_d2i(NULL, &p, outlen, it);
147 if (zbuf) OPENSSL_cleanse(out, outlen); 147 if (zbuf) OPENSSL_cleanse(out, outlen);
148 if(!ret) PKCS12err(PKCS12_F_PKCS12_ITEM_DECRYPT_D2I,PKCS12_R_DECODE_ERROR); 148 if(!ret) PKCS12err(PKCS12_F_PKCS12_ITEM_DECRYPT_D2I,PKCS12_R_DECODE_ERROR);
149 OPENSSL_free(out); 149 free(out);
150 return ret; 150 return ret;
151} 151}
152 152
@@ -173,11 +173,11 @@ ASN1_OCTET_STRING *PKCS12_item_i2d_encrypt(X509_ALGOR *algor, const ASN1_ITEM *i
173 if (!PKCS12_pbe_crypt(algor, pass, passlen, in, inlen, &oct->data, 173 if (!PKCS12_pbe_crypt(algor, pass, passlen, in, inlen, &oct->data,
174 &oct->length, 1)) { 174 &oct->length, 1)) {
175 PKCS12err(PKCS12_F_PKCS12_ITEM_I2D_ENCRYPT,PKCS12_R_ENCRYPT_ERROR); 175 PKCS12err(PKCS12_F_PKCS12_ITEM_I2D_ENCRYPT,PKCS12_R_ENCRYPT_ERROR);
176 OPENSSL_free(in); 176 free(in);
177 return NULL; 177 return NULL;
178 } 178 }
179 if (zbuf) OPENSSL_cleanse(in, inlen); 179 if (zbuf) OPENSSL_cleanse(in, inlen);
180 OPENSSL_free(in); 180 free(in);
181 return oct; 181 return oct;
182} 182}
183 183
diff --git a/src/lib/libcrypto/pkcs12/p12_key.c b/src/lib/libcrypto/pkcs12/p12_key.c
index 61d58502fd..b3672a95e5 100644
--- a/src/lib/libcrypto/pkcs12/p12_key.c
+++ b/src/lib/libcrypto/pkcs12/p12_key.c
@@ -95,7 +95,7 @@ int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt,
95 return 0; 95 return 0;
96 if(unipass) { 96 if(unipass) {
97 OPENSSL_cleanse(unipass, uniplen); /* Clear password from memory */ 97 OPENSSL_cleanse(unipass, uniplen); /* Clear password from memory */
98 OPENSSL_free(unipass); 98 free(unipass);
99 } 99 }
100 return ret; 100 return ret;
101} 101}
@@ -135,14 +135,14 @@ int PKCS12_key_gen_uni(unsigned char *pass, int passlen, unsigned char *salt,
135 u = EVP_MD_size (md_type); 135 u = EVP_MD_size (md_type);
136 if (u < 0) 136 if (u < 0)
137 return 0; 137 return 0;
138 D = OPENSSL_malloc (v); 138 D = malloc (v);
139 Ai = OPENSSL_malloc (u); 139 Ai = malloc (u);
140 B = OPENSSL_malloc (v + 1); 140 B = malloc (v + 1);
141 Slen = v * ((saltlen+v-1)/v); 141 Slen = v * ((saltlen+v-1)/v);
142 if(passlen) Plen = v * ((passlen+v-1)/v); 142 if(passlen) Plen = v * ((passlen+v-1)/v);
143 else Plen = 0; 143 else Plen = 0;
144 Ilen = Slen + Plen; 144 Ilen = Slen + Plen;
145 I = OPENSSL_malloc (Ilen); 145 I = malloc (Ilen);
146 Ij = BN_new(); 146 Ij = BN_new();
147 Bpl1 = BN_new(); 147 Bpl1 = BN_new();
148 if (!D || !Ai || !B || !I || !Ij || !Bpl1) 148 if (!D || !Ai || !B || !I || !Ij || !Bpl1)
@@ -209,10 +209,10 @@ err:
209 PKCS12err(PKCS12_F_PKCS12_KEY_GEN_UNI,ERR_R_MALLOC_FAILURE); 209 PKCS12err(PKCS12_F_PKCS12_KEY_GEN_UNI,ERR_R_MALLOC_FAILURE);
210 210
211end: 211end:
212 OPENSSL_free (Ai); 212 free (Ai);
213 OPENSSL_free (B); 213 free (B);
214 OPENSSL_free (D); 214 free (D);
215 OPENSSL_free (I); 215 free (I);
216 BN_free (Ij); 216 BN_free (Ij);
217 BN_free (Bpl1); 217 BN_free (Bpl1);
218 EVP_MD_CTX_cleanup(&ctx); 218 EVP_MD_CTX_cleanup(&ctx);
diff --git a/src/lib/libcrypto/pkcs12/p12_kiss.c b/src/lib/libcrypto/pkcs12/p12_kiss.c
index 206b1b0b18..bc1fcff45d 100644
--- a/src/lib/libcrypto/pkcs12/p12_kiss.c
+++ b/src/lib/libcrypto/pkcs12/p12_kiss.c
@@ -271,7 +271,7 @@ static int parse_bag(PKCS12_SAFEBAG *bag, const char *pass, int passlen,
271 len = ASN1_STRING_to_UTF8(&data, fname); 271 len = ASN1_STRING_to_UTF8(&data, fname);
272 if(len > 0) { 272 if(len > 0) {
273 r = X509_alias_set1(x509, data, len); 273 r = X509_alias_set1(x509, data, len);
274 OPENSSL_free(data); 274 free(data);
275 if (!r) 275 if (!r)
276 { 276 {
277 X509_free(x509); 277 X509_free(x509);
diff --git a/src/lib/libcrypto/pkcs12/p12_mutl.c b/src/lib/libcrypto/pkcs12/p12_mutl.c
index 96de1bd11e..98128e31cb 100644
--- a/src/lib/libcrypto/pkcs12/p12_mutl.c
+++ b/src/lib/libcrypto/pkcs12/p12_mutl.c
@@ -169,7 +169,7 @@ int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt, int saltlen,
169 } 169 }
170 if (!saltlen) saltlen = PKCS12_SALT_LEN; 170 if (!saltlen) saltlen = PKCS12_SALT_LEN;
171 p12->mac->salt->length = saltlen; 171 p12->mac->salt->length = saltlen;
172 if (!(p12->mac->salt->data = OPENSSL_malloc (saltlen))) { 172 if (!(p12->mac->salt->data = malloc (saltlen))) {
173 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE); 173 PKCS12err(PKCS12_F_PKCS12_SETUP_MAC, ERR_R_MALLOC_FAILURE);
174 return 0; 174 return 0;
175 } 175 }
diff --git a/src/lib/libcrypto/pkcs12/p12_utl.c b/src/lib/libcrypto/pkcs12/p12_utl.c
index 59c6f453f6..9c58036169 100644
--- a/src/lib/libcrypto/pkcs12/p12_utl.c
+++ b/src/lib/libcrypto/pkcs12/p12_utl.c
@@ -68,7 +68,7 @@ unsigned char *OPENSSL_asc2uni(const char *asc, int asclen, unsigned char **uni,
68 unsigned char *unitmp; 68 unsigned char *unitmp;
69 if (asclen == -1) asclen = strlen(asc); 69 if (asclen == -1) asclen = strlen(asc);
70 ulen = asclen*2 + 2; 70 ulen = asclen*2 + 2;
71 if (!(unitmp = OPENSSL_malloc(ulen))) return NULL; 71 if (!(unitmp = malloc(ulen))) return NULL;
72 for (i = 0; i < ulen - 2; i+=2) { 72 for (i = 0; i < ulen - 2; i+=2) {
73 unitmp[i] = 0; 73 unitmp[i] = 0;
74 unitmp[i + 1] = asc[i>>1]; 74 unitmp[i + 1] = asc[i>>1];
@@ -89,7 +89,7 @@ char *OPENSSL_uni2asc(unsigned char *uni, int unilen)
89 /* If no terminating zero allow for one */ 89 /* If no terminating zero allow for one */
90 if (!unilen || uni[unilen - 1]) asclen++; 90 if (!unilen || uni[unilen - 1]) asclen++;
91 uni++; 91 uni++;
92 if (!(asctmp = OPENSSL_malloc(asclen))) return NULL; 92 if (!(asctmp = malloc(asclen))) return NULL;
93 for (i = 0; i < unilen; i+=2) asctmp[i>>1] = uni[i]; 93 for (i = 0; i < unilen; i+=2) asctmp[i>>1] = uni[i];
94 asctmp[asclen - 1] = 0; 94 asctmp[asclen - 1] = 0;
95 return asctmp; 95 return asctmp;
diff --git a/src/lib/libcrypto/pkcs7/bio_ber.c b/src/lib/libcrypto/pkcs7/bio_ber.c
index 31973fcd1f..04dc5c9b96 100644
--- a/src/lib/libcrypto/pkcs7/bio_ber.c
+++ b/src/lib/libcrypto/pkcs7/bio_ber.c
@@ -128,7 +128,7 @@ static int ber_new(BIO *bi)
128 { 128 {
129 BIO_BER_CTX *ctx; 129 BIO_BER_CTX *ctx;
130 130
131 ctx=(BIO_BER_CTX *)OPENSSL_malloc(sizeof(BIO_BER_CTX)); 131 ctx=(BIO_BER_CTX *)malloc(sizeof(BIO_BER_CTX));
132 if (ctx == NULL) return(0); 132 if (ctx == NULL) return(0);
133 133
134 memset((char *)ctx,0,sizeof(BIO_BER_CTX)); 134 memset((char *)ctx,0,sizeof(BIO_BER_CTX));
@@ -146,7 +146,7 @@ static int ber_free(BIO *a)
146 if (a == NULL) return(0); 146 if (a == NULL) return(0);
147 b=(BIO_BER_CTX *)a->ptr; 147 b=(BIO_BER_CTX *)a->ptr;
148 OPENSSL_cleanse(a->ptr,sizeof(BIO_BER_CTX)); 148 OPENSSL_cleanse(a->ptr,sizeof(BIO_BER_CTX));
149 OPENSSL_free(a->ptr); 149 free(a->ptr);
150 a->ptr=NULL; 150 a->ptr=NULL;
151 a->init=0; 151 a->init=0;
152 a->flags=0; 152 a->flags=0;
diff --git a/src/lib/libcrypto/pkcs7/pk7_doit.c b/src/lib/libcrypto/pkcs7/pk7_doit.c
index 77fda3b82a..396a863f3b 100644
--- a/src/lib/libcrypto/pkcs7/pk7_doit.c
+++ b/src/lib/libcrypto/pkcs7/pk7_doit.c
@@ -169,7 +169,7 @@ static int pkcs7_encode_rinfo(PKCS7_RECIP_INFO *ri,
169 if (EVP_PKEY_encrypt(pctx, NULL, &eklen, key, keylen) <= 0) 169 if (EVP_PKEY_encrypt(pctx, NULL, &eklen, key, keylen) <= 0)
170 goto err; 170 goto err;
171 171
172 ek = OPENSSL_malloc(eklen); 172 ek = malloc(eklen);
173 173
174 if (ek == NULL) 174 if (ek == NULL)
175 { 175 {
@@ -191,7 +191,7 @@ static int pkcs7_encode_rinfo(PKCS7_RECIP_INFO *ri,
191 if (pctx) 191 if (pctx)
192 EVP_PKEY_CTX_free(pctx); 192 EVP_PKEY_CTX_free(pctx);
193 if (ek) 193 if (ek)
194 OPENSSL_free(ek); 194 free(ek);
195 return ret; 195 return ret;
196 196
197 } 197 }
@@ -224,7 +224,7 @@ static int pkcs7_decrypt_rinfo(unsigned char **pek, int *peklen,
224 ri->enc_key->data, ri->enc_key->length) <= 0) 224 ri->enc_key->data, ri->enc_key->length) <= 0)
225 goto err; 225 goto err;
226 226
227 ek = OPENSSL_malloc(eklen); 227 ek = malloc(eklen);
228 228
229 if (ek == NULL) 229 if (ek == NULL)
230 { 230 {
@@ -245,7 +245,7 @@ static int pkcs7_decrypt_rinfo(unsigned char **pek, int *peklen,
245 if (*pek) 245 if (*pek)
246 { 246 {
247 OPENSSL_cleanse(*pek, *peklen); 247 OPENSSL_cleanse(*pek, *peklen);
248 OPENSSL_free(*pek); 248 free(*pek);
249 } 249 }
250 250
251 *pek = ek; 251 *pek = ek;
@@ -255,7 +255,7 @@ static int pkcs7_decrypt_rinfo(unsigned char **pek, int *peklen,
255 if (pctx) 255 if (pctx)
256 EVP_PKEY_CTX_free(pctx); 256 EVP_PKEY_CTX_free(pctx);
257 if (!ret && ek) 257 if (!ret && ek)
258 OPENSSL_free(ek); 258 free(ek);
259 259
260 return ret; 260 return ret;
261 } 261 }
@@ -573,7 +573,7 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
573 goto err; 573 goto err;
574 /* Generate random key as MMA defence */ 574 /* Generate random key as MMA defence */
575 tkeylen = EVP_CIPHER_CTX_key_length(evp_ctx); 575 tkeylen = EVP_CIPHER_CTX_key_length(evp_ctx);
576 tkey = OPENSSL_malloc(tkeylen); 576 tkey = malloc(tkeylen);
577 if (!tkey) 577 if (!tkey)
578 goto err; 578 goto err;
579 if (EVP_CIPHER_CTX_rand_key(evp_ctx, tkey) <= 0) 579 if (EVP_CIPHER_CTX_rand_key(evp_ctx, tkey) <= 0)
@@ -594,7 +594,7 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
594 { 594 {
595 /* Use random key as MMA defence */ 595 /* Use random key as MMA defence */
596 OPENSSL_cleanse(ek, eklen); 596 OPENSSL_cleanse(ek, eklen);
597 OPENSSL_free(ek); 597 free(ek);
598 ek = tkey; 598 ek = tkey;
599 eklen = tkeylen; 599 eklen = tkeylen;
600 tkey = NULL; 600 tkey = NULL;
@@ -608,13 +608,13 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
608 if (ek) 608 if (ek)
609 { 609 {
610 OPENSSL_cleanse(ek,eklen); 610 OPENSSL_cleanse(ek,eklen);
611 OPENSSL_free(ek); 611 free(ek);
612 ek = NULL; 612 ek = NULL;
613 } 613 }
614 if (tkey) 614 if (tkey)
615 { 615 {
616 OPENSSL_cleanse(tkey,tkeylen); 616 OPENSSL_cleanse(tkey,tkeylen);
617 OPENSSL_free(tkey); 617 free(tkey);
618 tkey = NULL; 618 tkey = NULL;
619 } 619 }
620 620
@@ -661,12 +661,12 @@ err:
661 if (ek) 661 if (ek)
662 { 662 {
663 OPENSSL_cleanse(ek,eklen); 663 OPENSSL_cleanse(ek,eklen);
664 OPENSSL_free(ek); 664 free(ek);
665 } 665 }
666 if (tkey) 666 if (tkey)
667 { 667 {
668 OPENSSL_cleanse(tkey,tkeylen); 668 OPENSSL_cleanse(tkey,tkeylen);
669 OPENSSL_free(tkey); 669 free(tkey);
670 } 670 }
671 if (out != NULL) BIO_free_all(out); 671 if (out != NULL) BIO_free_all(out);
672 if (btmp != NULL) BIO_free_all(btmp); 672 if (btmp != NULL) BIO_free_all(btmp);
@@ -846,7 +846,7 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
846 unsigned char *abuf = NULL; 846 unsigned char *abuf = NULL;
847 unsigned int abuflen; 847 unsigned int abuflen;
848 abuflen = EVP_PKEY_size(si->pkey); 848 abuflen = EVP_PKEY_size(si->pkey);
849 abuf = OPENSSL_malloc(abuflen); 849 abuf = malloc(abuflen);
850 if (!abuf) 850 if (!abuf)
851 goto err; 851 goto err;
852 852
@@ -927,10 +927,10 @@ int PKCS7_SIGNER_INFO_sign(PKCS7_SIGNER_INFO *si)
927 goto err; 927 goto err;
928 if (EVP_DigestSignUpdate(&mctx,abuf,alen) <= 0) 928 if (EVP_DigestSignUpdate(&mctx,abuf,alen) <= 0)
929 goto err; 929 goto err;
930 OPENSSL_free(abuf); 930 free(abuf);
931 if (EVP_DigestSignFinal(&mctx, NULL, &siglen) <= 0) 931 if (EVP_DigestSignFinal(&mctx, NULL, &siglen) <= 0)
932 goto err; 932 goto err;
933 abuf = OPENSSL_malloc(siglen); 933 abuf = malloc(siglen);
934 if(!abuf) 934 if(!abuf)
935 goto err; 935 goto err;
936 if (EVP_DigestSignFinal(&mctx, abuf, &siglen) <= 0) 936 if (EVP_DigestSignFinal(&mctx, abuf, &siglen) <= 0)
@@ -951,7 +951,7 @@ int PKCS7_SIGNER_INFO_sign(PKCS7_SIGNER_INFO *si)
951 951
952 err: 952 err:
953 if (abuf) 953 if (abuf)
954 OPENSSL_free(abuf); 954 free(abuf);
955 EVP_MD_CTX_cleanup(&mctx); 955 EVP_MD_CTX_cleanup(&mctx);
956 return 0; 956 return 0;
957 957
@@ -1113,7 +1113,7 @@ for (ii=0; ii<md_len; ii++) printf("%02X",md_dat[ii]); printf(" calc\n");
1113 if (!EVP_VerifyUpdate(&mdc_tmp, abuf, alen)) 1113 if (!EVP_VerifyUpdate(&mdc_tmp, abuf, alen))
1114 goto err; 1114 goto err;
1115 1115
1116 OPENSSL_free(abuf); 1116 free(abuf);
1117 } 1117 }
1118 1118
1119 os=si->enc_digest; 1119 os=si->enc_digest;
diff --git a/src/lib/libcrypto/pqueue/pqueue.c b/src/lib/libcrypto/pqueue/pqueue.c
index eab13a1250..3ca8e049e4 100644
--- a/src/lib/libcrypto/pqueue/pqueue.c
+++ b/src/lib/libcrypto/pqueue/pqueue.c
@@ -70,7 +70,7 @@ typedef struct _pqueue
70pitem * 70pitem *
71pitem_new(unsigned char *prio64be, void *data) 71pitem_new(unsigned char *prio64be, void *data)
72 { 72 {
73 pitem *item = (pitem *) OPENSSL_malloc(sizeof(pitem)); 73 pitem *item = (pitem *) malloc(sizeof(pitem));
74 if (item == NULL) return NULL; 74 if (item == NULL) return NULL;
75 75
76 memcpy(item->priority,prio64be,sizeof(item->priority)); 76 memcpy(item->priority,prio64be,sizeof(item->priority));
@@ -86,13 +86,13 @@ pitem_free(pitem *item)
86 { 86 {
87 if (item == NULL) return; 87 if (item == NULL) return;
88 88
89 OPENSSL_free(item); 89 free(item);
90 } 90 }
91 91
92pqueue_s * 92pqueue_s *
93pqueue_new() 93pqueue_new()
94 { 94 {
95 pqueue_s *pq = (pqueue_s *) OPENSSL_malloc(sizeof(pqueue_s)); 95 pqueue_s *pq = (pqueue_s *) malloc(sizeof(pqueue_s));
96 if (pq == NULL) return NULL; 96 if (pq == NULL) return NULL;
97 97
98 memset(pq, 0x00, sizeof(pqueue_s)); 98 memset(pq, 0x00, sizeof(pqueue_s));
@@ -104,7 +104,7 @@ pqueue_free(pqueue_s *pq)
104 { 104 {
105 if (pq == NULL) return; 105 if (pq == NULL) return;
106 106
107 OPENSSL_free(pq); 107 free(pq);
108 } 108 }
109 109
110pitem * 110pitem *
diff --git a/src/lib/libcrypto/rsa/rsa_ameth.c b/src/lib/libcrypto/rsa/rsa_ameth.c
index 5a2062f903..fdd11835ad 100644
--- a/src/lib/libcrypto/rsa/rsa_ameth.c
+++ b/src/lib/libcrypto/rsa/rsa_ameth.c
@@ -78,7 +78,7 @@ static int rsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
78 V_ASN1_NULL, NULL, penc, penclen)) 78 V_ASN1_NULL, NULL, penc, penclen))
79 return 1; 79 return 1;
80 80
81 OPENSSL_free(penc); 81 free(penc);
82 return 0; 82 return 0;
83 } 83 }
84 84
@@ -201,7 +201,7 @@ static int do_rsa_print(BIO *bp, const RSA *x, int off, int priv)
201 update_buflen(x->iqmp, &buf_len); 201 update_buflen(x->iqmp, &buf_len);
202 } 202 }
203 203
204 m=(unsigned char *)OPENSSL_malloc(buf_len+10); 204 m=(unsigned char *)malloc(buf_len+10);
205 if (m == NULL) 205 if (m == NULL)
206 { 206 {
207 RSAerr(RSA_F_DO_RSA_PRINT,ERR_R_MALLOC_FAILURE); 207 RSAerr(RSA_F_DO_RSA_PRINT,ERR_R_MALLOC_FAILURE);
@@ -248,7 +248,7 @@ static int do_rsa_print(BIO *bp, const RSA *x, int off, int priv)
248 } 248 }
249 ret=1; 249 ret=1;
250err: 250err:
251 if (m != NULL) OPENSSL_free(m); 251 if (m != NULL) free(m);
252 return(ret); 252 return(ret);
253 } 253 }
254 254
diff --git a/src/lib/libcrypto/rsa/rsa_eay.c b/src/lib/libcrypto/rsa/rsa_eay.c
index 88ee2cb557..dcf0c16a8f 100644
--- a/src/lib/libcrypto/rsa/rsa_eay.c
+++ b/src/lib/libcrypto/rsa/rsa_eay.c
@@ -185,7 +185,7 @@ static int RSA_eay_public_encrypt(int flen, const unsigned char *from,
185 f = BN_CTX_get(ctx); 185 f = BN_CTX_get(ctx);
186 ret = BN_CTX_get(ctx); 186 ret = BN_CTX_get(ctx);
187 num=BN_num_bytes(rsa->n); 187 num=BN_num_bytes(rsa->n);
188 buf = OPENSSL_malloc(num); 188 buf = malloc(num);
189 if (!f || !ret || !buf) 189 if (!f || !ret || !buf)
190 { 190 {
191 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,ERR_R_MALLOC_FAILURE); 191 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,ERR_R_MALLOC_FAILURE);
@@ -247,7 +247,7 @@ err:
247 if (buf != NULL) 247 if (buf != NULL)
248 { 248 {
249 OPENSSL_cleanse(buf,num); 249 OPENSSL_cleanse(buf,num);
250 OPENSSL_free(buf); 250 free(buf);
251 } 251 }
252 return(r); 252 return(r);
253 } 253 }
@@ -366,7 +366,7 @@ static int RSA_eay_private_encrypt(int flen, const unsigned char *from,
366 f = BN_CTX_get(ctx); 366 f = BN_CTX_get(ctx);
367 ret = BN_CTX_get(ctx); 367 ret = BN_CTX_get(ctx);
368 num = BN_num_bytes(rsa->n); 368 num = BN_num_bytes(rsa->n);
369 buf = OPENSSL_malloc(num); 369 buf = malloc(num);
370 if(!f || !ret || !buf) 370 if(!f || !ret || !buf)
371 { 371 {
372 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,ERR_R_MALLOC_FAILURE); 372 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,ERR_R_MALLOC_FAILURE);
@@ -484,7 +484,7 @@ err:
484 if (buf != NULL) 484 if (buf != NULL)
485 { 485 {
486 OPENSSL_cleanse(buf,num); 486 OPENSSL_cleanse(buf,num);
487 OPENSSL_free(buf); 487 free(buf);
488 } 488 }
489 return(r); 489 return(r);
490 } 490 }
@@ -509,7 +509,7 @@ static int RSA_eay_private_decrypt(int flen, const unsigned char *from,
509 f = BN_CTX_get(ctx); 509 f = BN_CTX_get(ctx);
510 ret = BN_CTX_get(ctx); 510 ret = BN_CTX_get(ctx);
511 num = BN_num_bytes(rsa->n); 511 num = BN_num_bytes(rsa->n);
512 buf = OPENSSL_malloc(num); 512 buf = malloc(num);
513 if(!f || !ret || !buf) 513 if(!f || !ret || !buf)
514 { 514 {
515 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,ERR_R_MALLOC_FAILURE); 515 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,ERR_R_MALLOC_FAILURE);
@@ -624,7 +624,7 @@ err:
624 if (buf != NULL) 624 if (buf != NULL)
625 { 625 {
626 OPENSSL_cleanse(buf,num); 626 OPENSSL_cleanse(buf,num);
627 OPENSSL_free(buf); 627 free(buf);
628 } 628 }
629 return(r); 629 return(r);
630 } 630 }
@@ -666,7 +666,7 @@ static int RSA_eay_public_decrypt(int flen, const unsigned char *from,
666 f = BN_CTX_get(ctx); 666 f = BN_CTX_get(ctx);
667 ret = BN_CTX_get(ctx); 667 ret = BN_CTX_get(ctx);
668 num=BN_num_bytes(rsa->n); 668 num=BN_num_bytes(rsa->n);
669 buf = OPENSSL_malloc(num); 669 buf = malloc(num);
670 if(!f || !ret || !buf) 670 if(!f || !ret || !buf)
671 { 671 {
672 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,ERR_R_MALLOC_FAILURE); 672 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,ERR_R_MALLOC_FAILURE);
@@ -729,7 +729,7 @@ err:
729 if (buf != NULL) 729 if (buf != NULL)
730 { 730 {
731 OPENSSL_cleanse(buf,num); 731 OPENSSL_cleanse(buf,num);
732 OPENSSL_free(buf); 732 free(buf);
733 } 733 }
734 return(r); 734 return(r);
735 } 735 }
diff --git a/src/lib/libcrypto/rsa/rsa_lib.c b/src/lib/libcrypto/rsa/rsa_lib.c
index 9e3f7dafcd..e99a3627dc 100644
--- a/src/lib/libcrypto/rsa/rsa_lib.c
+++ b/src/lib/libcrypto/rsa/rsa_lib.c
@@ -125,7 +125,7 @@ RSA *RSA_new_method(ENGINE *engine)
125 { 125 {
126 RSA *ret; 126 RSA *ret;
127 127
128 ret=(RSA *)OPENSSL_malloc(sizeof(RSA)); 128 ret=(RSA *)malloc(sizeof(RSA));
129 if (ret == NULL) 129 if (ret == NULL)
130 { 130 {
131 RSAerr(RSA_F_RSA_NEW_METHOD,ERR_R_MALLOC_FAILURE); 131 RSAerr(RSA_F_RSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);
@@ -139,7 +139,7 @@ RSA *RSA_new_method(ENGINE *engine)
139 if (!ENGINE_init(engine)) 139 if (!ENGINE_init(engine))
140 { 140 {
141 RSAerr(RSA_F_RSA_NEW_METHOD, ERR_R_ENGINE_LIB); 141 RSAerr(RSA_F_RSA_NEW_METHOD, ERR_R_ENGINE_LIB);
142 OPENSSL_free(ret); 142 free(ret);
143 return NULL; 143 return NULL;
144 } 144 }
145 ret->engine = engine; 145 ret->engine = engine;
@@ -154,7 +154,7 @@ RSA *RSA_new_method(ENGINE *engine)
154 RSAerr(RSA_F_RSA_NEW_METHOD, 154 RSAerr(RSA_F_RSA_NEW_METHOD,
155 ERR_R_ENGINE_LIB); 155 ERR_R_ENGINE_LIB);
156 ENGINE_finish(ret->engine); 156 ENGINE_finish(ret->engine);
157 OPENSSL_free(ret); 157 free(ret);
158 return NULL; 158 return NULL;
159 } 159 }
160 } 160 }
@@ -184,7 +184,7 @@ RSA *RSA_new_method(ENGINE *engine)
184 if (ret->engine) 184 if (ret->engine)
185 ENGINE_finish(ret->engine); 185 ENGINE_finish(ret->engine);
186#endif 186#endif
187 OPENSSL_free(ret); 187 free(ret);
188 return(NULL); 188 return(NULL);
189 } 189 }
190 190
@@ -195,7 +195,7 @@ RSA *RSA_new_method(ENGINE *engine)
195 ENGINE_finish(ret->engine); 195 ENGINE_finish(ret->engine);
196#endif 196#endif
197 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data); 197 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data);
198 OPENSSL_free(ret); 198 free(ret);
199 ret=NULL; 199 ret=NULL;
200 } 200 }
201 return(ret); 201 return(ret);
@@ -240,7 +240,7 @@ void RSA_free(RSA *r)
240 if (r->blinding != NULL) BN_BLINDING_free(r->blinding); 240 if (r->blinding != NULL) BN_BLINDING_free(r->blinding);
241 if (r->mt_blinding != NULL) BN_BLINDING_free(r->mt_blinding); 241 if (r->mt_blinding != NULL) BN_BLINDING_free(r->mt_blinding);
242 if (r->bignum_data != NULL) OPENSSL_free_locked(r->bignum_data); 242 if (r->bignum_data != NULL) OPENSSL_free_locked(r->bignum_data);
243 OPENSSL_free(r); 243 free(r);
244 } 244 }
245 245
246int RSA_up_ref(RSA *r) 246int RSA_up_ref(RSA *r)
diff --git a/src/lib/libcrypto/rsa/rsa_oaep.c b/src/lib/libcrypto/rsa/rsa_oaep.c
index af4d24a56e..a107e89b81 100644
--- a/src/lib/libcrypto/rsa/rsa_oaep.c
+++ b/src/lib/libcrypto/rsa/rsa_oaep.c
@@ -70,7 +70,7 @@ int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
70 20); 70 20);
71#endif 71#endif
72 72
73 dbmask = OPENSSL_malloc(emlen - SHA_DIGEST_LENGTH); 73 dbmask = malloc(emlen - SHA_DIGEST_LENGTH);
74 if (dbmask == NULL) 74 if (dbmask == NULL)
75 { 75 {
76 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE); 76 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE);
@@ -87,7 +87,7 @@ int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
87 for (i = 0; i < SHA_DIGEST_LENGTH; i++) 87 for (i = 0; i < SHA_DIGEST_LENGTH; i++)
88 seed[i] ^= seedmask[i]; 88 seed[i] ^= seedmask[i];
89 89
90 OPENSSL_free(dbmask); 90 free(dbmask);
91 return 1; 91 return 1;
92 } 92 }
93 93
@@ -121,7 +121,7 @@ int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
121 } 121 }
122 122
123 dblen = num - SHA_DIGEST_LENGTH; 123 dblen = num - SHA_DIGEST_LENGTH;
124 db = OPENSSL_malloc(dblen + num); 124 db = malloc(dblen + num);
125 if (db == NULL) 125 if (db == NULL)
126 { 126 {
127 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, ERR_R_MALLOC_FAILURE); 127 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, ERR_R_MALLOC_FAILURE);
@@ -172,14 +172,14 @@ int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
172 memcpy(to, db + i, mlen); 172 memcpy(to, db + i, mlen);
173 } 173 }
174 } 174 }
175 OPENSSL_free(db); 175 free(db);
176 return mlen; 176 return mlen;
177 177
178decoding_err: 178decoding_err:
179 /* to avoid chosen ciphertext attacks, the error message should not reveal 179 /* to avoid chosen ciphertext attacks, the error message should not reveal
180 * which kind of decoding error happened */ 180 * which kind of decoding error happened */
181 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, RSA_R_OAEP_DECODING_ERROR); 181 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, RSA_R_OAEP_DECODING_ERROR);
182 if (db != NULL) OPENSSL_free(db); 182 if (db != NULL) free(db);
183 return -1; 183 return -1;
184 } 184 }
185 185
diff --git a/src/lib/libcrypto/rsa/rsa_pmeth.c b/src/lib/libcrypto/rsa/rsa_pmeth.c
index d706d35ff6..adec632b3b 100644
--- a/src/lib/libcrypto/rsa/rsa_pmeth.c
+++ b/src/lib/libcrypto/rsa/rsa_pmeth.c
@@ -93,7 +93,7 @@ typedef struct
93static int pkey_rsa_init(EVP_PKEY_CTX *ctx) 93static int pkey_rsa_init(EVP_PKEY_CTX *ctx)
94 { 94 {
95 RSA_PKEY_CTX *rctx; 95 RSA_PKEY_CTX *rctx;
96 rctx = OPENSSL_malloc(sizeof(RSA_PKEY_CTX)); 96 rctx = malloc(sizeof(RSA_PKEY_CTX));
97 if (!rctx) 97 if (!rctx)
98 return 0; 98 return 0;
99 rctx->nbits = 1024; 99 rctx->nbits = 1024;
@@ -135,7 +135,7 @@ static int setup_tbuf(RSA_PKEY_CTX *ctx, EVP_PKEY_CTX *pk)
135 { 135 {
136 if (ctx->tbuf) 136 if (ctx->tbuf)
137 return 1; 137 return 1;
138 ctx->tbuf = OPENSSL_malloc(EVP_PKEY_size(pk->pkey)); 138 ctx->tbuf = malloc(EVP_PKEY_size(pk->pkey));
139 if (!ctx->tbuf) 139 if (!ctx->tbuf)
140 return 0; 140 return 0;
141 return 1; 141 return 1;
@@ -149,8 +149,8 @@ static void pkey_rsa_cleanup(EVP_PKEY_CTX *ctx)
149 if (rctx->pub_exp) 149 if (rctx->pub_exp)
150 BN_free(rctx->pub_exp); 150 BN_free(rctx->pub_exp);
151 if (rctx->tbuf) 151 if (rctx->tbuf)
152 OPENSSL_free(rctx->tbuf); 152 free(rctx->tbuf);
153 OPENSSL_free(rctx); 153 free(rctx);
154 } 154 }
155 } 155 }
156static int pkey_rsa_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, 156static int pkey_rsa_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
diff --git a/src/lib/libcrypto/rsa/rsa_pss.c b/src/lib/libcrypto/rsa/rsa_pss.c
index 5f9f533d0c..75e8c18533 100644
--- a/src/lib/libcrypto/rsa/rsa_pss.c
+++ b/src/lib/libcrypto/rsa/rsa_pss.c
@@ -133,7 +133,7 @@ int RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const unsigned char *mHash,
133 } 133 }
134 maskedDBLen = emLen - hLen - 1; 134 maskedDBLen = emLen - hLen - 1;
135 H = EM + maskedDBLen; 135 H = EM + maskedDBLen;
136 DB = OPENSSL_malloc(maskedDBLen); 136 DB = malloc(maskedDBLen);
137 if (!DB) 137 if (!DB)
138 { 138 {
139 RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, ERR_R_MALLOC_FAILURE); 139 RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, ERR_R_MALLOC_FAILURE);
@@ -177,7 +177,7 @@ int RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const unsigned char *mHash,
177 177
178 err: 178 err:
179 if (DB) 179 if (DB)
180 OPENSSL_free(DB); 180 free(DB);
181 EVP_MD_CTX_cleanup(&ctx); 181 EVP_MD_CTX_cleanup(&ctx);
182 182
183 return ret; 183 return ret;
@@ -239,7 +239,7 @@ int RSA_padding_add_PKCS1_PSS_mgf1(RSA *rsa, unsigned char *EM,
239 } 239 }
240 if (sLen > 0) 240 if (sLen > 0)
241 { 241 {
242 salt = OPENSSL_malloc(sLen); 242 salt = malloc(sLen);
243 if (!salt) 243 if (!salt)
244 { 244 {
245 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_PSS_MGF1,ERR_R_MALLOC_FAILURE); 245 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_PSS_MGF1,ERR_R_MALLOC_FAILURE);
@@ -289,7 +289,7 @@ int RSA_padding_add_PKCS1_PSS_mgf1(RSA *rsa, unsigned char *EM,
289 289
290 err: 290 err:
291 if (salt) 291 if (salt)
292 OPENSSL_free(salt); 292 free(salt);
293 293
294 return ret; 294 return ret;
295 295
diff --git a/src/lib/libcrypto/rsa/rsa_saos.c b/src/lib/libcrypto/rsa/rsa_saos.c
index f98e0a80a6..ee5473a184 100644
--- a/src/lib/libcrypto/rsa/rsa_saos.c
+++ b/src/lib/libcrypto/rsa/rsa_saos.c
@@ -82,7 +82,7 @@ int RSA_sign_ASN1_OCTET_STRING(int type,
82 RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY); 82 RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY);
83 return(0); 83 return(0);
84 } 84 }
85 s=(unsigned char *)OPENSSL_malloc((unsigned int)j+1); 85 s=(unsigned char *)malloc((unsigned int)j+1);
86 if (s == NULL) 86 if (s == NULL)
87 { 87 {
88 RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE); 88 RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE);
@@ -97,7 +97,7 @@ int RSA_sign_ASN1_OCTET_STRING(int type,
97 *siglen=i; 97 *siglen=i;
98 98
99 OPENSSL_cleanse(s,(unsigned int)j+1); 99 OPENSSL_cleanse(s,(unsigned int)j+1);
100 OPENSSL_free(s); 100 free(s);
101 return(ret); 101 return(ret);
102 } 102 }
103 103
@@ -117,7 +117,7 @@ int RSA_verify_ASN1_OCTET_STRING(int dtype,
117 return(0); 117 return(0);
118 } 118 }
119 119
120 s=(unsigned char *)OPENSSL_malloc((unsigned int)siglen); 120 s=(unsigned char *)malloc((unsigned int)siglen);
121 if (s == NULL) 121 if (s == NULL)
122 { 122 {
123 RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE); 123 RSAerr(RSA_F_RSA_VERIFY_ASN1_OCTET_STRING,ERR_R_MALLOC_FAILURE);
@@ -143,7 +143,7 @@ err:
143 if (s != NULL) 143 if (s != NULL)
144 { 144 {
145 OPENSSL_cleanse(s,(unsigned int)siglen); 145 OPENSSL_cleanse(s,(unsigned int)siglen);
146 OPENSSL_free(s); 146 free(s);
147 } 147 }
148 return(ret); 148 return(ret);
149 } 149 }
diff --git a/src/lib/libcrypto/rsa/rsa_sign.c b/src/lib/libcrypto/rsa/rsa_sign.c
index fa3239ab30..71d6bb3ce4 100644
--- a/src/lib/libcrypto/rsa/rsa_sign.c
+++ b/src/lib/libcrypto/rsa/rsa_sign.c
@@ -120,7 +120,7 @@ int RSA_sign(int type, const unsigned char *m, unsigned int m_len,
120 return(0); 120 return(0);
121 } 121 }
122 if(type != NID_md5_sha1) { 122 if(type != NID_md5_sha1) {
123 tmps=(unsigned char *)OPENSSL_malloc((unsigned int)j+1); 123 tmps=(unsigned char *)malloc((unsigned int)j+1);
124 if (tmps == NULL) 124 if (tmps == NULL)
125 { 125 {
126 RSAerr(RSA_F_RSA_SIGN,ERR_R_MALLOC_FAILURE); 126 RSAerr(RSA_F_RSA_SIGN,ERR_R_MALLOC_FAILURE);
@@ -138,7 +138,7 @@ int RSA_sign(int type, const unsigned char *m, unsigned int m_len,
138 138
139 if(type != NID_md5_sha1) { 139 if(type != NID_md5_sha1) {
140 OPENSSL_cleanse(tmps,(unsigned int)j+1); 140 OPENSSL_cleanse(tmps,(unsigned int)j+1);
141 OPENSSL_free(tmps); 141 free(tmps);
142 } 142 }
143 return(ret); 143 return(ret);
144 } 144 }
@@ -169,7 +169,7 @@ int int_rsa_verify(int dtype, const unsigned char *m,
169 return 1; 169 return 1;
170 } 170 }
171 171
172 s=(unsigned char *)OPENSSL_malloc((unsigned int)siglen); 172 s=(unsigned char *)malloc((unsigned int)siglen);
173 if (s == NULL) 173 if (s == NULL)
174 { 174 {
175 RSAerr(RSA_F_INT_RSA_VERIFY,ERR_R_MALLOC_FAILURE); 175 RSAerr(RSA_F_INT_RSA_VERIFY,ERR_R_MALLOC_FAILURE);
@@ -281,7 +281,7 @@ err:
281 if (s != NULL) 281 if (s != NULL)
282 { 282 {
283 OPENSSL_cleanse(s,(unsigned int)siglen); 283 OPENSSL_cleanse(s,(unsigned int)siglen);
284 OPENSSL_free(s); 284 free(s);
285 } 285 }
286 return(ret); 286 return(ret);
287 } 287 }
diff --git a/src/lib/libcrypto/srp/srp_lib.c b/src/lib/libcrypto/srp/srp_lib.c
index 7c1dcc5111..8cc94f51db 100644
--- a/src/lib/libcrypto/srp/srp_lib.c
+++ b/src/lib/libcrypto/srp/srp_lib.c
@@ -89,7 +89,7 @@ static BIGNUM *srp_Calc_k(BIGNUM *N, BIGNUM *g)
89 int longg ; 89 int longg ;
90 int longN = BN_num_bytes(N); 90 int longN = BN_num_bytes(N);
91 91
92 if ((tmp = OPENSSL_malloc(longN)) == NULL) 92 if ((tmp = malloc(longN)) == NULL)
93 return NULL; 93 return NULL;
94 BN_bn2bin(N,tmp) ; 94 BN_bn2bin(N,tmp) ;
95 95
@@ -102,7 +102,7 @@ static BIGNUM *srp_Calc_k(BIGNUM *N, BIGNUM *g)
102 /* use the zeros behind to pad on left */ 102 /* use the zeros behind to pad on left */
103 EVP_DigestUpdate(&ctxt, tmp + longg, longN-longg); 103 EVP_DigestUpdate(&ctxt, tmp + longg, longN-longg);
104 EVP_DigestUpdate(&ctxt, tmp, longg); 104 EVP_DigestUpdate(&ctxt, tmp, longg);
105 OPENSSL_free(tmp); 105 free(tmp);
106 106
107 EVP_DigestFinal_ex(&ctxt, digest, NULL); 107 EVP_DigestFinal_ex(&ctxt, digest, NULL);
108 EVP_MD_CTX_cleanup(&ctxt); 108 EVP_MD_CTX_cleanup(&ctxt);
@@ -123,7 +123,7 @@ BIGNUM *SRP_Calc_u(BIGNUM *A, BIGNUM *B, BIGNUM *N)
123 123
124 longN= BN_num_bytes(N); 124 longN= BN_num_bytes(N);
125 125
126 if ((cAB = OPENSSL_malloc(2*longN)) == NULL) 126 if ((cAB = malloc(2*longN)) == NULL)
127 return NULL; 127 return NULL;
128 128
129 memset(cAB, 0, longN); 129 memset(cAB, 0, longN);
@@ -132,7 +132,7 @@ BIGNUM *SRP_Calc_u(BIGNUM *A, BIGNUM *B, BIGNUM *N)
132 EVP_DigestInit_ex(&ctxt, EVP_sha1(), NULL); 132 EVP_DigestInit_ex(&ctxt, EVP_sha1(), NULL);
133 EVP_DigestUpdate(&ctxt, cAB + BN_bn2bin(A,cAB+longN), longN); 133 EVP_DigestUpdate(&ctxt, cAB + BN_bn2bin(A,cAB+longN), longN);
134 EVP_DigestUpdate(&ctxt, cAB + BN_bn2bin(B,cAB+longN), longN); 134 EVP_DigestUpdate(&ctxt, cAB + BN_bn2bin(B,cAB+longN), longN);
135 OPENSSL_free(cAB); 135 free(cAB);
136 EVP_DigestFinal_ex(&ctxt, cu, NULL); 136 EVP_DigestFinal_ex(&ctxt, cu, NULL);
137 EVP_MD_CTX_cleanup(&ctxt); 137 EVP_MD_CTX_cleanup(&ctxt);
138 138
@@ -215,7 +215,7 @@ BIGNUM *SRP_Calc_x(BIGNUM *s, const char *user, const char *pass)
215 (pass == NULL)) 215 (pass == NULL))
216 return NULL; 216 return NULL;
217 217
218 if ((cs = OPENSSL_malloc(BN_num_bytes(s))) == NULL) 218 if ((cs = malloc(BN_num_bytes(s))) == NULL)
219 return NULL; 219 return NULL;
220 220
221 EVP_MD_CTX_init(&ctxt); 221 EVP_MD_CTX_init(&ctxt);
@@ -228,7 +228,7 @@ BIGNUM *SRP_Calc_x(BIGNUM *s, const char *user, const char *pass)
228 EVP_DigestInit_ex(&ctxt, EVP_sha1(), NULL); 228 EVP_DigestInit_ex(&ctxt, EVP_sha1(), NULL);
229 BN_bn2bin(s,cs); 229 BN_bn2bin(s,cs);
230 EVP_DigestUpdate(&ctxt, cs, BN_num_bytes(s)); 230 EVP_DigestUpdate(&ctxt, cs, BN_num_bytes(s));
231 OPENSSL_free(cs); 231 free(cs);
232 EVP_DigestUpdate(&ctxt, dig, sizeof(dig)); 232 EVP_DigestUpdate(&ctxt, dig, sizeof(dig));
233 EVP_DigestFinal_ex(&ctxt, dig, NULL); 233 EVP_DigestFinal_ex(&ctxt, dig, NULL);
234 EVP_MD_CTX_cleanup(&ctxt); 234 EVP_MD_CTX_cleanup(&ctxt);
diff --git a/src/lib/libcrypto/srp/srp_vfy.c b/src/lib/libcrypto/srp/srp_vfy.c
index 4a3d13edf6..de7dbe5bbd 100644
--- a/src/lib/libcrypto/srp/srp_vfy.c
+++ b/src/lib/libcrypto/srp/srp_vfy.c
@@ -185,14 +185,14 @@ static void SRP_user_pwd_free(SRP_user_pwd *user_pwd)
185 return; 185 return;
186 BN_free(user_pwd->s); 186 BN_free(user_pwd->s);
187 BN_clear_free(user_pwd->v); 187 BN_clear_free(user_pwd->v);
188 OPENSSL_free(user_pwd->id); 188 free(user_pwd->id);
189 OPENSSL_free(user_pwd->info); 189 free(user_pwd->info);
190 OPENSSL_free(user_pwd); 190 free(user_pwd);
191 } 191 }
192 192
193static SRP_user_pwd *SRP_user_pwd_new() 193static SRP_user_pwd *SRP_user_pwd_new()
194 { 194 {
195 SRP_user_pwd *ret = OPENSSL_malloc(sizeof(SRP_user_pwd)); 195 SRP_user_pwd *ret = malloc(sizeof(SRP_user_pwd));
196 if (ret == NULL) 196 if (ret == NULL)
197 return NULL; 197 return NULL;
198 ret->N = NULL; 198 ret->N = NULL;
@@ -243,14 +243,14 @@ static int SRP_user_pwd_set_sv_BN(SRP_user_pwd *vinfo, BIGNUM *s, BIGNUM *v)
243 243
244SRP_VBASE *SRP_VBASE_new(char *seed_key) 244SRP_VBASE *SRP_VBASE_new(char *seed_key)
245 { 245 {
246 SRP_VBASE *vb = (SRP_VBASE *) OPENSSL_malloc(sizeof(SRP_VBASE)); 246 SRP_VBASE *vb = (SRP_VBASE *) malloc(sizeof(SRP_VBASE));
247 247
248 if (vb == NULL) 248 if (vb == NULL)
249 return NULL; 249 return NULL;
250 if (!(vb->users_pwd = sk_SRP_user_pwd_new_null()) || 250 if (!(vb->users_pwd = sk_SRP_user_pwd_new_null()) ||
251 !(vb->gN_cache = sk_SRP_gN_cache_new_null())) 251 !(vb->gN_cache = sk_SRP_gN_cache_new_null()))
252 { 252 {
253 OPENSSL_free(vb); 253 free(vb);
254 return NULL; 254 return NULL;
255 } 255 }
256 vb->default_g = NULL; 256 vb->default_g = NULL;
@@ -261,7 +261,7 @@ SRP_VBASE *SRP_VBASE_new(char *seed_key)
261 { 261 {
262 sk_SRP_user_pwd_free(vb->users_pwd); 262 sk_SRP_user_pwd_free(vb->users_pwd);
263 sk_SRP_gN_cache_free(vb->gN_cache); 263 sk_SRP_gN_cache_free(vb->gN_cache);
264 OPENSSL_free(vb); 264 free(vb);
265 return NULL; 265 return NULL;
266 } 266 }
267 return vb; 267 return vb;
@@ -272,8 +272,8 @@ int SRP_VBASE_free(SRP_VBASE *vb)
272 { 272 {
273 sk_SRP_user_pwd_pop_free(vb->users_pwd,SRP_user_pwd_free); 273 sk_SRP_user_pwd_pop_free(vb->users_pwd,SRP_user_pwd_free);
274 sk_SRP_gN_cache_free(vb->gN_cache); 274 sk_SRP_gN_cache_free(vb->gN_cache);
275 OPENSSL_free(vb->seed_key); 275 free(vb->seed_key);
276 OPENSSL_free(vb); 276 free(vb);
277 return 0; 277 return 0;
278 } 278 }
279 279
@@ -283,7 +283,7 @@ static SRP_gN_cache *SRP_gN_new_init(const char *ch)
283 unsigned char tmp[MAX_LEN]; 283 unsigned char tmp[MAX_LEN];
284 int len; 284 int len;
285 285
286 SRP_gN_cache *newgN = (SRP_gN_cache *)OPENSSL_malloc(sizeof(SRP_gN_cache)); 286 SRP_gN_cache *newgN = (SRP_gN_cache *)malloc(sizeof(SRP_gN_cache));
287 if (newgN == NULL) 287 if (newgN == NULL)
288 return NULL; 288 return NULL;
289 289
@@ -294,9 +294,9 @@ static SRP_gN_cache *SRP_gN_new_init(const char *ch)
294 if ((newgN->bn = BN_bin2bn(tmp, len, NULL))) 294 if ((newgN->bn = BN_bin2bn(tmp, len, NULL)))
295 return newgN; 295 return newgN;
296 296
297 OPENSSL_free(newgN->b64_bn); 297 free(newgN->b64_bn);
298err: 298err:
299 OPENSSL_free(newgN); 299 free(newgN);
300 return NULL; 300 return NULL;
301 } 301 }
302 302
@@ -305,9 +305,9 @@ static void SRP_gN_free(SRP_gN_cache *gN_cache)
305 { 305 {
306 if (gN_cache == NULL) 306 if (gN_cache == NULL)
307 return; 307 return;
308 OPENSSL_free(gN_cache->b64_bn); 308 free(gN_cache->b64_bn);
309 BN_free(gN_cache->bn); 309 BN_free(gN_cache->bn);
310 OPENSSL_free(gN_cache); 310 free(gN_cache);
311 } 311 }
312 312
313static SRP_gN *SRP_get_gN_by_id(const char *id, STACK_OF(SRP_gN) *gN_tab) 313static SRP_gN *SRP_get_gN_by_id(const char *id, STACK_OF(SRP_gN) *gN_tab)
@@ -395,7 +395,7 @@ int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file)
395 { 395 {
396 /*we add this couple in the internal Stack */ 396 /*we add this couple in the internal Stack */
397 397
398 if ((gN = (SRP_gN *)OPENSSL_malloc(sizeof(SRP_gN))) == NULL) 398 if ((gN = (SRP_gN *)malloc(sizeof(SRP_gN))) == NULL)
399 goto err; 399 goto err;
400 400
401 if (!(gN->id = BUF_strdup(pp[DB_srpid])) 401 if (!(gN->id = BUF_strdup(pp[DB_srpid]))
@@ -456,8 +456,8 @@ int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file)
456 456
457 if (gN != NULL) 457 if (gN != NULL)
458 { 458 {
459 OPENSSL_free(gN->id); 459 free(gN->id);
460 OPENSSL_free(gN); 460 free(gN);
461 } 461 }
462 462
463 SRP_user_pwd_free(user_pwd); 463 SRP_user_pwd_free(user_pwd);
@@ -573,7 +573,7 @@ char *SRP_create_verifier(const char *user, const char *pass, char **salt,
573 if(!SRP_create_verifier_BN(user, pass, &s, &v, N_bn, g_bn)) goto err; 573 if(!SRP_create_verifier_BN(user, pass, &s, &v, N_bn, g_bn)) goto err;
574 574
575 BN_bn2bin(v,tmp); 575 BN_bn2bin(v,tmp);
576 if (((vf = OPENSSL_malloc(BN_num_bytes(v)*2)) == NULL)) 576 if (((vf = malloc(BN_num_bytes(v)*2)) == NULL))
577 goto err; 577 goto err;
578 t_tob64(vf, tmp, BN_num_bytes(v)); 578 t_tob64(vf, tmp, BN_num_bytes(v));
579 579
@@ -582,9 +582,9 @@ char *SRP_create_verifier(const char *user, const char *pass, char **salt,
582 { 582 {
583 char *tmp_salt; 583 char *tmp_salt;
584 584
585 if ((tmp_salt = OPENSSL_malloc(SRP_RANDOM_SALT_LEN * 2)) == NULL) 585 if ((tmp_salt = malloc(SRP_RANDOM_SALT_LEN * 2)) == NULL)
586 { 586 {
587 OPENSSL_free(vf); 587 free(vf);
588 goto err; 588 goto err;
589 } 589 }
590 t_tob64(tmp_salt, tmp2, SRP_RANDOM_SALT_LEN); 590 t_tob64(tmp_salt, tmp2, SRP_RANDOM_SALT_LEN);
diff --git a/src/lib/libcrypto/stack/stack.c b/src/lib/libcrypto/stack/stack.c
index 76cf1a1168..dabf26d2cd 100644
--- a/src/lib/libcrypto/stack/stack.c
+++ b/src/lib/libcrypto/stack/stack.c
@@ -95,7 +95,7 @@ _STACK *sk_dup(_STACK *sk)
95 char **s; 95 char **s;
96 96
97 if ((ret=sk_new(sk->comp)) == NULL) goto err; 97 if ((ret=sk_new(sk->comp)) == NULL) goto err;
98 s=(char **)OPENSSL_realloc((char *)ret->data, 98 s=(char **)realloc((char *)ret->data,
99 (unsigned int)sizeof(char *)*sk->num_alloc); 99 (unsigned int)sizeof(char *)*sk->num_alloc);
100 if (s == NULL) goto err; 100 if (s == NULL) goto err;
101 ret->data=s; 101 ret->data=s;
@@ -122,9 +122,9 @@ _STACK *sk_new(int (*c)(const void *, const void *))
122 _STACK *ret; 122 _STACK *ret;
123 int i; 123 int i;
124 124
125 if ((ret=OPENSSL_malloc(sizeof(_STACK))) == NULL) 125 if ((ret=malloc(sizeof(_STACK))) == NULL)
126 goto err; 126 goto err;
127 if ((ret->data=OPENSSL_malloc(sizeof(char *)*MIN_NODES)) == NULL) 127 if ((ret->data=malloc(sizeof(char *)*MIN_NODES)) == NULL)
128 goto err; 128 goto err;
129 for (i=0; i<MIN_NODES; i++) 129 for (i=0; i<MIN_NODES; i++)
130 ret->data[i]=NULL; 130 ret->data[i]=NULL;
@@ -135,7 +135,7 @@ _STACK *sk_new(int (*c)(const void *, const void *))
135 return(ret); 135 return(ret);
136err: 136err:
137 if(ret) 137 if(ret)
138 OPENSSL_free(ret); 138 free(ret);
139 return(NULL); 139 return(NULL);
140 } 140 }
141 141
@@ -146,7 +146,7 @@ int sk_insert(_STACK *st, void *data, int loc)
146 if(st == NULL) return 0; 146 if(st == NULL) return 0;
147 if (st->num_alloc <= st->num+1) 147 if (st->num_alloc <= st->num+1)
148 { 148 {
149 s=OPENSSL_realloc((char *)st->data, 149 s=realloc((char *)st->data,
150 (unsigned int)sizeof(char *)*st->num_alloc*2); 150 (unsigned int)sizeof(char *)*st->num_alloc*2);
151 if (s == NULL) 151 if (s == NULL)
152 return(0); 152 return(0);
@@ -287,8 +287,8 @@ void sk_pop_free(_STACK *st, void (*func)(void *))
287void sk_free(_STACK *st) 287void sk_free(_STACK *st)
288 { 288 {
289 if (st == NULL) return; 289 if (st == NULL) return;
290 if (st->data != NULL) OPENSSL_free(st->data); 290 if (st->data != NULL) free(st->data);
291 OPENSSL_free(st); 291 free(st);
292 } 292 }
293 293
294int sk_num(const _STACK *st) 294int sk_num(const _STACK *st)
diff --git a/src/lib/libcrypto/store/str_lib.c b/src/lib/libcrypto/store/str_lib.c
index e92dc1f51c..a451e9cb74 100644
--- a/src/lib/libcrypto/store/str_lib.c
+++ b/src/lib/libcrypto/store/str_lib.c
@@ -112,7 +112,7 @@ STORE *STORE_new_method(const STORE_METHOD *method)
112 return NULL; 112 return NULL;
113 } 113 }
114 114
115 ret=(STORE *)OPENSSL_malloc(sizeof(STORE)); 115 ret=(STORE *)malloc(sizeof(STORE));
116 if (ret == NULL) 116 if (ret == NULL)
117 { 117 {
118 STOREerr(STORE_F_STORE_NEW_METHOD,ERR_R_MALLOC_FAILURE); 118 STOREerr(STORE_F_STORE_NEW_METHOD,ERR_R_MALLOC_FAILURE);
@@ -185,7 +185,7 @@ void STORE_free(STORE *store)
185 if (store->meth->clean) 185 if (store->meth->clean)
186 store->meth->clean(store); 186 store->meth->clean(store);
187 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_STORE, store, &store->ex_data); 187 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_STORE, store, &store->ex_data);
188 OPENSSL_free(store); 188 free(store);
189 } 189 }
190 190
191int STORE_ctrl(STORE *store, int cmd, long i, void *p, void (*f)(void)) 191int STORE_ctrl(STORE *store, int cmd, long i, void *p, void (*f)(void))
@@ -1227,7 +1227,7 @@ int STORE_delete_arbitrary(STORE *s, OPENSSL_ITEM attributes[],
1227 1227
1228STORE_OBJECT *STORE_OBJECT_new(void) 1228STORE_OBJECT *STORE_OBJECT_new(void)
1229 { 1229 {
1230 STORE_OBJECT *object = OPENSSL_malloc(sizeof(STORE_OBJECT)); 1230 STORE_OBJECT *object = malloc(sizeof(STORE_OBJECT));
1231 if (object) memset(object, 0, sizeof(STORE_OBJECT)); 1231 if (object) memset(object, 0, sizeof(STORE_OBJECT));
1232 return object; 1232 return object;
1233 } 1233 }
@@ -1253,7 +1253,7 @@ void STORE_OBJECT_free(STORE_OBJECT *data)
1253 BUF_MEM_free(data->data.arbitrary); 1253 BUF_MEM_free(data->data.arbitrary);
1254 break; 1254 break;
1255 } 1255 }
1256 OPENSSL_free(data); 1256 free(data);
1257 } 1257 }
1258 1258
1259IMPLEMENT_STACK_OF(STORE_OBJECT*) 1259IMPLEMENT_STACK_OF(STORE_OBJECT*)
@@ -1280,7 +1280,7 @@ struct STORE_attr_info_st
1280 1280
1281STORE_ATTR_INFO *STORE_ATTR_INFO_new(void) 1281STORE_ATTR_INFO *STORE_ATTR_INFO_new(void)
1282 { 1282 {
1283 return (STORE_ATTR_INFO *)OPENSSL_malloc(sizeof(STORE_ATTR_INFO)); 1283 return (STORE_ATTR_INFO *)malloc(sizeof(STORE_ATTR_INFO));
1284 } 1284 }
1285static void STORE_ATTR_INFO_attr_free(STORE_ATTR_INFO *attrs, 1285static void STORE_ATTR_INFO_attr_free(STORE_ATTR_INFO *attrs,
1286 STORE_ATTR_TYPES code) 1286 STORE_ATTR_TYPES code)
@@ -1320,7 +1320,7 @@ int STORE_ATTR_INFO_free(STORE_ATTR_INFO *attrs)
1320 STORE_ATTR_TYPES i; 1320 STORE_ATTR_TYPES i;
1321 for(i = 0; i++ < STORE_ATTR_TYPE_NUM;) 1321 for(i = 0; i++ < STORE_ATTR_TYPE_NUM;)
1322 STORE_ATTR_INFO_attr_free(attrs, i); 1322 STORE_ATTR_INFO_attr_free(attrs, i);
1323 OPENSSL_free(attrs); 1323 free(attrs);
1324 } 1324 }
1325 return 1; 1325 return 1;
1326 } 1326 }
@@ -1474,7 +1474,7 @@ int STORE_ATTR_INFO_modify_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1474 } 1474 }
1475 if (ATTR_IS_SET(attrs,code)) 1475 if (ATTR_IS_SET(attrs,code))
1476 { 1476 {
1477 OPENSSL_free(attrs->values[code].cstring); 1477 free(attrs->values[code].cstring);
1478 attrs->values[code].cstring = NULL; 1478 attrs->values[code].cstring = NULL;
1479 CLEAR_ATTRBIT(attrs, code); 1479 CLEAR_ATTRBIT(attrs, code);
1480 } 1480 }
@@ -1491,7 +1491,7 @@ int STORE_ATTR_INFO_modify_sha1str(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code
1491 } 1491 }
1492 if (ATTR_IS_SET(attrs,code)) 1492 if (ATTR_IS_SET(attrs,code))
1493 { 1493 {
1494 OPENSSL_free(attrs->values[code].sha1string); 1494 free(attrs->values[code].sha1string);
1495 attrs->values[code].sha1string = NULL; 1495 attrs->values[code].sha1string = NULL;
1496 CLEAR_ATTRBIT(attrs, code); 1496 CLEAR_ATTRBIT(attrs, code);
1497 } 1497 }
@@ -1508,7 +1508,7 @@ int STORE_ATTR_INFO_modify_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1508 } 1508 }
1509 if (ATTR_IS_SET(attrs,code)) 1509 if (ATTR_IS_SET(attrs,code))
1510 { 1510 {
1511 OPENSSL_free(attrs->values[code].dn); 1511 free(attrs->values[code].dn);
1512 attrs->values[code].dn = NULL; 1512 attrs->values[code].dn = NULL;
1513 CLEAR_ATTRBIT(attrs, code); 1513 CLEAR_ATTRBIT(attrs, code);
1514 } 1514 }
@@ -1525,7 +1525,7 @@ int STORE_ATTR_INFO_modify_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1525 } 1525 }
1526 if (ATTR_IS_SET(attrs,code)) 1526 if (ATTR_IS_SET(attrs,code))
1527 { 1527 {
1528 OPENSSL_free(attrs->values[code].number); 1528 free(attrs->values[code].number);
1529 attrs->values[code].number = NULL; 1529 attrs->values[code].number = NULL;
1530 CLEAR_ATTRBIT(attrs, code); 1530 CLEAR_ATTRBIT(attrs, code);
1531 } 1531 }
@@ -1541,7 +1541,7 @@ void *STORE_parse_attrs_start(OPENSSL_ITEM *attributes)
1541 if (attributes) 1541 if (attributes)
1542 { 1542 {
1543 struct attr_list_ctx_st *context = 1543 struct attr_list_ctx_st *context =
1544 (struct attr_list_ctx_st *)OPENSSL_malloc(sizeof(struct attr_list_ctx_st)); 1544 (struct attr_list_ctx_st *)malloc(sizeof(struct attr_list_ctx_st));
1545 if (context) 1545 if (context)
1546 context->attributes = attributes; 1546 context->attributes = attributes;
1547 else 1547 else
@@ -1650,7 +1650,7 @@ int STORE_parse_attrs_end(void *handle)
1650#if 0 1650#if 0
1651 OPENSSL_ITEM *attributes = context->attributes; 1651 OPENSSL_ITEM *attributes = context->attributes;
1652#endif 1652#endif
1653 OPENSSL_free(context); 1653 free(context);
1654 return 1; 1654 return 1;
1655 } 1655 }
1656 STOREerr(STORE_F_STORE_PARSE_ATTRS_END, ERR_R_PASSED_NULL_PARAMETER); 1656 STOREerr(STORE_F_STORE_PARSE_ATTRS_END, ERR_R_PASSED_NULL_PARAMETER);
diff --git a/src/lib/libcrypto/store/str_mem.c b/src/lib/libcrypto/store/str_mem.c
index 8ac4f7e55c..997e60fe93 100644
--- a/src/lib/libcrypto/store/str_mem.c
+++ b/src/lib/libcrypto/store/str_mem.c
@@ -222,7 +222,7 @@ static void *mem_list_start(STORE *s, STORE_OBJECT_TYPES type,
222 OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]) 222 OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[])
223 { 223 {
224 struct mem_ctx_st *context = 224 struct mem_ctx_st *context =
225 (struct mem_ctx_st *)OPENSSL_malloc(sizeof(struct mem_ctx_st)); 225 (struct mem_ctx_st *)malloc(sizeof(struct mem_ctx_st));
226 void *attribute_context = NULL; 226 void *attribute_context = NULL;
227 STORE_ATTR_INFO *attrs = NULL; 227 STORE_ATTR_INFO *attrs = NULL;
228 228
@@ -336,7 +336,7 @@ static int mem_list_end(STORE *s, void *handle)
336 } 336 }
337 if (context && context->search_attributes) 337 if (context && context->search_attributes)
338 sk_STORE_ATTR_INFO_free(context->search_attributes); 338 sk_STORE_ATTR_INFO_free(context->search_attributes);
339 if (context) OPENSSL_free(context); 339 if (context) free(context);
340 return 1; 340 return 1;
341 } 341 }
342static int mem_list_endp(STORE *s, void *handle) 342static int mem_list_endp(STORE *s, void *handle)
diff --git a/src/lib/libcrypto/store/str_meth.c b/src/lib/libcrypto/store/str_meth.c
index a46de03a26..8944824618 100644
--- a/src/lib/libcrypto/store/str_meth.c
+++ b/src/lib/libcrypto/store/str_meth.c
@@ -62,7 +62,7 @@
62 62
63STORE_METHOD *STORE_create_method(char *name) 63STORE_METHOD *STORE_create_method(char *name)
64 { 64 {
65 STORE_METHOD *store_method = (STORE_METHOD *)OPENSSL_malloc(sizeof(STORE_METHOD)); 65 STORE_METHOD *store_method = (STORE_METHOD *)malloc(sizeof(STORE_METHOD));
66 66
67 if (store_method) 67 if (store_method)
68 { 68 {
@@ -78,9 +78,9 @@ STORE_METHOD *STORE_create_method(char *name)
78void STORE_destroy_method(STORE_METHOD *store_method) 78void STORE_destroy_method(STORE_METHOD *store_method)
79 { 79 {
80 if (!store_method) return; 80 if (!store_method) return;
81 OPENSSL_free(store_method->name); 81 free(store_method->name);
82 store_method->name = NULL; 82 store_method->name = NULL;
83 OPENSSL_free(store_method); 83 free(store_method);
84 } 84 }
85 85
86int STORE_method_set_initialise_function(STORE_METHOD *sm, STORE_INITIALISE_FUNC_PTR init_f) 86int STORE_method_set_initialise_function(STORE_METHOD *sm, STORE_INITIALISE_FUNC_PTR init_f)
diff --git a/src/lib/libcrypto/ts/ts_lib.c b/src/lib/libcrypto/ts/ts_lib.c
index e8608dbf71..a8de801e28 100644
--- a/src/lib/libcrypto/ts/ts_lib.c
+++ b/src/lib/libcrypto/ts/ts_lib.c
@@ -79,7 +79,7 @@ int TS_ASN1_INTEGER_print_bio(BIO *bio, const ASN1_INTEGER *num)
79 { 79 {
80 result = BIO_write(bio, "0x", 2) > 0; 80 result = BIO_write(bio, "0x", 2) > 0;
81 result = result && BIO_write(bio, hex, strlen(hex)) > 0; 81 result = result && BIO_write(bio, hex, strlen(hex)) > 0;
82 OPENSSL_free(hex); 82 free(hex);
83 } 83 }
84 BN_free(&num_bn); 84 BN_free(&num_bn);
85 85
diff --git a/src/lib/libcrypto/ts/ts_rsp_sign.c b/src/lib/libcrypto/ts/ts_rsp_sign.c
index e7186a8ce0..e52c9ff03b 100644
--- a/src/lib/libcrypto/ts/ts_rsp_sign.c
+++ b/src/lib/libcrypto/ts/ts_rsp_sign.c
@@ -167,7 +167,7 @@ TS_RESP_CTX *TS_RESP_CTX_new()
167 { 167 {
168 TS_RESP_CTX *ctx; 168 TS_RESP_CTX *ctx;
169 169
170 if (!(ctx = (TS_RESP_CTX *) OPENSSL_malloc(sizeof(TS_RESP_CTX)))) 170 if (!(ctx = (TS_RESP_CTX *) malloc(sizeof(TS_RESP_CTX))))
171 { 171 {
172 TSerr(TS_F_TS_RESP_CTX_NEW, ERR_R_MALLOC_FAILURE); 172 TSerr(TS_F_TS_RESP_CTX_NEW, ERR_R_MALLOC_FAILURE);
173 return NULL; 173 return NULL;
@@ -195,7 +195,7 @@ void TS_RESP_CTX_free(TS_RESP_CTX *ctx)
195 ASN1_INTEGER_free(ctx->seconds); 195 ASN1_INTEGER_free(ctx->seconds);
196 ASN1_INTEGER_free(ctx->millis); 196 ASN1_INTEGER_free(ctx->millis);
197 ASN1_INTEGER_free(ctx->micros); 197 ASN1_INTEGER_free(ctx->micros);
198 OPENSSL_free(ctx); 198 free(ctx);
199 } 199 }
200 200
201int TS_RESP_CTX_set_signer_cert(TS_RESP_CTX *ctx, X509 *signer) 201int TS_RESP_CTX_set_signer_cert(TS_RESP_CTX *ctx, X509 *signer)
@@ -922,7 +922,7 @@ static int ESS_add_signing_cert(PKCS7_SIGNER_INFO *si, ESS_SIGNING_CERT *sc)
922 int len; 922 int len;
923 923
924 len = i2d_ESS_SIGNING_CERT(sc, NULL); 924 len = i2d_ESS_SIGNING_CERT(sc, NULL);
925 if (!(pp = (unsigned char *) OPENSSL_malloc(len))) 925 if (!(pp = (unsigned char *) malloc(len)))
926 { 926 {
927 TSerr(TS_F_ESS_ADD_SIGNING_CERT, ERR_R_MALLOC_FAILURE); 927 TSerr(TS_F_ESS_ADD_SIGNING_CERT, ERR_R_MALLOC_FAILURE);
928 goto err; 928 goto err;
@@ -934,13 +934,13 @@ static int ESS_add_signing_cert(PKCS7_SIGNER_INFO *si, ESS_SIGNING_CERT *sc)
934 TSerr(TS_F_ESS_ADD_SIGNING_CERT, ERR_R_MALLOC_FAILURE); 934 TSerr(TS_F_ESS_ADD_SIGNING_CERT, ERR_R_MALLOC_FAILURE);
935 goto err; 935 goto err;
936 } 936 }
937 OPENSSL_free(pp); pp = NULL; 937 free(pp); pp = NULL;
938 return PKCS7_add_signed_attribute(si, 938 return PKCS7_add_signed_attribute(si,
939 NID_id_smime_aa_signingCertificate, 939 NID_id_smime_aa_signingCertificate,
940 V_ASN1_SEQUENCE, seq); 940 V_ASN1_SEQUENCE, seq);
941 err: 941 err:
942 ASN1_STRING_free(seq); 942 ASN1_STRING_free(seq);
943 OPENSSL_free(pp); 943 free(pp);
944 944
945 return 0; 945 return 0;
946 } 946 }
diff --git a/src/lib/libcrypto/ts/ts_rsp_verify.c b/src/lib/libcrypto/ts/ts_rsp_verify.c
index f241230ef4..d51500b5d4 100644
--- a/src/lib/libcrypto/ts/ts_rsp_verify.c
+++ b/src/lib/libcrypto/ts/ts_rsp_verify.c
@@ -472,7 +472,7 @@ static int int_TS_RESP_verify_token(TS_VERIFY_CTX *ctx,
472 err: 472 err:
473 X509_free(signer); 473 X509_free(signer);
474 X509_ALGOR_free(md_alg); 474 X509_ALGOR_free(md_alg);
475 OPENSSL_free(imprint); 475 free(imprint);
476 return ret; 476 return ret;
477 } 477 }
478 478
@@ -528,7 +528,7 @@ static int TS_check_status_info(TS_RESP *response)
528 ", status text: ", embedded_status_text ? 528 ", status text: ", embedded_status_text ?
529 embedded_status_text : "unspecified", 529 embedded_status_text : "unspecified",
530 ", failure codes: ", failure_text); 530 ", failure codes: ", failure_text);
531 OPENSSL_free(embedded_status_text); 531 free(embedded_status_text);
532 532
533 return 0; 533 return 0;
534 } 534 }
@@ -547,7 +547,7 @@ static char *TS_get_status_text(STACK_OF(ASN1_UTF8STRING) *text)
547 length += 1; /* separator character */ 547 length += 1; /* separator character */
548 } 548 }
549 /* Allocate memory (closing '\0' included). */ 549 /* Allocate memory (closing '\0' included). */
550 if (!(result = OPENSSL_malloc(length))) 550 if (!(result = malloc(length)))
551 { 551 {
552 TSerr(TS_F_TS_GET_STATUS_TEXT, ERR_R_MALLOC_FAILURE); 552 TSerr(TS_F_TS_GET_STATUS_TEXT, ERR_R_MALLOC_FAILURE);
553 return NULL; 553 return NULL;
@@ -606,7 +606,7 @@ static int TS_compute_imprint(BIO *data, TS_TST_INFO *tst_info,
606 if (length < 0) 606 if (length < 0)
607 goto err; 607 goto err;
608 *imprint_len = length; 608 *imprint_len = length;
609 if (!(*imprint = OPENSSL_malloc(*imprint_len))) 609 if (!(*imprint = malloc(*imprint_len)))
610 { 610 {
611 TSerr(TS_F_TS_COMPUTE_IMPRINT, ERR_R_MALLOC_FAILURE); 611 TSerr(TS_F_TS_COMPUTE_IMPRINT, ERR_R_MALLOC_FAILURE);
612 goto err; 612 goto err;
@@ -625,7 +625,7 @@ static int TS_compute_imprint(BIO *data, TS_TST_INFO *tst_info,
625 return 1; 625 return 1;
626 err: 626 err:
627 X509_ALGOR_free(*md_alg); 627 X509_ALGOR_free(*md_alg);
628 OPENSSL_free(*imprint); 628 free(*imprint);
629 *imprint_len = 0; 629 *imprint_len = 0;
630 return 0; 630 return 0;
631 } 631 }
diff --git a/src/lib/libcrypto/ts/ts_verify_ctx.c b/src/lib/libcrypto/ts/ts_verify_ctx.c
index 609b7735d4..629107aeec 100644
--- a/src/lib/libcrypto/ts/ts_verify_ctx.c
+++ b/src/lib/libcrypto/ts/ts_verify_ctx.c
@@ -63,7 +63,7 @@
63TS_VERIFY_CTX *TS_VERIFY_CTX_new(void) 63TS_VERIFY_CTX *TS_VERIFY_CTX_new(void)
64 { 64 {
65 TS_VERIFY_CTX *ctx = 65 TS_VERIFY_CTX *ctx =
66 (TS_VERIFY_CTX *) OPENSSL_malloc(sizeof(TS_VERIFY_CTX)); 66 (TS_VERIFY_CTX *) malloc(sizeof(TS_VERIFY_CTX));
67 if (ctx) 67 if (ctx)
68 memset(ctx, 0, sizeof(TS_VERIFY_CTX)); 68 memset(ctx, 0, sizeof(TS_VERIFY_CTX));
69 else 69 else
@@ -82,7 +82,7 @@ void TS_VERIFY_CTX_free(TS_VERIFY_CTX *ctx)
82 if (!ctx) return; 82 if (!ctx) return;
83 83
84 TS_VERIFY_CTX_cleanup(ctx); 84 TS_VERIFY_CTX_cleanup(ctx);
85 OPENSSL_free(ctx); 85 free(ctx);
86 } 86 }
87 87
88void TS_VERIFY_CTX_cleanup(TS_VERIFY_CTX *ctx) 88void TS_VERIFY_CTX_cleanup(TS_VERIFY_CTX *ctx)
@@ -95,7 +95,7 @@ void TS_VERIFY_CTX_cleanup(TS_VERIFY_CTX *ctx)
95 ASN1_OBJECT_free(ctx->policy); 95 ASN1_OBJECT_free(ctx->policy);
96 96
97 X509_ALGOR_free(ctx->md_alg); 97 X509_ALGOR_free(ctx->md_alg);
98 OPENSSL_free(ctx->imprint); 98 free(ctx->imprint);
99 99
100 BIO_free_all(ctx->data); 100 BIO_free_all(ctx->data);
101 101
@@ -138,7 +138,7 @@ TS_VERIFY_CTX *TS_REQ_to_TS_VERIFY_CTX(TS_REQ *req, TS_VERIFY_CTX *ctx)
138 if (!(ret->md_alg = X509_ALGOR_dup(md_alg))) goto err; 138 if (!(ret->md_alg = X509_ALGOR_dup(md_alg))) goto err;
139 msg = TS_MSG_IMPRINT_get_msg(imprint); 139 msg = TS_MSG_IMPRINT_get_msg(imprint);
140 ret->imprint_len = ASN1_STRING_length(msg); 140 ret->imprint_len = ASN1_STRING_length(msg);
141 if (!(ret->imprint = OPENSSL_malloc(ret->imprint_len))) goto err; 141 if (!(ret->imprint = malloc(ret->imprint_len))) goto err;
142 memcpy(ret->imprint, ASN1_STRING_data(msg), ret->imprint_len); 142 memcpy(ret->imprint, ASN1_STRING_data(msg), ret->imprint_len);
143 143
144 /* Setting nonce. */ 144 /* Setting nonce. */
diff --git a/src/lib/libcrypto/txt_db/txt_db.c b/src/lib/libcrypto/txt_db/txt_db.c
index 6f2ce3b5a4..c1e7a79a1a 100644
--- a/src/lib/libcrypto/txt_db/txt_db.c
+++ b/src/lib/libcrypto/txt_db/txt_db.c
@@ -84,16 +84,16 @@ TXT_DB *TXT_DB_read(BIO *in, int num)
84 if ((buf=BUF_MEM_new()) == NULL) goto err; 84 if ((buf=BUF_MEM_new()) == NULL) goto err;
85 if (!BUF_MEM_grow(buf,size)) goto err; 85 if (!BUF_MEM_grow(buf,size)) goto err;
86 86
87 if ((ret=OPENSSL_malloc(sizeof(TXT_DB))) == NULL) 87 if ((ret=malloc(sizeof(TXT_DB))) == NULL)
88 goto err; 88 goto err;
89 ret->num_fields=num; 89 ret->num_fields=num;
90 ret->index=NULL; 90 ret->index=NULL;
91 ret->qual=NULL; 91 ret->qual=NULL;
92 if ((ret->data=sk_OPENSSL_PSTRING_new_null()) == NULL) 92 if ((ret->data=sk_OPENSSL_PSTRING_new_null()) == NULL)
93 goto err; 93 goto err;
94 if ((ret->index=OPENSSL_malloc(sizeof(*ret->index)*num)) == NULL) 94 if ((ret->index=malloc(sizeof(*ret->index)*num)) == NULL)
95 goto err; 95 goto err;
96 if ((ret->qual=OPENSSL_malloc(sizeof(*(ret->qual))*num)) == NULL) 96 if ((ret->qual=malloc(sizeof(*(ret->qual))*num)) == NULL)
97 goto err; 97 goto err;
98 for (i=0; i<num; i++) 98 for (i=0; i<num; i++)
99 { 99 {
@@ -123,7 +123,7 @@ TXT_DB *TXT_DB_read(BIO *in, int num)
123 else 123 else
124 { 124 {
125 buf->data[offset-1]='\0'; /* blat the '\n' */ 125 buf->data[offset-1]='\0'; /* blat the '\n' */
126 if (!(p=OPENSSL_malloc(add+offset))) goto err; 126 if (!(p=malloc(add+offset))) goto err;
127 offset=0; 127 offset=0;
128 } 128 }
129 pp=(char **)p; 129 pp=(char **)p;
@@ -178,14 +178,14 @@ err:
178 if (er) 178 if (er)
179 { 179 {
180#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16) 180#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)
181 if (er == 1) fprintf(stderr,"OPENSSL_malloc failure\n"); 181 if (er == 1) fprintf(stderr,"malloc failure\n");
182#endif 182#endif
183 if (ret != NULL) 183 if (ret != NULL)
184 { 184 {
185 if (ret->data != NULL) sk_OPENSSL_PSTRING_free(ret->data); 185 if (ret->data != NULL) sk_OPENSSL_PSTRING_free(ret->data);
186 if (ret->index != NULL) OPENSSL_free(ret->index); 186 if (ret->index != NULL) free(ret->index);
187 if (ret->qual != NULL) OPENSSL_free(ret->qual); 187 if (ret->qual != NULL) free(ret->qual);
188 if (ret != NULL) OPENSSL_free(ret); 188 if (ret != NULL) free(ret);
189 } 189 }
190 return(NULL); 190 return(NULL);
191 } 191 }
@@ -354,10 +354,10 @@ void TXT_DB_free(TXT_DB *db)
354 { 354 {
355 for (i=db->num_fields-1; i>=0; i--) 355 for (i=db->num_fields-1; i>=0; i--)
356 if (db->index[i] != NULL) lh_OPENSSL_STRING_free(db->index[i]); 356 if (db->index[i] != NULL) lh_OPENSSL_STRING_free(db->index[i]);
357 OPENSSL_free(db->index); 357 free(db->index);
358 } 358 }
359 if (db->qual != NULL) 359 if (db->qual != NULL)
360 OPENSSL_free(db->qual); 360 free(db->qual);
361 if (db->data != NULL) 361 if (db->data != NULL)
362 { 362 {
363 for (i=sk_OPENSSL_PSTRING_num(db->data)-1; i>=0; i--) 363 for (i=sk_OPENSSL_PSTRING_num(db->data)-1; i>=0; i--)
@@ -369,7 +369,7 @@ void TXT_DB_free(TXT_DB *db)
369 if (max == NULL) /* new row */ 369 if (max == NULL) /* new row */
370 { 370 {
371 for (n=0; n<db->num_fields; n++) 371 for (n=0; n<db->num_fields; n++)
372 if (p[n] != NULL) OPENSSL_free(p[n]); 372 if (p[n] != NULL) free(p[n]);
373 } 373 }
374 else 374 else
375 { 375 {
@@ -377,12 +377,12 @@ void TXT_DB_free(TXT_DB *db)
377 { 377 {
378 if (((p[n] < (char *)p) || (p[n] > max)) 378 if (((p[n] < (char *)p) || (p[n] > max))
379 && (p[n] != NULL)) 379 && (p[n] != NULL))
380 OPENSSL_free(p[n]); 380 free(p[n]);
381 } 381 }
382 } 382 }
383 OPENSSL_free(sk_OPENSSL_PSTRING_value(db->data,i)); 383 free(sk_OPENSSL_PSTRING_value(db->data,i));
384 } 384 }
385 sk_OPENSSL_PSTRING_free(db->data); 385 sk_OPENSSL_PSTRING_free(db->data);
386 } 386 }
387 OPENSSL_free(db); 387 free(db);
388 } 388 }
diff --git a/src/lib/libcrypto/ui/ui.h b/src/lib/libcrypto/ui/ui.h
index bd78aa413f..ed35e50eb4 100644
--- a/src/lib/libcrypto/ui/ui.h
+++ b/src/lib/libcrypto/ui/ui.h
@@ -173,7 +173,7 @@ int UI_dup_error_string(UI *ui, const char *text);
173 and object_name is the name of the object (might be a card name or 173 and object_name is the name of the object (might be a card name or
174 a file name. 174 a file name.
175 The returned string shall always be allocated on the heap with 175 The returned string shall always be allocated on the heap with
176 OPENSSL_malloc(), and need to be free'd with OPENSSL_free(). 176 malloc(), and need to be free'd with free().
177 177
178 If the ui_method doesn't contain a pointer to a user-defined prompt 178 If the ui_method doesn't contain a pointer to a user-defined prompt
179 constructor, a default string is built, looking like this: 179 constructor, a default string is built, looking like this:
diff --git a/src/lib/libcrypto/ui/ui_lib.c b/src/lib/libcrypto/ui/ui_lib.c
index 6113060aa9..d3cadd51f6 100644
--- a/src/lib/libcrypto/ui/ui_lib.c
+++ b/src/lib/libcrypto/ui/ui_lib.c
@@ -77,7 +77,7 @@ UI *UI_new_method(const UI_METHOD *method)
77 { 77 {
78 UI *ret; 78 UI *ret;
79 79
80 ret=(UI *)OPENSSL_malloc(sizeof(UI)); 80 ret=(UI *)malloc(sizeof(UI));
81 if (ret == NULL) 81 if (ret == NULL)
82 { 82 {
83 UIerr(UI_F_UI_NEW_METHOD,ERR_R_MALLOC_FAILURE); 83 UIerr(UI_F_UI_NEW_METHOD,ERR_R_MALLOC_FAILURE);
@@ -99,19 +99,19 @@ static void free_string(UI_STRING *uis)
99 { 99 {
100 if (uis->flags & OUT_STRING_FREEABLE) 100 if (uis->flags & OUT_STRING_FREEABLE)
101 { 101 {
102 OPENSSL_free((char *)uis->out_string); 102 free((char *)uis->out_string);
103 switch(uis->type) 103 switch(uis->type)
104 { 104 {
105 case UIT_BOOLEAN: 105 case UIT_BOOLEAN:
106 OPENSSL_free((char *)uis->_.boolean_data.action_desc); 106 free((char *)uis->_.boolean_data.action_desc);
107 OPENSSL_free((char *)uis->_.boolean_data.ok_chars); 107 free((char *)uis->_.boolean_data.ok_chars);
108 OPENSSL_free((char *)uis->_.boolean_data.cancel_chars); 108 free((char *)uis->_.boolean_data.cancel_chars);
109 break; 109 break;
110 default: 110 default:
111 break; 111 break;
112 } 112 }
113 } 113 }
114 OPENSSL_free(uis); 114 free(uis);
115 } 115 }
116 116
117void UI_free(UI *ui) 117void UI_free(UI *ui)
@@ -120,7 +120,7 @@ void UI_free(UI *ui)
120 return; 120 return;
121 sk_UI_STRING_pop_free(ui->strings,free_string); 121 sk_UI_STRING_pop_free(ui->strings,free_string);
122 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_UI, ui, &ui->ex_data); 122 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_UI, ui, &ui->ex_data);
123 OPENSSL_free(ui); 123 free(ui);
124 } 124 }
125 125
126static int allocate_string_stack(UI *ui) 126static int allocate_string_stack(UI *ui)
@@ -151,7 +151,7 @@ static UI_STRING *general_allocate_prompt(UI *ui, const char *prompt,
151 { 151 {
152 UIerr(UI_F_GENERAL_ALLOCATE_PROMPT,UI_R_NO_RESULT_BUFFER); 152 UIerr(UI_F_GENERAL_ALLOCATE_PROMPT,UI_R_NO_RESULT_BUFFER);
153 } 153 }
154 else if ((ret = (UI_STRING *)OPENSSL_malloc(sizeof(UI_STRING)))) 154 else if ((ret = (UI_STRING *)malloc(sizeof(UI_STRING))))
155 { 155 {
156 ret->out_string=prompt; 156 ret->out_string=prompt;
157 ret->flags=prompt_freeable ? OUT_STRING_FREEABLE : 0; 157 ret->flags=prompt_freeable ? OUT_STRING_FREEABLE : 0;
@@ -354,10 +354,10 @@ int UI_dup_input_boolean(UI *ui, const char *prompt, const char *action_desc,
354 ok_chars_copy, cancel_chars_copy, 1, UIT_BOOLEAN, flags, 354 ok_chars_copy, cancel_chars_copy, 1, UIT_BOOLEAN, flags,
355 result_buf); 355 result_buf);
356 err: 356 err:
357 if (prompt_copy) OPENSSL_free(prompt_copy); 357 if (prompt_copy) free(prompt_copy);
358 if (action_desc_copy) OPENSSL_free(action_desc_copy); 358 if (action_desc_copy) free(action_desc_copy);
359 if (ok_chars_copy) OPENSSL_free(ok_chars_copy); 359 if (ok_chars_copy) free(ok_chars_copy);
360 if (cancel_chars_copy) OPENSSL_free(cancel_chars_copy); 360 if (cancel_chars_copy) free(cancel_chars_copy);
361 return -1; 361 return -1;
362 } 362 }
363 363
@@ -430,7 +430,7 @@ char *UI_construct_prompt(UI *ui, const char *object_desc,
430 len += sizeof(prompt2) - 1 + strlen(object_name); 430 len += sizeof(prompt2) - 1 + strlen(object_name);
431 len += sizeof(prompt3) - 1; 431 len += sizeof(prompt3) - 1;
432 432
433 prompt = (char *)OPENSSL_malloc(len + 1); 433 prompt = (char *)malloc(len + 1);
434 BUF_strlcpy(prompt, prompt1, len + 1); 434 BUF_strlcpy(prompt, prompt1, len + 1);
435 BUF_strlcat(prompt, object_desc, len + 1); 435 BUF_strlcat(prompt, object_desc, len + 1);
436 if (object_name) 436 if (object_name)
@@ -618,7 +618,7 @@ const UI_METHOD *UI_set_method(UI *ui, const UI_METHOD *meth)
618 618
619UI_METHOD *UI_create_method(char *name) 619UI_METHOD *UI_create_method(char *name)
620 { 620 {
621 UI_METHOD *ui_method = (UI_METHOD *)OPENSSL_malloc(sizeof(UI_METHOD)); 621 UI_METHOD *ui_method = (UI_METHOD *)malloc(sizeof(UI_METHOD));
622 622
623 if (ui_method) 623 if (ui_method)
624 { 624 {
@@ -633,9 +633,9 @@ UI_METHOD *UI_create_method(char *name)
633 anything Murphy can throw at you and more! You have been warned. */ 633 anything Murphy can throw at you and more! You have been warned. */
634void UI_destroy_method(UI_METHOD *ui_method) 634void UI_destroy_method(UI_METHOD *ui_method)
635 { 635 {
636 OPENSSL_free(ui_method->name); 636 free(ui_method->name);
637 ui_method->name = NULL; 637 ui_method->name = NULL;
638 OPENSSL_free(ui_method); 638 free(ui_method);
639 } 639 }
640 640
641int UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui)) 641int UI_method_set_opener(UI_METHOD *method, int (*opener)(UI *ui))
diff --git a/src/lib/libcrypto/ui/ui_locl.h b/src/lib/libcrypto/ui/ui_locl.h
index aa4a55637d..39789e2638 100644
--- a/src/lib/libcrypto/ui/ui_locl.h
+++ b/src/lib/libcrypto/ui/ui_locl.h
@@ -94,7 +94,7 @@ struct ui_method_st
94 and object_name is the name of the object (might be a card name or 94 and object_name is the name of the object (might be a card name or
95 a file name. 95 a file name.
96 The returned string shall always be allocated on the heap with 96 The returned string shall always be allocated on the heap with
97 OPENSSL_malloc(), and need to be free'd with OPENSSL_free(). */ 97 malloc(), and need to be free'd with free(). */
98 char *(*ui_construct_prompt)(UI *ui, const char *object_desc, 98 char *(*ui_construct_prompt)(UI *ui, const char *object_desc,
99 const char *object_name); 99 const char *object_name);
100 }; 100 };
diff --git a/src/lib/libcrypto/x509/by_dir.c b/src/lib/libcrypto/x509/by_dir.c
index ccf2f6e0bf..3b72fd302f 100644
--- a/src/lib/libcrypto/x509/by_dir.c
+++ b/src/lib/libcrypto/x509/by_dir.c
@@ -153,10 +153,10 @@ new_dir(X509_LOOKUP *lu)
153{ 153{
154 BY_DIR *a; 154 BY_DIR *a;
155 155
156 if ((a = (BY_DIR *)OPENSSL_malloc(sizeof(BY_DIR))) == NULL) 156 if ((a = (BY_DIR *)malloc(sizeof(BY_DIR))) == NULL)
157 return (0); 157 return (0);
158 if ((a->buffer = BUF_MEM_new()) == NULL) { 158 if ((a->buffer = BUF_MEM_new()) == NULL) {
159 OPENSSL_free(a); 159 free(a);
160 return (0); 160 return (0);
161 } 161 }
162 a->dirs = NULL; 162 a->dirs = NULL;
@@ -167,7 +167,7 @@ new_dir(X509_LOOKUP *lu)
167static void 167static void
168by_dir_hash_free(BY_DIR_HASH *hash) 168by_dir_hash_free(BY_DIR_HASH *hash)
169{ 169{
170 OPENSSL_free(hash); 170 free(hash);
171} 171}
172 172
173static int 173static int
@@ -185,10 +185,10 @@ static void
185by_dir_entry_free(BY_DIR_ENTRY *ent) 185by_dir_entry_free(BY_DIR_ENTRY *ent)
186{ 186{
187 if (ent->dir) 187 if (ent->dir)
188 OPENSSL_free(ent->dir); 188 free(ent->dir);
189 if (ent->hashes) 189 if (ent->hashes)
190 sk_BY_DIR_HASH_pop_free(ent->hashes, by_dir_hash_free); 190 sk_BY_DIR_HASH_pop_free(ent->hashes, by_dir_hash_free);
191 OPENSSL_free(ent); 191 free(ent);
192} 192}
193 193
194static void 194static void
@@ -201,7 +201,7 @@ free_dir(X509_LOOKUP *lu)
201 sk_BY_DIR_ENTRY_pop_free(a->dirs, by_dir_entry_free); 201 sk_BY_DIR_ENTRY_pop_free(a->dirs, by_dir_entry_free);
202 if (a->buffer != NULL) 202 if (a->buffer != NULL)
203 BUF_MEM_free(a->buffer); 203 BUF_MEM_free(a->buffer);
204 OPENSSL_free(a); 204 free(a);
205} 205}
206 206
207static int 207static int
@@ -241,7 +241,7 @@ add_cert_dir(BY_DIR *ctx, const char *dir, int type)
241 return 0; 241 return 0;
242 } 242 }
243 } 243 }
244 ent = OPENSSL_malloc(sizeof(BY_DIR_ENTRY)); 244 ent = malloc(sizeof(BY_DIR_ENTRY));
245 if (!ent) 245 if (!ent)
246 return 0; 246 return 0;
247 ent->dir_type = type; 247 ent->dir_type = type;
@@ -411,12 +411,12 @@ get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
411 ent->hashes, idx); 411 ent->hashes, idx);
412 } 412 }
413 if (!hent) { 413 if (!hent) {
414 hent = OPENSSL_malloc(sizeof(BY_DIR_HASH)); 414 hent = malloc(sizeof(BY_DIR_HASH));
415 hent->hash = h; 415 hent->hash = h;
416 hent->suffix = k; 416 hent->suffix = k;
417 if (!sk_BY_DIR_HASH_push(ent->hashes, hent)) { 417 if (!sk_BY_DIR_HASH_push(ent->hashes, hent)) {
418 CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE); 418 CRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);
419 OPENSSL_free(hent); 419 free(hent);
420 ok = 0; 420 ok = 0;
421 goto finish; 421 goto finish;
422 } 422 }
diff --git a/src/lib/libcrypto/x509/x509_cmp.c b/src/lib/libcrypto/x509/x509_cmp.c
index 352aa37434..2f1b8953e5 100644
--- a/src/lib/libcrypto/x509/x509_cmp.c
+++ b/src/lib/libcrypto/x509/x509_cmp.c
@@ -90,7 +90,7 @@ unsigned long X509_issuer_and_serial_hash(X509 *a)
90 goto err; 90 goto err;
91 if (!EVP_DigestUpdate(&ctx,(unsigned char *)f,strlen(f))) 91 if (!EVP_DigestUpdate(&ctx,(unsigned char *)f,strlen(f)))
92 goto err; 92 goto err;
93 OPENSSL_free(f); 93 free(f);
94 if(!EVP_DigestUpdate(&ctx,(unsigned char *)a->cert_info->serialNumber->data, 94 if(!EVP_DigestUpdate(&ctx,(unsigned char *)a->cert_info->serialNumber->data,
95 (unsigned long)a->cert_info->serialNumber->length)) 95 (unsigned long)a->cert_info->serialNumber->length))
96 goto err; 96 goto err;
diff --git a/src/lib/libcrypto/x509/x509_lu.c b/src/lib/libcrypto/x509/x509_lu.c
index 38525a8cdd..644ea83bac 100644
--- a/src/lib/libcrypto/x509/x509_lu.c
+++ b/src/lib/libcrypto/x509/x509_lu.c
@@ -66,7 +66,7 @@ X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method)
66 { 66 {
67 X509_LOOKUP *ret; 67 X509_LOOKUP *ret;
68 68
69 ret=(X509_LOOKUP *)OPENSSL_malloc(sizeof(X509_LOOKUP)); 69 ret=(X509_LOOKUP *)malloc(sizeof(X509_LOOKUP));
70 if (ret == NULL) return NULL; 70 if (ret == NULL) return NULL;
71 71
72 ret->init=0; 72 ret->init=0;
@@ -76,7 +76,7 @@ X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method)
76 ret->store_ctx=NULL; 76 ret->store_ctx=NULL;
77 if ((method->new_item != NULL) && !method->new_item(ret)) 77 if ((method->new_item != NULL) && !method->new_item(ret))
78 { 78 {
79 OPENSSL_free(ret); 79 free(ret);
80 return NULL; 80 return NULL;
81 } 81 }
82 return ret; 82 return ret;
@@ -88,7 +88,7 @@ void X509_LOOKUP_free(X509_LOOKUP *ctx)
88 if ( (ctx->method != NULL) && 88 if ( (ctx->method != NULL) &&
89 (ctx->method->free != NULL)) 89 (ctx->method->free != NULL))
90 (*ctx->method->free)(ctx); 90 (*ctx->method->free)(ctx);
91 OPENSSL_free(ctx); 91 free(ctx);
92 } 92 }
93 93
94int X509_LOOKUP_init(X509_LOOKUP *ctx) 94int X509_LOOKUP_init(X509_LOOKUP *ctx)
@@ -179,7 +179,7 @@ X509_STORE *X509_STORE_new(void)
179 { 179 {
180 X509_STORE *ret; 180 X509_STORE *ret;
181 181
182 if ((ret=(X509_STORE *)OPENSSL_malloc(sizeof(X509_STORE))) == NULL) 182 if ((ret=(X509_STORE *)malloc(sizeof(X509_STORE))) == NULL)
183 return NULL; 183 return NULL;
184 ret->objs = sk_X509_OBJECT_new(x509_object_cmp); 184 ret->objs = sk_X509_OBJECT_new(x509_object_cmp);
185 ret->cache=1; 185 ret->cache=1;
@@ -203,7 +203,7 @@ X509_STORE *X509_STORE_new(void)
203 if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE, ret, &ret->ex_data)) 203 if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE, ret, &ret->ex_data))
204 { 204 {
205 sk_X509_OBJECT_free(ret->objs); 205 sk_X509_OBJECT_free(ret->objs);
206 OPENSSL_free(ret); 206 free(ret);
207 return NULL; 207 return NULL;
208 } 208 }
209 209
@@ -226,7 +226,7 @@ static void cleanup(X509_OBJECT *a)
226 /* abort(); */ 226 /* abort(); */
227 } 227 }
228 228
229 OPENSSL_free(a); 229 free(a);
230 } 230 }
231 231
232void X509_STORE_free(X509_STORE *vfy) 232void X509_STORE_free(X509_STORE *vfy)
@@ -251,7 +251,7 @@ void X509_STORE_free(X509_STORE *vfy)
251 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509_STORE, vfy, &vfy->ex_data); 251 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509_STORE, vfy, &vfy->ex_data);
252 if (vfy->param) 252 if (vfy->param)
253 X509_VERIFY_PARAM_free(vfy->param); 253 X509_VERIFY_PARAM_free(vfy->param);
254 OPENSSL_free(vfy); 254 free(vfy);
255 } 255 }
256 256
257X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m) 257X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, X509_LOOKUP_METHOD *m)
@@ -337,7 +337,7 @@ int X509_STORE_add_cert(X509_STORE *ctx, X509 *x)
337 int ret=1; 337 int ret=1;
338 338
339 if (x == NULL) return 0; 339 if (x == NULL) return 0;
340 obj=(X509_OBJECT *)OPENSSL_malloc(sizeof(X509_OBJECT)); 340 obj=(X509_OBJECT *)malloc(sizeof(X509_OBJECT));
341 if (obj == NULL) 341 if (obj == NULL)
342 { 342 {
343 X509err(X509_F_X509_STORE_ADD_CERT,ERR_R_MALLOC_FAILURE); 343 X509err(X509_F_X509_STORE_ADD_CERT,ERR_R_MALLOC_FAILURE);
@@ -353,7 +353,7 @@ int X509_STORE_add_cert(X509_STORE *ctx, X509 *x)
353 if (X509_OBJECT_retrieve_match(ctx->objs, obj)) 353 if (X509_OBJECT_retrieve_match(ctx->objs, obj))
354 { 354 {
355 X509_OBJECT_free_contents(obj); 355 X509_OBJECT_free_contents(obj);
356 OPENSSL_free(obj); 356 free(obj);
357 X509err(X509_F_X509_STORE_ADD_CERT,X509_R_CERT_ALREADY_IN_HASH_TABLE); 357 X509err(X509_F_X509_STORE_ADD_CERT,X509_R_CERT_ALREADY_IN_HASH_TABLE);
358 ret=0; 358 ret=0;
359 } 359 }
@@ -370,7 +370,7 @@ int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x)
370 int ret=1; 370 int ret=1;
371 371
372 if (x == NULL) return 0; 372 if (x == NULL) return 0;
373 obj=(X509_OBJECT *)OPENSSL_malloc(sizeof(X509_OBJECT)); 373 obj=(X509_OBJECT *)malloc(sizeof(X509_OBJECT));
374 if (obj == NULL) 374 if (obj == NULL)
375 { 375 {
376 X509err(X509_F_X509_STORE_ADD_CRL,ERR_R_MALLOC_FAILURE); 376 X509err(X509_F_X509_STORE_ADD_CRL,ERR_R_MALLOC_FAILURE);
@@ -386,7 +386,7 @@ int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x)
386 if (X509_OBJECT_retrieve_match(ctx->objs, obj)) 386 if (X509_OBJECT_retrieve_match(ctx->objs, obj))
387 { 387 {
388 X509_OBJECT_free_contents(obj); 388 X509_OBJECT_free_contents(obj);
389 OPENSSL_free(obj); 389 free(obj);
390 X509err(X509_F_X509_STORE_ADD_CRL,X509_R_CERT_ALREADY_IN_HASH_TABLE); 390 X509err(X509_F_X509_STORE_ADD_CRL,X509_R_CERT_ALREADY_IN_HASH_TABLE);
391 ret=0; 391 ret=0;
392 } 392 }
diff --git a/src/lib/libcrypto/x509/x509_obj.c b/src/lib/libcrypto/x509/x509_obj.c
index 1d3cf547d7..5f38315f22 100644
--- a/src/lib/libcrypto/x509/x509_obj.c
+++ b/src/lib/libcrypto/x509/x509_obj.c
@@ -88,7 +88,7 @@ int i;
88 if(b) 88 if(b)
89 { 89 {
90 buf=b->data; 90 buf=b->data;
91 OPENSSL_free(b); 91 free(b);
92 } 92 }
93 strlcpy(buf,"NO X509_NAME",len); 93 strlcpy(buf,"NO X509_NAME",len);
94 return buf; 94 return buf;
@@ -170,7 +170,7 @@ int i;
170 if (b != NULL) 170 if (b != NULL)
171 { 171 {
172 p=b->data; 172 p=b->data;
173 OPENSSL_free(b); 173 free(b);
174 } 174 }
175 else 175 else
176 p=buf; 176 p=buf;
diff --git a/src/lib/libcrypto/x509/x509_req.c b/src/lib/libcrypto/x509/x509_req.c
index 48183dc00c..1c5cee8030 100644
--- a/src/lib/libcrypto/x509/x509_req.c
+++ b/src/lib/libcrypto/x509/x509_req.c
@@ -84,7 +84,7 @@ X509_REQ *X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md)
84 ri=ret->req_info; 84 ri=ret->req_info;
85 85
86 ri->version->length=1; 86 ri->version->length=1;
87 ri->version->data=(unsigned char *)OPENSSL_malloc(1); 87 ri->version->data=(unsigned char *)malloc(1);
88 if (ri->version->data == NULL) goto err; 88 if (ri->version->data == NULL) goto err;
89 ri->version->data[0]=0; /* version == 0 */ 89 ri->version->data[0]=0; /* version == 0 */
90 90
diff --git a/src/lib/libcrypto/x509/x509_trs.c b/src/lib/libcrypto/x509/x509_trs.c
index a6cb9c8b1b..7bb5094e64 100644
--- a/src/lib/libcrypto/x509/x509_trs.c
+++ b/src/lib/libcrypto/x509/x509_trs.c
@@ -169,15 +169,15 @@ int X509_TRUST_add(int id, int flags, int (*ck)(X509_TRUST *, X509 *, int),
169 idx = X509_TRUST_get_by_id(id); 169 idx = X509_TRUST_get_by_id(id);
170 /* Need a new entry */ 170 /* Need a new entry */
171 if(idx == -1) { 171 if(idx == -1) {
172 if(!(trtmp = OPENSSL_malloc(sizeof(X509_TRUST)))) { 172 if(!(trtmp = malloc(sizeof(X509_TRUST)))) {
173 X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE); 173 X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);
174 return 0; 174 return 0;
175 } 175 }
176 trtmp->flags = X509_TRUST_DYNAMIC; 176 trtmp->flags = X509_TRUST_DYNAMIC;
177 } else trtmp = X509_TRUST_get0(idx); 177 } else trtmp = X509_TRUST_get0(idx);
178 178
179 /* OPENSSL_free existing name if dynamic */ 179 /* free existing name if dynamic */
180 if(trtmp->flags & X509_TRUST_DYNAMIC_NAME) OPENSSL_free(trtmp->name); 180 if(trtmp->flags & X509_TRUST_DYNAMIC_NAME) free(trtmp->name);
181 /* dup supplied name */ 181 /* dup supplied name */
182 if(!(trtmp->name = BUF_strdup(name))) { 182 if(!(trtmp->name = BUF_strdup(name))) {
183 X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE); 183 X509err(X509_F_X509_TRUST_ADD,ERR_R_MALLOC_FAILURE);
@@ -213,8 +213,8 @@ static void trtable_free(X509_TRUST *p)
213 if (p->flags & X509_TRUST_DYNAMIC) 213 if (p->flags & X509_TRUST_DYNAMIC)
214 { 214 {
215 if (p->flags & X509_TRUST_DYNAMIC_NAME) 215 if (p->flags & X509_TRUST_DYNAMIC_NAME)
216 OPENSSL_free(p->name); 216 free(p->name);
217 OPENSSL_free(p); 217 free(p);
218 } 218 }
219 } 219 }
220 220
diff --git a/src/lib/libcrypto/x509/x509_vfy.c b/src/lib/libcrypto/x509/x509_vfy.c
index a82c2872e0..077bfd8f2d 100644
--- a/src/lib/libcrypto/x509/x509_vfy.c
+++ b/src/lib/libcrypto/x509/x509_vfy.c
@@ -1986,7 +1986,7 @@ int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,
1986X509_STORE_CTX *X509_STORE_CTX_new(void) 1986X509_STORE_CTX *X509_STORE_CTX_new(void)
1987{ 1987{
1988 X509_STORE_CTX *ctx; 1988 X509_STORE_CTX *ctx;
1989 ctx = (X509_STORE_CTX *)OPENSSL_malloc(sizeof(X509_STORE_CTX)); 1989 ctx = (X509_STORE_CTX *)malloc(sizeof(X509_STORE_CTX));
1990 if (!ctx) 1990 if (!ctx)
1991 { 1991 {
1992 X509err(X509_F_X509_STORE_CTX_NEW,ERR_R_MALLOC_FAILURE); 1992 X509err(X509_F_X509_STORE_CTX_NEW,ERR_R_MALLOC_FAILURE);
@@ -1999,7 +1999,7 @@ X509_STORE_CTX *X509_STORE_CTX_new(void)
1999void X509_STORE_CTX_free(X509_STORE_CTX *ctx) 1999void X509_STORE_CTX_free(X509_STORE_CTX *ctx)
2000{ 2000{
2001 X509_STORE_CTX_cleanup(ctx); 2001 X509_STORE_CTX_cleanup(ctx);
2002 OPENSSL_free(ctx); 2002 free(ctx);
2003} 2003}
2004 2004
2005int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509, 2005int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
@@ -2122,7 +2122,7 @@ int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
2122 if(!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE_CTX, ctx, 2122 if(!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE_CTX, ctx,
2123 &(ctx->ex_data))) 2123 &(ctx->ex_data)))
2124 { 2124 {
2125 OPENSSL_free(ctx); 2125 free(ctx);
2126 X509err(X509_F_X509_STORE_CTX_INIT,ERR_R_MALLOC_FAILURE); 2126 X509err(X509_F_X509_STORE_CTX_INIT,ERR_R_MALLOC_FAILURE);
2127 return 0; 2127 return 0;
2128 } 2128 }
diff --git a/src/lib/libcrypto/x509/x509_vpm.c b/src/lib/libcrypto/x509/x509_vpm.c
index dfd89d89fa..5e3eba4029 100644
--- a/src/lib/libcrypto/x509/x509_vpm.c
+++ b/src/lib/libcrypto/x509/x509_vpm.c
@@ -88,7 +88,7 @@ static void x509_verify_param_zero(X509_VERIFY_PARAM *param)
88X509_VERIFY_PARAM *X509_VERIFY_PARAM_new(void) 88X509_VERIFY_PARAM *X509_VERIFY_PARAM_new(void)
89 { 89 {
90 X509_VERIFY_PARAM *param; 90 X509_VERIFY_PARAM *param;
91 param = OPENSSL_malloc(sizeof(X509_VERIFY_PARAM)); 91 param = malloc(sizeof(X509_VERIFY_PARAM));
92 memset(param, 0, sizeof(X509_VERIFY_PARAM)); 92 memset(param, 0, sizeof(X509_VERIFY_PARAM));
93 x509_verify_param_zero(param); 93 x509_verify_param_zero(param);
94 return param; 94 return param;
@@ -97,7 +97,7 @@ X509_VERIFY_PARAM *X509_VERIFY_PARAM_new(void)
97void X509_VERIFY_PARAM_free(X509_VERIFY_PARAM *param) 97void X509_VERIFY_PARAM_free(X509_VERIFY_PARAM *param)
98 { 98 {
99 x509_verify_param_zero(param); 99 x509_verify_param_zero(param);
100 OPENSSL_free(param); 100 free(param);
101 } 101 }
102 102
103/* This function determines how parameters are "inherited" from one structure 103/* This function determines how parameters are "inherited" from one structure
@@ -210,7 +210,7 @@ int X509_VERIFY_PARAM_set1(X509_VERIFY_PARAM *to,
210int X509_VERIFY_PARAM_set1_name(X509_VERIFY_PARAM *param, const char *name) 210int X509_VERIFY_PARAM_set1_name(X509_VERIFY_PARAM *param, const char *name)
211 { 211 {
212 if (param->name) 212 if (param->name)
213 OPENSSL_free(param->name); 213 free(param->name);
214 param->name = BUF_strdup(name); 214 param->name = BUF_strdup(name);
215 if (param->name) 215 if (param->name)
216 return 1; 216 return 1;
diff --git a/src/lib/libcrypto/x509/x509spki.c b/src/lib/libcrypto/x509/x509spki.c
index 02a203d72c..28bc12e1a2 100644
--- a/src/lib/libcrypto/x509/x509spki.c
+++ b/src/lib/libcrypto/x509/x509spki.c
@@ -82,7 +82,7 @@ NETSCAPE_SPKI * NETSCAPE_SPKI_b64_decode(const char *str, int len)
82 int spki_len; 82 int spki_len;
83 NETSCAPE_SPKI *spki; 83 NETSCAPE_SPKI *spki;
84 if(len <= 0) len = strlen(str); 84 if(len <= 0) len = strlen(str);
85 if (!(spki_der = OPENSSL_malloc(len + 1))) { 85 if (!(spki_der = malloc(len + 1))) {
86 X509err(X509_F_NETSCAPE_SPKI_B64_DECODE, ERR_R_MALLOC_FAILURE); 86 X509err(X509_F_NETSCAPE_SPKI_B64_DECODE, ERR_R_MALLOC_FAILURE);
87 return NULL; 87 return NULL;
88 } 88 }
@@ -90,12 +90,12 @@ NETSCAPE_SPKI * NETSCAPE_SPKI_b64_decode(const char *str, int len)
90 if(spki_len < 0) { 90 if(spki_len < 0) {
91 X509err(X509_F_NETSCAPE_SPKI_B64_DECODE, 91 X509err(X509_F_NETSCAPE_SPKI_B64_DECODE,
92 X509_R_BASE64_DECODE_ERROR); 92 X509_R_BASE64_DECODE_ERROR);
93 OPENSSL_free(spki_der); 93 free(spki_der);
94 return NULL; 94 return NULL;
95 } 95 }
96 p = spki_der; 96 p = spki_der;
97 spki = d2i_NETSCAPE_SPKI(NULL, &p, spki_len); 97 spki = d2i_NETSCAPE_SPKI(NULL, &p, spki_len);
98 OPENSSL_free(spki_der); 98 free(spki_der);
99 return spki; 99 return spki;
100} 100}
101 101
@@ -107,8 +107,8 @@ char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *spki)
107 char *b64_str; 107 char *b64_str;
108 int der_len; 108 int der_len;
109 der_len = i2d_NETSCAPE_SPKI(spki, NULL); 109 der_len = i2d_NETSCAPE_SPKI(spki, NULL);
110 der_spki = OPENSSL_malloc(der_len); 110 der_spki = malloc(der_len);
111 b64_str = OPENSSL_malloc(der_len * 2); 111 b64_str = malloc(der_len * 2);
112 if(!der_spki || !b64_str) { 112 if(!der_spki || !b64_str) {
113 X509err(X509_F_NETSCAPE_SPKI_B64_ENCODE, ERR_R_MALLOC_FAILURE); 113 X509err(X509_F_NETSCAPE_SPKI_B64_ENCODE, ERR_R_MALLOC_FAILURE);
114 return NULL; 114 return NULL;
@@ -116,6 +116,6 @@ char * NETSCAPE_SPKI_b64_encode(NETSCAPE_SPKI *spki)
116 p = der_spki; 116 p = der_spki;
117 i2d_NETSCAPE_SPKI(spki, &p); 117 i2d_NETSCAPE_SPKI(spki, &p);
118 EVP_EncodeBlock((unsigned char *)b64_str, der_spki, der_len); 118 EVP_EncodeBlock((unsigned char *)b64_str, der_spki, der_len);
119 OPENSSL_free(der_spki); 119 free(der_spki);
120 return b64_str; 120 return b64_str;
121} 121}
diff --git a/src/lib/libcrypto/x509v3/pcy_cache.c b/src/lib/libcrypto/x509v3/pcy_cache.c
index 172b7e7ee4..24c79b4a80 100644
--- a/src/lib/libcrypto/x509v3/pcy_cache.c
+++ b/src/lib/libcrypto/x509v3/pcy_cache.c
@@ -134,7 +134,7 @@ static int policy_cache_new(X509 *x)
134 CERTIFICATEPOLICIES *ext_cpols = NULL; 134 CERTIFICATEPOLICIES *ext_cpols = NULL;
135 POLICY_MAPPINGS *ext_pmaps = NULL; 135 POLICY_MAPPINGS *ext_pmaps = NULL;
136 int i; 136 int i;
137 cache = OPENSSL_malloc(sizeof(X509_POLICY_CACHE)); 137 cache = malloc(sizeof(X509_POLICY_CACHE));
138 if (!cache) 138 if (!cache)
139 return 0; 139 return 0;
140 cache->anyPolicy = NULL; 140 cache->anyPolicy = NULL;
@@ -240,7 +240,7 @@ void policy_cache_free(X509_POLICY_CACHE *cache)
240 policy_data_free(cache->anyPolicy); 240 policy_data_free(cache->anyPolicy);
241 if (cache->data) 241 if (cache->data)
242 sk_X509_POLICY_DATA_pop_free(cache->data, policy_data_free); 242 sk_X509_POLICY_DATA_pop_free(cache->data, policy_data_free);
243 OPENSSL_free(cache); 243 free(cache);
244 } 244 }
245 245
246const X509_POLICY_CACHE *policy_cache_set(X509 *x) 246const X509_POLICY_CACHE *policy_cache_set(X509 *x)
diff --git a/src/lib/libcrypto/x509v3/pcy_data.c b/src/lib/libcrypto/x509v3/pcy_data.c
index 3444b03195..7c80915f5b 100644
--- a/src/lib/libcrypto/x509v3/pcy_data.c
+++ b/src/lib/libcrypto/x509v3/pcy_data.c
@@ -72,7 +72,7 @@ void policy_data_free(X509_POLICY_DATA *data)
72 sk_POLICYQUALINFO_pop_free(data->qualifier_set, 72 sk_POLICYQUALINFO_pop_free(data->qualifier_set,
73 POLICYQUALINFO_free); 73 POLICYQUALINFO_free);
74 sk_ASN1_OBJECT_pop_free(data->expected_policy_set, ASN1_OBJECT_free); 74 sk_ASN1_OBJECT_pop_free(data->expected_policy_set, ASN1_OBJECT_free);
75 OPENSSL_free(data); 75 free(data);
76 } 76 }
77 77
78/* Create a data based on an existing policy. If 'id' is NULL use the 78/* Create a data based on an existing policy. If 'id' is NULL use the
@@ -97,13 +97,13 @@ X509_POLICY_DATA *policy_data_new(POLICYINFO *policy,
97 } 97 }
98 else 98 else
99 id = NULL; 99 id = NULL;
100 ret = OPENSSL_malloc(sizeof(X509_POLICY_DATA)); 100 ret = malloc(sizeof(X509_POLICY_DATA));
101 if (!ret) 101 if (!ret)
102 return NULL; 102 return NULL;
103 ret->expected_policy_set = sk_ASN1_OBJECT_new_null(); 103 ret->expected_policy_set = sk_ASN1_OBJECT_new_null();
104 if (!ret->expected_policy_set) 104 if (!ret->expected_policy_set)
105 { 105 {
106 OPENSSL_free(ret); 106 free(ret);
107 if (id) 107 if (id)
108 ASN1_OBJECT_free(id); 108 ASN1_OBJECT_free(id);
109 return NULL; 109 return NULL;
diff --git a/src/lib/libcrypto/x509v3/pcy_node.c b/src/lib/libcrypto/x509v3/pcy_node.c
index bd1e7f1ae8..8c2124a7f6 100644
--- a/src/lib/libcrypto/x509v3/pcy_node.c
+++ b/src/lib/libcrypto/x509v3/pcy_node.c
@@ -115,7 +115,7 @@ X509_POLICY_NODE *level_add_node(X509_POLICY_LEVEL *level,
115 X509_POLICY_TREE *tree) 115 X509_POLICY_TREE *tree)
116 { 116 {
117 X509_POLICY_NODE *node; 117 X509_POLICY_NODE *node;
118 node = OPENSSL_malloc(sizeof(X509_POLICY_NODE)); 118 node = malloc(sizeof(X509_POLICY_NODE));
119 if (!node) 119 if (!node)
120 return NULL; 120 return NULL;
121 node->data = data; 121 node->data = data;
@@ -164,7 +164,7 @@ X509_POLICY_NODE *level_add_node(X509_POLICY_LEVEL *level,
164 164
165void policy_node_free(X509_POLICY_NODE *node) 165void policy_node_free(X509_POLICY_NODE *node)
166 { 166 {
167 OPENSSL_free(node); 167 free(node);
168 } 168 }
169 169
170/* See if a policy node matches a policy OID. If mapping enabled look through 170/* See if a policy node matches a policy OID. If mapping enabled look through
diff --git a/src/lib/libcrypto/x509v3/pcy_tree.c b/src/lib/libcrypto/x509v3/pcy_tree.c
index bb9777348f..c4239b1fd9 100644
--- a/src/lib/libcrypto/x509v3/pcy_tree.c
+++ b/src/lib/libcrypto/x509v3/pcy_tree.c
@@ -219,13 +219,13 @@ static int tree_init(X509_POLICY_TREE **ptree, STACK_OF(X509) *certs,
219 219
220 /* If we get this far initialize the tree */ 220 /* If we get this far initialize the tree */
221 221
222 tree = OPENSSL_malloc(sizeof(X509_POLICY_TREE)); 222 tree = malloc(sizeof(X509_POLICY_TREE));
223 223
224 if (!tree) 224 if (!tree)
225 return 0; 225 return 0;
226 226
227 tree->flags = 0; 227 tree->flags = 0;
228 tree->levels = OPENSSL_malloc(sizeof(X509_POLICY_LEVEL) * n); 228 tree->levels = malloc(sizeof(X509_POLICY_LEVEL) * n);
229 tree->nlevel = 0; 229 tree->nlevel = 0;
230 tree->extra_data = NULL; 230 tree->extra_data = NULL;
231 tree->auth_policies = NULL; 231 tree->auth_policies = NULL;
@@ -233,7 +233,7 @@ static int tree_init(X509_POLICY_TREE **ptree, STACK_OF(X509) *certs,
233 233
234 if (!tree->levels) 234 if (!tree->levels)
235 { 235 {
236 OPENSSL_free(tree); 236 free(tree);
237 return 0; 237 return 0;
238 } 238 }
239 239
@@ -516,7 +516,7 @@ static int tree_prune(X509_POLICY_TREE *tree, X509_POLICY_LEVEL *curr)
516 if (node->data->flags & POLICY_DATA_FLAG_MAP_MASK) 516 if (node->data->flags & POLICY_DATA_FLAG_MAP_MASK)
517 { 517 {
518 node->parent->nchild--; 518 node->parent->nchild--;
519 OPENSSL_free(node); 519 free(node);
520 (void)sk_X509_POLICY_NODE_delete(nodes,i); 520 (void)sk_X509_POLICY_NODE_delete(nodes,i);
521 } 521 }
522 } 522 }
@@ -531,7 +531,7 @@ static int tree_prune(X509_POLICY_TREE *tree, X509_POLICY_LEVEL *curr)
531 if (node->nchild == 0) 531 if (node->nchild == 0)
532 { 532 {
533 node->parent->nchild--; 533 node->parent->nchild--;
534 OPENSSL_free(node); 534 free(node);
535 (void)sk_X509_POLICY_NODE_delete(nodes, i); 535 (void)sk_X509_POLICY_NODE_delete(nodes, i);
536 } 536 }
537 } 537 }
@@ -539,7 +539,7 @@ static int tree_prune(X509_POLICY_TREE *tree, X509_POLICY_LEVEL *curr)
539 { 539 {
540 if (curr->anyPolicy->parent) 540 if (curr->anyPolicy->parent)
541 curr->anyPolicy->parent->nchild--; 541 curr->anyPolicy->parent->nchild--;
542 OPENSSL_free(curr->anyPolicy); 542 free(curr->anyPolicy);
543 curr->anyPolicy = NULL; 543 curr->anyPolicy = NULL;
544 } 544 }
545 if (curr == tree->levels) 545 if (curr == tree->levels)
@@ -721,7 +721,7 @@ static int tree_evaluate(X509_POLICY_TREE *tree)
721static void exnode_free(X509_POLICY_NODE *node) 721static void exnode_free(X509_POLICY_NODE *node)
722 { 722 {
723 if (node->data && (node->data->flags & POLICY_DATA_FLAG_EXTRA_NODE)) 723 if (node->data && (node->data->flags & POLICY_DATA_FLAG_EXTRA_NODE))
724 OPENSSL_free(node); 724 free(node);
725 } 725 }
726 726
727 727
@@ -751,8 +751,8 @@ void X509_policy_tree_free(X509_POLICY_TREE *tree)
751 sk_X509_POLICY_DATA_pop_free(tree->extra_data, 751 sk_X509_POLICY_DATA_pop_free(tree->extra_data,
752 policy_data_free); 752 policy_data_free);
753 753
754 OPENSSL_free(tree->levels); 754 free(tree->levels);
755 OPENSSL_free(tree); 755 free(tree);
756 756
757 } 757 }
758 758
diff --git a/src/lib/libcrypto/x509v3/v3_addr.c b/src/lib/libcrypto/x509v3/v3_addr.c
index df46a4983b..179f08d222 100644
--- a/src/lib/libcrypto/x509v3/v3_addr.c
+++ b/src/lib/libcrypto/x509v3/v3_addr.c
@@ -1013,7 +1013,7 @@ static void *v2i_IPAddrBlocks(const struct v3_ext_method *method,
1013 X509V3_conf_err(val); 1013 X509V3_conf_err(val);
1014 goto err; 1014 goto err;
1015 } 1015 }
1016 OPENSSL_free(s); 1016 free(s);
1017 s = NULL; 1017 s = NULL;
1018 continue; 1018 continue;
1019 } 1019 }
@@ -1077,7 +1077,7 @@ static void *v2i_IPAddrBlocks(const struct v3_ext_method *method,
1077 goto err; 1077 goto err;
1078 } 1078 }
1079 1079
1080 OPENSSL_free(s); 1080 free(s);
1081 s = NULL; 1081 s = NULL;
1082 } 1082 }
1083 1083
@@ -1089,7 +1089,7 @@ static void *v2i_IPAddrBlocks(const struct v3_ext_method *method,
1089 return addr; 1089 return addr;
1090 1090
1091 err: 1091 err:
1092 OPENSSL_free(s); 1092 free(s);
1093 sk_IPAddressFamily_pop_free(addr, IPAddressFamily_free); 1093 sk_IPAddressFamily_pop_free(addr, IPAddressFamily_free);
1094 return NULL; 1094 return NULL;
1095} 1095}
diff --git a/src/lib/libcrypto/x509v3/v3_akey.c b/src/lib/libcrypto/x509v3/v3_akey.c
index c6b68ee221..04e1fb9544 100644
--- a/src/lib/libcrypto/x509v3/v3_akey.c
+++ b/src/lib/libcrypto/x509v3/v3_akey.c
@@ -87,7 +87,7 @@ static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
87 if(akeyid->keyid) { 87 if(akeyid->keyid) {
88 tmp = hex_to_string(akeyid->keyid->data, akeyid->keyid->length); 88 tmp = hex_to_string(akeyid->keyid->data, akeyid->keyid->length);
89 X509V3_add_value("keyid", tmp, &extlist); 89 X509V3_add_value("keyid", tmp, &extlist);
90 OPENSSL_free(tmp); 90 free(tmp);
91 } 91 }
92 if(akeyid->issuer) 92 if(akeyid->issuer)
93 extlist = i2v_GENERAL_NAMES(NULL, akeyid->issuer, extlist); 93 extlist = i2v_GENERAL_NAMES(NULL, akeyid->issuer, extlist);
@@ -95,7 +95,7 @@ static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
95 tmp = hex_to_string(akeyid->serial->data, 95 tmp = hex_to_string(akeyid->serial->data,
96 akeyid->serial->length); 96 akeyid->serial->length);
97 X509V3_add_value("serial", tmp, &extlist); 97 X509V3_add_value("serial", tmp, &extlist);
98 OPENSSL_free(tmp); 98 free(tmp);
99 } 99 }
100 return extlist; 100 return extlist;
101} 101}
diff --git a/src/lib/libcrypto/x509v3/v3_alt.c b/src/lib/libcrypto/x509v3/v3_alt.c
index 8de5dd041b..636677df94 100644
--- a/src/lib/libcrypto/x509v3/v3_alt.c
+++ b/src/lib/libcrypto/x509v3/v3_alt.c
@@ -578,11 +578,11 @@ static int do_othername(GENERAL_NAME *gen, char *value, X509V3_CTX *ctx)
578 if (!(gen->d.otherName->value = ASN1_generate_v3(p + 1, ctx))) 578 if (!(gen->d.otherName->value = ASN1_generate_v3(p + 1, ctx)))
579 return 0; 579 return 0;
580 objlen = p - value; 580 objlen = p - value;
581 objtmp = OPENSSL_malloc(objlen + 1); 581 objtmp = malloc(objlen + 1);
582 if (objtmp) { 582 if (objtmp) {
583 strlcpy(objtmp, value, objlen + 1); 583 strlcpy(objtmp, value, objlen + 1);
584 gen->d.otherName->type_id = OBJ_txt2obj(objtmp, 0); 584 gen->d.otherName->type_id = OBJ_txt2obj(objtmp, 0);
585 OPENSSL_free(objtmp); 585 free(objtmp);
586 } else 586 } else
587 gen->d.otherName->type_id = NULL; 587 gen->d.otherName->type_id = NULL;
588 if (!gen->d.otherName->type_id) 588 if (!gen->d.otherName->type_id)
diff --git a/src/lib/libcrypto/x509v3/v3_asid.c b/src/lib/libcrypto/x509v3/v3_asid.c
index 1587e8ed72..325c8e0406 100644
--- a/src/lib/libcrypto/x509v3/v3_asid.c
+++ b/src/lib/libcrypto/x509v3/v3_asid.c
@@ -125,17 +125,17 @@ static int i2r_ASIdentifierChoice(BIO *out,
125 if ((s = i2s_ASN1_INTEGER(NULL, aor->u.id)) == NULL) 125 if ((s = i2s_ASN1_INTEGER(NULL, aor->u.id)) == NULL)
126 return 0; 126 return 0;
127 BIO_printf(out, "%*s%s\n", indent + 2, "", s); 127 BIO_printf(out, "%*s%s\n", indent + 2, "", s);
128 OPENSSL_free(s); 128 free(s);
129 break; 129 break;
130 case ASIdOrRange_range: 130 case ASIdOrRange_range:
131 if ((s = i2s_ASN1_INTEGER(NULL, aor->u.range->min)) == NULL) 131 if ((s = i2s_ASN1_INTEGER(NULL, aor->u.range->min)) == NULL)
132 return 0; 132 return 0;
133 BIO_printf(out, "%*s%s-", indent + 2, "", s); 133 BIO_printf(out, "%*s%s-", indent + 2, "", s);
134 OPENSSL_free(s); 134 free(s);
135 if ((s = i2s_ASN1_INTEGER(NULL, aor->u.range->max)) == NULL) 135 if ((s = i2s_ASN1_INTEGER(NULL, aor->u.range->max)) == NULL)
136 return 0; 136 return 0;
137 BIO_printf(out, "%s\n", s); 137 BIO_printf(out, "%s\n", s);
138 OPENSSL_free(s); 138 free(s);
139 break; 139 break;
140 default: 140 default:
141 return 0; 141 return 0;
@@ -471,7 +471,7 @@ static int ASIdentifierChoice_canonize(ASIdentifierChoice *choice)
471 ASRange *r; 471 ASRange *r;
472 switch (a->type) { 472 switch (a->type) {
473 case ASIdOrRange_id: 473 case ASIdOrRange_id:
474 if ((r = OPENSSL_malloc(sizeof(ASRange))) == NULL) { 474 if ((r = malloc(sizeof(ASRange))) == NULL) {
475 X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE, 475 X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,
476 ERR_R_MALLOC_FAILURE); 476 ERR_R_MALLOC_FAILURE);
477 goto done; 477 goto done;
@@ -620,7 +620,7 @@ static void *v2i_ASIdentifiers(const struct v3_ext_method *method,
620 s[i1] = '\0'; 620 s[i1] = '\0';
621 min = s2i_ASN1_INTEGER(NULL, s); 621 min = s2i_ASN1_INTEGER(NULL, s);
622 max = s2i_ASN1_INTEGER(NULL, s + i2); 622 max = s2i_ASN1_INTEGER(NULL, s + i2);
623 OPENSSL_free(s); 623 free(s);
624 if (min == NULL || max == NULL) { 624 if (min == NULL || max == NULL) {
625 X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE); 625 X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE);
626 goto err; 626 goto err;
diff --git a/src/lib/libcrypto/x509v3/v3_conf.c b/src/lib/libcrypto/x509v3/v3_conf.c
index 6730f9a6ee..519aefc93c 100644
--- a/src/lib/libcrypto/x509v3/v3_conf.c
+++ b/src/lib/libcrypto/x509v3/v3_conf.c
@@ -190,7 +190,7 @@ static X509_EXTENSION *do_ext_i2d(const X509V3_EXT_METHOD *method, int ext_nid,
190 { 190 {
191 unsigned char *p; 191 unsigned char *p;
192 ext_len = method->i2d(ext_struc, NULL); 192 ext_len = method->i2d(ext_struc, NULL);
193 if(!(ext_der = OPENSSL_malloc(ext_len))) goto merr; 193 if(!(ext_der = malloc(ext_len))) goto merr;
194 p = ext_der; 194 p = ext_der;
195 method->i2d(ext_struc, &p); 195 method->i2d(ext_struc, &p);
196 } 196 }
@@ -300,7 +300,7 @@ static X509_EXTENSION *v3_generic_extension(const char *ext, char *value,
300 err: 300 err:
301 ASN1_OBJECT_free(obj); 301 ASN1_OBJECT_free(obj);
302 M_ASN1_OCTET_STRING_free(oct); 302 M_ASN1_OCTET_STRING_free(oct);
303 if(ext_der) OPENSSL_free(ext_der); 303 if(ext_der) free(ext_der);
304 return extension; 304 return extension;
305 305
306 } 306 }
diff --git a/src/lib/libcrypto/x509v3/v3_cpols.c b/src/lib/libcrypto/x509v3/v3_cpols.c
index 1f0798b946..1a337fa07e 100644
--- a/src/lib/libcrypto/x509v3/v3_cpols.c
+++ b/src/lib/libcrypto/x509v3/v3_cpols.c
@@ -426,7 +426,7 @@ static void print_notice(BIO *out, USERNOTICE *notice, int indent)
426 if(i) BIO_puts(out, ", "); 426 if(i) BIO_puts(out, ", ");
427 tmp = i2s_ASN1_INTEGER(NULL, num); 427 tmp = i2s_ASN1_INTEGER(NULL, num);
428 BIO_puts(out, tmp); 428 BIO_puts(out, tmp);
429 OPENSSL_free(tmp); 429 free(tmp);
430 } 430 }
431 BIO_puts(out, "\n"); 431 BIO_puts(out, "\n");
432 } 432 }
diff --git a/src/lib/libcrypto/x509v3/v3_ia5.c b/src/lib/libcrypto/x509v3/v3_ia5.c
index ab1c5188b8..98789b36e9 100644
--- a/src/lib/libcrypto/x509v3/v3_ia5.c
+++ b/src/lib/libcrypto/x509v3/v3_ia5.c
@@ -82,7 +82,7 @@ static char *i2s_ASN1_IA5STRING(X509V3_EXT_METHOD *method,
82{ 82{
83 char *tmp; 83 char *tmp;
84 if(!ia5 || !ia5->length) return NULL; 84 if(!ia5 || !ia5->length) return NULL;
85 if(!(tmp = OPENSSL_malloc(ia5->length + 1))) { 85 if(!(tmp = malloc(ia5->length + 1))) {
86 X509V3err(X509V3_F_I2S_ASN1_IA5STRING,ERR_R_MALLOC_FAILURE); 86 X509V3err(X509V3_F_I2S_ASN1_IA5STRING,ERR_R_MALLOC_FAILURE);
87 return NULL; 87 return NULL;
88 } 88 }
diff --git a/src/lib/libcrypto/x509v3/v3_info.c b/src/lib/libcrypto/x509v3/v3_info.c
index 44bc3e1105..2b290ca00c 100644
--- a/src/lib/libcrypto/x509v3/v3_info.c
+++ b/src/lib/libcrypto/x509v3/v3_info.c
@@ -115,7 +115,7 @@ static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method
115 vtmp = sk_CONF_VALUE_value(ret, i); 115 vtmp = sk_CONF_VALUE_value(ret, i);
116 i2t_ASN1_OBJECT(objtmp, sizeof objtmp, desc->method); 116 i2t_ASN1_OBJECT(objtmp, sizeof objtmp, desc->method);
117 nlen = strlen(objtmp) + strlen(vtmp->name) + 5; 117 nlen = strlen(objtmp) + strlen(vtmp->name) + 5;
118 ntmp = OPENSSL_malloc(nlen); 118 ntmp = malloc(nlen);
119 if(!ntmp) { 119 if(!ntmp) {
120 X509V3err(X509V3_F_I2V_AUTHORITY_INFO_ACCESS, 120 X509V3err(X509V3_F_I2V_AUTHORITY_INFO_ACCESS,
121 ERR_R_MALLOC_FAILURE); 121 ERR_R_MALLOC_FAILURE);
@@ -124,7 +124,7 @@ static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method
124 BUF_strlcpy(ntmp, objtmp, nlen); 124 BUF_strlcpy(ntmp, objtmp, nlen);
125 BUF_strlcat(ntmp, " - ", nlen); 125 BUF_strlcat(ntmp, " - ", nlen);
126 BUF_strlcat(ntmp, vtmp->name, nlen); 126 BUF_strlcat(ntmp, vtmp->name, nlen);
127 OPENSSL_free(vtmp->name); 127 free(vtmp->name);
128 vtmp->name = ntmp; 128 vtmp->name = ntmp;
129 129
130 } 130 }
@@ -161,7 +161,7 @@ static AUTHORITY_INFO_ACCESS *v2i_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *metho
161 ctmp.value = cnf->value; 161 ctmp.value = cnf->value;
162 if(!v2i_GENERAL_NAME_ex(acc->location, method, ctx, &ctmp, 0)) 162 if(!v2i_GENERAL_NAME_ex(acc->location, method, ctx, &ctmp, 0))
163 goto err; 163 goto err;
164 if(!(objtmp = OPENSSL_malloc(objlen + 1))) { 164 if(!(objtmp = malloc(objlen + 1))) {
165 X509V3err(X509V3_F_V2I_AUTHORITY_INFO_ACCESS,ERR_R_MALLOC_FAILURE); 165 X509V3err(X509V3_F_V2I_AUTHORITY_INFO_ACCESS,ERR_R_MALLOC_FAILURE);
166 goto err; 166 goto err;
167 } 167 }
@@ -170,10 +170,10 @@ static AUTHORITY_INFO_ACCESS *v2i_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *metho
170 if(!acc->method) { 170 if(!acc->method) {
171 X509V3err(X509V3_F_V2I_AUTHORITY_INFO_ACCESS,X509V3_R_BAD_OBJECT); 171 X509V3err(X509V3_F_V2I_AUTHORITY_INFO_ACCESS,X509V3_R_BAD_OBJECT);
172 ERR_add_error_data(2, "value=", objtmp); 172 ERR_add_error_data(2, "value=", objtmp);
173 OPENSSL_free(objtmp); 173 free(objtmp);
174 goto err; 174 goto err;
175 } 175 }
176 OPENSSL_free(objtmp); 176 free(objtmp);
177 177
178 } 178 }
179 return ainfo; 179 return ainfo;
diff --git a/src/lib/libcrypto/x509v3/v3_lib.c b/src/lib/libcrypto/x509v3/v3_lib.c
index 0f1e1d4422..0613ea7f22 100644
--- a/src/lib/libcrypto/x509v3/v3_lib.c
+++ b/src/lib/libcrypto/x509v3/v3_lib.c
@@ -133,7 +133,7 @@ int X509V3_EXT_add_alias(int nid_to, int nid_from)
133 X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS,X509V3_R_EXTENSION_NOT_FOUND); 133 X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS,X509V3_R_EXTENSION_NOT_FOUND);
134 return 0; 134 return 0;
135 } 135 }
136 if(!(tmpext = (X509V3_EXT_METHOD *)OPENSSL_malloc(sizeof(X509V3_EXT_METHOD)))) { 136 if(!(tmpext = (X509V3_EXT_METHOD *)malloc(sizeof(X509V3_EXT_METHOD)))) {
137 X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS,ERR_R_MALLOC_FAILURE); 137 X509V3err(X509V3_F_X509V3_EXT_ADD_ALIAS,ERR_R_MALLOC_FAILURE);
138 return 0; 138 return 0;
139 } 139 }
@@ -151,7 +151,7 @@ void X509V3_EXT_cleanup(void)
151 151
152static void ext_list_free(X509V3_EXT_METHOD *ext) 152static void ext_list_free(X509V3_EXT_METHOD *ext)
153{ 153{
154 if(ext->ext_flags & X509V3_EXT_DYNAMIC) OPENSSL_free(ext); 154 if(ext->ext_flags & X509V3_EXT_DYNAMIC) free(ext);
155} 155}
156 156
157/* Legacy function: we don't need to add standard extensions 157/* Legacy function: we don't need to add standard extensions
diff --git a/src/lib/libcrypto/x509v3/v3_pci.c b/src/lib/libcrypto/x509v3/v3_pci.c
index 0dcfa004fe..9cef94258c 100644
--- a/src/lib/libcrypto/x509v3/v3_pci.c
+++ b/src/lib/libcrypto/x509v3/v3_pci.c
@@ -135,7 +135,7 @@ static int process_pci_value(CONF_VALUE *val,
135 goto err; 135 goto err;
136 } 136 }
137 137
138 tmp_data = OPENSSL_realloc((*policy)->data, 138 tmp_data = realloc((*policy)->data,
139 (*policy)->length + val_len + 1); 139 (*policy)->length + val_len + 1);
140 if (tmp_data) 140 if (tmp_data)
141 { 141 {
@@ -147,7 +147,7 @@ static int process_pci_value(CONF_VALUE *val,
147 } 147 }
148 else 148 else
149 { 149 {
150 OPENSSL_free(tmp_data2); 150 free(tmp_data2);
151 /* realloc failure implies the original data space is b0rked too! */ 151 /* realloc failure implies the original data space is b0rked too! */
152 (*policy)->data = NULL; 152 (*policy)->data = NULL;
153 (*policy)->length = 0; 153 (*policy)->length = 0;
@@ -155,7 +155,7 @@ static int process_pci_value(CONF_VALUE *val,
155 X509V3_conf_err(val); 155 X509V3_conf_err(val);
156 goto err; 156 goto err;
157 } 157 }
158 OPENSSL_free(tmp_data2); 158 free(tmp_data2);
159 } 159 }
160 else if (strncmp(val->value, "file:", 5) == 0) 160 else if (strncmp(val->value, "file:", 5) == 0)
161 { 161 {
@@ -173,7 +173,7 @@ static int process_pci_value(CONF_VALUE *val,
173 { 173 {
174 if (!n) continue; 174 if (!n) continue;
175 175
176 tmp_data = OPENSSL_realloc((*policy)->data, 176 tmp_data = realloc((*policy)->data,
177 (*policy)->length + n + 1); 177 (*policy)->length + n + 1);
178 178
179 if (!tmp_data) 179 if (!tmp_data)
@@ -197,7 +197,7 @@ static int process_pci_value(CONF_VALUE *val,
197 else if (strncmp(val->value, "text:", 5) == 0) 197 else if (strncmp(val->value, "text:", 5) == 0)
198 { 198 {
199 val_len = strlen(val->value + 5); 199 val_len = strlen(val->value + 5);
200 tmp_data = OPENSSL_realloc((*policy)->data, 200 tmp_data = realloc((*policy)->data,
201 (*policy)->length + val_len + 1); 201 (*policy)->length + val_len + 1);
202 if (tmp_data) 202 if (tmp_data)
203 { 203 {
diff --git a/src/lib/libcrypto/x509v3/v3_prn.c b/src/lib/libcrypto/x509v3/v3_prn.c
index 2124b447b4..565937af47 100644
--- a/src/lib/libcrypto/x509v3/v3_prn.c
+++ b/src/lib/libcrypto/x509v3/v3_prn.c
@@ -126,7 +126,7 @@ int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, int inde
126 126
127 err: 127 err:
128 sk_CONF_VALUE_pop_free(nval, X509V3_conf_free); 128 sk_CONF_VALUE_pop_free(nval, X509V3_conf_free);
129 if(value) OPENSSL_free(value); 129 if(value) free(value);
130 if(method->it) ASN1_item_free(ext_str, ASN1_ITEM_ptr(method->it)); 130 if(method->it) ASN1_item_free(ext_str, ASN1_ITEM_ptr(method->it));
131 else method->ext_free(ext_str); 131 else method->ext_free(ext_str);
132 return ok; 132 return ok;
diff --git a/src/lib/libcrypto/x509v3/v3_purp.c b/src/lib/libcrypto/x509v3/v3_purp.c
index f59bfc1844..45d7251c29 100644
--- a/src/lib/libcrypto/x509v3/v3_purp.c
+++ b/src/lib/libcrypto/x509v3/v3_purp.c
@@ -183,17 +183,17 @@ int X509_PURPOSE_add(int id, int trust, int flags,
183 idx = X509_PURPOSE_get_by_id(id); 183 idx = X509_PURPOSE_get_by_id(id);
184 /* Need a new entry */ 184 /* Need a new entry */
185 if(idx == -1) { 185 if(idx == -1) {
186 if(!(ptmp = OPENSSL_malloc(sizeof(X509_PURPOSE)))) { 186 if(!(ptmp = malloc(sizeof(X509_PURPOSE)))) {
187 X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE); 187 X509V3err(X509V3_F_X509_PURPOSE_ADD,ERR_R_MALLOC_FAILURE);
188 return 0; 188 return 0;
189 } 189 }
190 ptmp->flags = X509_PURPOSE_DYNAMIC; 190 ptmp->flags = X509_PURPOSE_DYNAMIC;
191 } else ptmp = X509_PURPOSE_get0(idx); 191 } else ptmp = X509_PURPOSE_get0(idx);
192 192
193 /* OPENSSL_free existing name if dynamic */ 193 /* free existing name if dynamic */
194 if(ptmp->flags & X509_PURPOSE_DYNAMIC_NAME) { 194 if(ptmp->flags & X509_PURPOSE_DYNAMIC_NAME) {
195 OPENSSL_free(ptmp->name); 195 free(ptmp->name);
196 OPENSSL_free(ptmp->sname); 196 free(ptmp->sname);
197 } 197 }
198 /* dup supplied name */ 198 /* dup supplied name */
199 ptmp->name = BUF_strdup(name); 199 ptmp->name = BUF_strdup(name);
@@ -232,10 +232,10 @@ static void xptable_free(X509_PURPOSE *p)
232 if (p->flags & X509_PURPOSE_DYNAMIC) 232 if (p->flags & X509_PURPOSE_DYNAMIC)
233 { 233 {
234 if (p->flags & X509_PURPOSE_DYNAMIC_NAME) { 234 if (p->flags & X509_PURPOSE_DYNAMIC_NAME) {
235 OPENSSL_free(p->name); 235 free(p->name);
236 OPENSSL_free(p->sname); 236 free(p->sname);
237 } 237 }
238 OPENSSL_free(p); 238 free(p);
239 } 239 }
240 } 240 }
241 241
diff --git a/src/lib/libcrypto/x509v3/v3_sxnet.c b/src/lib/libcrypto/x509v3/v3_sxnet.c
index 2a6bf11b65..a2b0322e44 100644
--- a/src/lib/libcrypto/x509v3/v3_sxnet.c
+++ b/src/lib/libcrypto/x509v3/v3_sxnet.c
@@ -114,7 +114,7 @@ static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out,
114 id = sk_SXNETID_value(sx->ids, i); 114 id = sk_SXNETID_value(sx->ids, i);
115 tmp = i2s_ASN1_INTEGER(NULL, id->zone); 115 tmp = i2s_ASN1_INTEGER(NULL, id->zone);
116 BIO_printf(out, "\n%*sZone: %s, User: ", indent, "", tmp); 116 BIO_printf(out, "\n%*sZone: %s, User: ", indent, "", tmp);
117 OPENSSL_free(tmp); 117 free(tmp);
118 M_ASN1_OCTET_STRING_print(out, id->user); 118 M_ASN1_OCTET_STRING_print(out, id->user);
119 } 119 }
120 return 1; 120 return 1;
diff --git a/src/lib/libcrypto/x509v3/v3_utl.c b/src/lib/libcrypto/x509v3/v3_utl.c
index c4b6143eff..d938a175ed 100644
--- a/src/lib/libcrypto/x509v3/v3_utl.c
+++ b/src/lib/libcrypto/x509v3/v3_utl.c
@@ -85,7 +85,7 @@ int X509V3_add_value(const char *name, const char *value,
85 char *tname = NULL, *tvalue = NULL; 85 char *tname = NULL, *tvalue = NULL;
86 if(name && !(tname = BUF_strdup(name))) goto err; 86 if(name && !(tname = BUF_strdup(name))) goto err;
87 if(value && !(tvalue = BUF_strdup(value))) goto err; 87 if(value && !(tvalue = BUF_strdup(value))) goto err;
88 if(!(vtmp = (CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE)))) goto err; 88 if(!(vtmp = (CONF_VALUE *)malloc(sizeof(CONF_VALUE)))) goto err;
89 if(!*extlist && !(*extlist = sk_CONF_VALUE_new_null())) goto err; 89 if(!*extlist && !(*extlist = sk_CONF_VALUE_new_null())) goto err;
90 vtmp->section = NULL; 90 vtmp->section = NULL;
91 vtmp->name = tname; 91 vtmp->name = tname;
@@ -94,9 +94,9 @@ int X509V3_add_value(const char *name, const char *value,
94 return 1; 94 return 1;
95 err: 95 err:
96 X509V3err(X509V3_F_X509V3_ADD_VALUE,ERR_R_MALLOC_FAILURE); 96 X509V3err(X509V3_F_X509V3_ADD_VALUE,ERR_R_MALLOC_FAILURE);
97 if(vtmp) OPENSSL_free(vtmp); 97 if(vtmp) free(vtmp);
98 if(tname) OPENSSL_free(tname); 98 if(tname) free(tname);
99 if(tvalue) OPENSSL_free(tvalue); 99 if(tvalue) free(tvalue);
100 return 0; 100 return 0;
101} 101}
102 102
@@ -111,10 +111,10 @@ int X509V3_add_value_uchar(const char *name, const unsigned char *value,
111void X509V3_conf_free(CONF_VALUE *conf) 111void X509V3_conf_free(CONF_VALUE *conf)
112{ 112{
113 if(!conf) return; 113 if(!conf) return;
114 if(conf->name) OPENSSL_free(conf->name); 114 if(conf->name) free(conf->name);
115 if(conf->value) OPENSSL_free(conf->value); 115 if(conf->value) free(conf->value);
116 if(conf->section) OPENSSL_free(conf->section); 116 if(conf->section) free(conf->section);
117 OPENSSL_free(conf); 117 free(conf);
118} 118}
119 119
120int X509V3_add_value_bool(const char *name, int asn1_bool, 120int X509V3_add_value_bool(const char *name, int asn1_bool,
@@ -206,7 +206,7 @@ int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint,
206 if(!aint) return 1; 206 if(!aint) return 1;
207 if(!(strtmp = i2s_ASN1_INTEGER(NULL, aint))) return 0; 207 if(!(strtmp = i2s_ASN1_INTEGER(NULL, aint))) return 0;
208 ret = X509V3_add_value(name, strtmp, extlist); 208 ret = X509V3_add_value(name, strtmp, extlist);
209 OPENSSL_free(strtmp); 209 free(strtmp);
210 return ret; 210 return ret;
211} 211}
212 212
@@ -328,11 +328,11 @@ STACK_OF(CONF_VALUE) *X509V3_parse_list(const char *line)
328 } 328 }
329 X509V3_add_value(ntmp, NULL, &values); 329 X509V3_add_value(ntmp, NULL, &values);
330 } 330 }
331OPENSSL_free(linebuf); 331free(linebuf);
332return values; 332return values;
333 333
334err: 334err:
335OPENSSL_free(linebuf); 335free(linebuf);
336sk_CONF_VALUE_pop_free(values, X509V3_conf_free); 336sk_CONF_VALUE_pop_free(values, X509V3_conf_free);
337return NULL; 337return NULL;
338 338
@@ -355,7 +355,7 @@ static char *strip_spaces(char *name)
355 355
356/* hex string utilities */ 356/* hex string utilities */
357 357
358/* Given a buffer of length 'len' return a OPENSSL_malloc'ed string with its 358/* Given a buffer of length 'len' return a malloc'ed string with its
359 * hex representation 359 * hex representation
360 * @@@ (Contents of buffer are always kept in ASCII, also on EBCDIC machines) 360 * @@@ (Contents of buffer are always kept in ASCII, also on EBCDIC machines)
361 */ 361 */
@@ -367,7 +367,7 @@ char *hex_to_string(const unsigned char *buffer, long len)
367 int i; 367 int i;
368 const static char hexdig[] = "0123456789ABCDEF"; 368 const static char hexdig[] = "0123456789ABCDEF";
369 if(!buffer || !len) return NULL; 369 if(!buffer || !len) return NULL;
370 if(!(tmp = OPENSSL_malloc(len * 3 + 1))) { 370 if(!(tmp = malloc(len * 3 + 1))) {
371 X509V3err(X509V3_F_HEX_TO_STRING,ERR_R_MALLOC_FAILURE); 371 X509V3err(X509V3_F_HEX_TO_STRING,ERR_R_MALLOC_FAILURE);
372 return NULL; 372 return NULL;
373 } 373 }
@@ -393,14 +393,14 @@ unsigned char *string_to_hex(const char *str, long *len)
393 X509V3err(X509V3_F_STRING_TO_HEX,X509V3_R_INVALID_NULL_ARGUMENT); 393 X509V3err(X509V3_F_STRING_TO_HEX,X509V3_R_INVALID_NULL_ARGUMENT);
394 return NULL; 394 return NULL;
395 } 395 }
396 if(!(hexbuf = OPENSSL_malloc(strlen(str) >> 1))) goto err; 396 if(!(hexbuf = malloc(strlen(str) >> 1))) goto err;
397 for(p = (unsigned char *)str, q = hexbuf; *p;) { 397 for(p = (unsigned char *)str, q = hexbuf; *p;) {
398 ch = *p++; 398 ch = *p++;
399 if(ch == ':') continue; 399 if(ch == ':') continue;
400 cl = *p++; 400 cl = *p++;
401 if(!cl) { 401 if(!cl) {
402 X509V3err(X509V3_F_STRING_TO_HEX,X509V3_R_ODD_NUMBER_OF_DIGITS); 402 X509V3err(X509V3_F_STRING_TO_HEX,X509V3_R_ODD_NUMBER_OF_DIGITS);
403 OPENSSL_free(hexbuf); 403 free(hexbuf);
404 return NULL; 404 return NULL;
405 } 405 }
406 if(isupper(ch)) ch = tolower(ch); 406 if(isupper(ch)) ch = tolower(ch);
@@ -422,12 +422,12 @@ unsigned char *string_to_hex(const char *str, long *len)
422 return hexbuf; 422 return hexbuf;
423 423
424 err: 424 err:
425 if(hexbuf) OPENSSL_free(hexbuf); 425 if(hexbuf) free(hexbuf);
426 X509V3err(X509V3_F_STRING_TO_HEX,ERR_R_MALLOC_FAILURE); 426 X509V3err(X509V3_F_STRING_TO_HEX,ERR_R_MALLOC_FAILURE);
427 return NULL; 427 return NULL;
428 428
429 badhex: 429 badhex:
430 OPENSSL_free(hexbuf); 430 free(hexbuf);
431 X509V3err(X509V3_F_STRING_TO_HEX,X509V3_R_ILLEGAL_HEX_DIGIT); 431 X509V3err(X509V3_F_STRING_TO_HEX,X509V3_R_ILLEGAL_HEX_DIGIT);
432 return NULL; 432 return NULL;
433 433
@@ -531,7 +531,7 @@ static STACK_OF(OPENSSL_STRING) *get_email(X509_NAME *name, GENERAL_NAMES *gens)
531 531
532static void str_free(OPENSSL_STRING str) 532static void str_free(OPENSSL_STRING str)
533{ 533{
534 OPENSSL_free(str); 534 free(str);
535} 535}
536 536
537static int append_ia5(STACK_OF(OPENSSL_STRING) **sk, ASN1_IA5STRING *email) 537static int append_ia5(STACK_OF(OPENSSL_STRING) **sk, ASN1_IA5STRING *email)
@@ -608,7 +608,7 @@ ASN1_OCTET_STRING *a2i_IPADDRESS_NC(const char *ipasc)
608 608
609 iplen2 = a2i_ipadd(ipout + iplen1, p); 609 iplen2 = a2i_ipadd(ipout + iplen1, p);
610 610
611 OPENSSL_free(iptmp); 611 free(iptmp);
612 iptmp = NULL; 612 iptmp = NULL;
613 613
614 if (!iplen2 || (iplen1 != iplen2)) 614 if (!iplen2 || (iplen1 != iplen2))
@@ -624,7 +624,7 @@ ASN1_OCTET_STRING *a2i_IPADDRESS_NC(const char *ipasc)
624 624
625 err: 625 err:
626 if (iptmp) 626 if (iptmp)
627 OPENSSL_free(iptmp); 627 free(iptmp);
628 if (ret) 628 if (ret)
629 ASN1_OCTET_STRING_free(ret); 629 ASN1_OCTET_STRING_free(ret);
630 return NULL; 630 return NULL;