Browse Source

free null cleanup finale

Don't check for NULL before calling OPENSSL_free

Reviewed-by: Richard Levitte <levitte@openssl.org>
master
Rich Salz 7 years ago
parent
commit
b548a1f11c
173 changed files with 509 additions and 1012 deletions
  1. +2
    -6
      apps/apps.c
  2. +3
    -5
      apps/asn1pars.c
  3. +4
    -8
      apps/ca.c
  4. +4
    -8
      apps/cms.c
  5. +1
    -2
      apps/dgst.c
  6. +2
    -4
      apps/dsa.c
  7. +2
    -4
      apps/ec.c
  8. +1
    -2
      apps/ecparam.c
  9. +3
    -6
      apps/enc.c
  10. +4
    -8
      apps/engine.c
  11. +1
    -2
      apps/gendsa.c
  12. +1
    -2
      apps/genpkey.c
  13. +1
    -2
      apps/genrsa.c
  14. +6
    -13
      apps/ocsp.c
  15. +3
    -6
      apps/openssl.c
  16. +2
    -4
      apps/passwd.c
  17. +2
    -4
      apps/pkcs12.c
  18. +2
    -4
      apps/pkcs8.c
  19. +2
    -4
      apps/pkey.c
  20. +4
    -10
      apps/pkeyutl.c
  21. +3
    -6
      apps/req.c
  22. +2
    -4
      apps/rsa.c
  23. +3
    -6
      apps/rsautl.c
  24. +2
    -8
      apps/s_client.c
  25. +2
    -8
      apps/s_server.c
  26. +1
    -2
      apps/s_socket.c
  27. +1
    -2
      apps/smime.c
  28. +2
    -4
      apps/speed.c
  29. +1
    -2
      apps/spkac.c
  30. +12
    -25
      apps/srp.c
  31. +2
    -4
      apps/x509.c
  32. +1
    -2
      crypto/asn1/a_bitstr.c
  33. +1
    -2
      crypto/asn1/a_enum.c
  34. +1
    -2
      crypto/asn1/a_gentm.c
  35. +3
    -6
      crypto/asn1/a_int.c
  36. +3
    -5
      crypto/asn1/a_mbstr.c
  37. +4
    -8
      crypto/asn1/a_object.c
  38. +2
    -4
      crypto/asn1/a_sign.c
  39. +1
    -2
      crypto/asn1/a_utctm.c
  40. +2
    -4
      crypto/asn1/ameth_lib.c
  41. +3
    -6
      crypto/asn1/asn1_gen.c
  42. +2
    -3
      crypto/asn1/asn1_lib.c
  43. +10
    -20
      crypto/asn1/asn_mime.c
  44. +2
    -4
      crypto/asn1/asn_pack.c
  45. +1
    -2
      crypto/asn1/bio_asn1.c
  46. +2
    -4
      crypto/asn1/bio_ndef.c
  47. +1
    -2
      crypto/asn1/f_enum.c
  48. +1
    -2
      crypto/asn1/f_int.c
  49. +1
    -2
      crypto/asn1/f_string.c
  50. +2
    -4
      crypto/asn1/t_x509.c
  51. +2
    -3
      crypto/asn1/tasn_dec.c
  52. +1
    -2
      crypto/asn1/tasn_prn.c
  53. +1
    -2
      crypto/asn1/tasn_scn.c
  54. +2
    -4
      crypto/asn1/tasn_utl.c
  55. +1
    -2
      crypto/asn1/x_info.c
  56. +1
    -1
      crypto/asn1/x_pkey.c
  57. +1
    -2
      crypto/asn1/x_pubkey.c
  58. +2
    -5
      crypto/asn1/x_x509.c
  59. +1
    -2
      crypto/bio/b_sock.c
  60. +3
    -6
      crypto/bio/bf_buff.c
  61. +1
    -2
      crypto/bio/bf_lbuf.c
  62. +1
    -2
      crypto/bio/bf_nbio.c
  63. +3
    -6
      crypto/bio/bss_acpt.c
  64. +3
    -8
      crypto/bio/bss_bio.c
  65. +7
    -14
      crypto/bio/bss_conn.c
  66. +3
    -6
      crypto/bio/bss_dgram.c
  67. +1
    -2
      crypto/bn/bn_exp.c
  68. +5
    -10
      crypto/bn/bn_gf2m.c
  69. +4
    -10
      crypto/bn/bn_intern.c
  70. +2
    -3
      crypto/bn/bn_lib.c
  71. +5
    -8
      crypto/bn/bn_print.c
  72. +1
    -2
      crypto/bn/bn_rand.c
  73. +4
    -5
      crypto/cms/cms_env.c
  74. +1
    -2
      crypto/cms/cms_ess.c
  75. +2
    -3
      crypto/cms/cms_kari.c
  76. +1
    -1
      crypto/cms/cms_pwri.c
  77. +1
    -2
      crypto/cms/cms_sd.c
  78. +5
    -10
      crypto/comp/c_zlib.c
  79. +1
    -2
      crypto/conf/conf_api.c
  80. +6
    -12
      crypto/conf/conf_def.c
  81. +2
    -4
      crypto/conf/conf_mod.c
  82. +6
    -11
      crypto/dh/dh_ameth.c
  83. +1
    -2
      crypto/dh/dh_kdf.c
  84. +1
    -2
      crypto/dh/dh_lib.c
  85. +2
    -4
      crypto/dh/dh_pmeth.c
  86. +4
    -8
      crypto/dsa/dsa_ameth.c
  87. +1
    -2
      crypto/dsa/dsa_gen.c
  88. +1
    -2
      crypto/dsa/dsa_pmeth.c
  89. +1
    -2
      crypto/dso/dso_dl.c
  90. +1
    -2
      crypto/dso/dso_dlfcn.c
  91. +3
    -7
      crypto/dso/dso_lib.c
  92. +2
    -4
      crypto/dso/dso_vms.c
  93. +2
    -4
      crypto/dso/dso_win32.c
  94. +2
    -4
      crypto/ec/ec_ameth.c
  95. +5
    -10
      crypto/ec/ec_asn1.c
  96. +5
    -9
      crypto/ec/ec_lib.c
  97. +3
    -7
      crypto/ec/ec_mult.c
  98. +2
    -4
      crypto/ec/ec_pmeth.c
  99. +1
    -2
      crypto/ec/eck_prn.c
  100. +3
    -6
      crypto/ec/ecp_nistp224.c

+ 2
- 6
apps/apps.c View File

@ -2165,9 +2165,7 @@ void jpake_client_auth(BIO *out, BIO *conn, const char *secret)
BIO_puts(out, "JPAKE authentication succeeded, setting PSK\n");
if (psk_key)
OPENSSL_free(psk_key);
OPENSSL_free(psk_key);
psk_key = BN_bn2hex(JPAKE_get_shared_key(ctx));
BIO_pop(bconn);
@ -2197,9 +2195,7 @@ void jpake_server_auth(BIO *out, BIO *conn, const char *secret)
BIO_puts(out, "JPAKE authentication succeeded, setting PSK\n");
if (psk_key)
OPENSSL_free(psk_key);
OPENSSL_free(psk_key);
psk_key = BN_bn2hex(JPAKE_get_shared_key(ctx));
BIO_pop(bconn);


+ 3
- 5
apps/asn1pars.c View File

@ -321,11 +321,9 @@ int asn1parse_main(int argc, char **argv)
ERR_print_errors(bio_err);
if (buf != NULL)
BUF_MEM_free(buf);
if (name != NULL)
OPENSSL_free(name);
if (header != NULL)
OPENSSL_free(header);
if (strictpem && str != NULL)
OPENSSL_free(name);
OPENSSL_free(header);
if (strictpem)
OPENSSL_free(str);
ASN1_TYPE_free(at);
if (osk != NULL)


+ 4
- 8
apps/ca.c View File

@ -2271,8 +2271,7 @@ static int do_revoke(X509 *x509, CA_DB *db, int type, char *value)
ok = 1;
end:
for (i = 0; i < DB_NUMBER; i++) {
if (row[i] != NULL)
OPENSSL_free(row[i]);
OPENSSL_free(row[i]);
}
return (ok);
}
@ -2339,8 +2338,7 @@ static int get_certificate_status(const char *serial, CA_DB *db)
}
end:
for (i = 0; i < DB_NUMBER; i++) {
if (row[i] != NULL)
OPENSSL_free(row[i]);
OPENSSL_free(row[i]);
}
return (ok);
}
@ -2564,8 +2562,7 @@ int make_revoked(X509_REVOKED *rev, const char *str)
end:
if (tmp)
OPENSSL_free(tmp);
OPENSSL_free(tmp);
ASN1_OBJECT_free(hold);
ASN1_GENERALIZEDTIME_free(comp_time);
ASN1_ENUMERATED_free(rtmp);
@ -2719,8 +2716,7 @@ int unpack_revinfo(ASN1_TIME **prevtm, int *preason, ASN1_OBJECT **phold,
end:
if (tmp)
OPENSSL_free(tmp);
OPENSSL_free(tmp);
ASN1_GENERALIZEDTIME_free(comp_time);
return ret;


+ 4
- 8
apps/cms.c View File

@ -1121,12 +1121,9 @@ int cms_main(int argc, char **argv)
sk_OPENSSL_STRING_free(sksigners);
if (skkeys)
sk_OPENSSL_STRING_free(skkeys);
if (secret_key)
OPENSSL_free(secret_key);
if (secret_keyid)
OPENSSL_free(secret_keyid);
if (pwri_tmp)
OPENSSL_free(pwri_tmp);
OPENSSL_free(secret_key);
OPENSSL_free(secret_keyid);
OPENSSL_free(pwri_tmp);
ASN1_OBJECT_free(econtent_type);
if (rr)
CMS_ReceiptRequest_free(rr);
@ -1152,8 +1149,7 @@ int cms_main(int argc, char **argv)
BIO_free(in);
BIO_free(indata);
BIO_free_all(out);
if (passin)
OPENSSL_free(passin);
OPENSSL_free(passin);
return (ret);
}


+ 1
- 2
apps/dgst.c View File

@ -451,8 +451,7 @@ int dgst_main(int argc, char **argv)
sk_OPENSSL_STRING_free(sigopts);
if (macopts)
sk_OPENSSL_STRING_free(macopts);
if (sigbuf)
OPENSSL_free(sigbuf);
OPENSSL_free(sigbuf);
BIO_free(bmd);
return (ret);
}


+ 2
- 4
apps/dsa.c View File

@ -275,10 +275,8 @@ int dsa_main(int argc, char **argv)
end:
BIO_free_all(out);
DSA_free(dsa);
if (passin)
OPENSSL_free(passin);
if (passout)
OPENSSL_free(passout);
OPENSSL_free(passin);
OPENSSL_free(passout);
return (ret);
}
#else /* !OPENSSL_NO_DSA */


+ 2
- 4
apps/ec.c View File

@ -271,10 +271,8 @@ int ec_main(int argc, char **argv)
BIO_free(in);
BIO_free_all(out);
EC_KEY_free(eckey);
if (passin)
OPENSSL_free(passin);
if (passout)
OPENSSL_free(passout);
OPENSSL_free(passin);
OPENSSL_free(passout);
return (ret);
}
#else /* !OPENSSL_NO_EC */


+ 1
- 2
apps/ecparam.c View File

@ -489,8 +489,7 @@ int ecparam_main(int argc, char **argv)
BN_free(ec_gen);
BN_free(ec_order);
BN_free(ec_cofactor);
if (buffer)
OPENSSL_free(buffer);
OPENSSL_free(buffer);
BIO_free(in);
BIO_free_all(out);
EC_GROUP_free(group);


+ 3
- 6
apps/enc.c View File

@ -564,10 +564,8 @@ int enc_main(int argc, char **argv)
}
end:
ERR_print_errors(bio_err);
if (strbuf != NULL)
OPENSSL_free(strbuf);
if (buff != NULL)
OPENSSL_free(buff);
OPENSSL_free(strbuf);
OPENSSL_free(buff);
BIO_free(in);
BIO_free_all(out);
BIO_free(benc);
@ -575,8 +573,7 @@ int enc_main(int argc, char **argv)
#ifdef ZLIB
BIO_free(bzl);
#endif
if (pass)
OPENSSL_free(pass);
OPENSSL_free(pass);
return (ret);
}


+ 4
- 8
apps/engine.c View File

@ -252,10 +252,8 @@ static int util_verbose(ENGINE *e, int verbose, BIO *out, const char *indent)
}
OPENSSL_free(name);
name = NULL;
if (desc) {
OPENSSL_free(desc);
desc = NULL;
}
OPENSSL_free(desc);
desc = NULL;
/* Move to the next command */
num = ENGINE_ctrl(e, ENGINE_CTRL_GET_NEXT_CMD_TYPE, num, NULL, NULL);
} while (num > 0);
@ -265,10 +263,8 @@ static int util_verbose(ENGINE *e, int verbose, BIO *out, const char *indent)
err:
if (cmds)
sk_OPENSSL_STRING_pop_free(cmds, identity);
if (name)
OPENSSL_free(name);
if (desc)
OPENSSL_free(desc);
OPENSSL_free(name);
OPENSSL_free(desc);
return ret;
}


+ 1
- 2
apps/gendsa.c View File

@ -182,8 +182,7 @@ int gendsa_main(int argc, char **argv)
BIO_free(in);
BIO_free_all(out);
DSA_free(dsa);
if (passout)
OPENSSL_free(passout);
OPENSSL_free(passout);
return (ret);
}
#else /* !OPENSSL_NO_DSA */


+ 1
- 2
apps/genpkey.c View File

@ -235,8 +235,7 @@ int genpkey_main(int argc, char **argv)
EVP_PKEY_CTX_free(ctx);
BIO_free_all(out);
BIO_free(in);
if (pass)
OPENSSL_free(pass);
OPENSSL_free(pass);
return ret;
}


+ 1
- 2
apps/genrsa.c View File

@ -218,8 +218,7 @@ int genrsa_main(int argc, char **argv)
BN_GENCB_free(cb);
RSA_free(rsa);
BIO_free_all(out);
if (passout)
OPENSSL_free(passout);
OPENSSL_free(passout);
if (ret != 0)
ERR_print_errors(bio_err);
return (ret);


+ 6
- 13
apps/ocsp.c View File

@ -271,12 +271,9 @@ int ocsp_main(int argc, char **argv)
req_timeout = atoi(opt_arg());
break;
case OPT_URL:
if (thost)
OPENSSL_free(thost);
if (tport)
OPENSSL_free(tport);
if (tpath)
OPENSSL_free(tpath);
OPENSSL_free(thost);
OPENSSL_free(tport);
OPENSSL_free(tpath);
if (!OCSP_parse_url(opt_arg(), &host, &port, &path, &use_ssl)) {
BIO_printf(bio_err, "%s Error parsing URL\n", prog);
goto end;
@ -753,13 +750,9 @@ int ocsp_main(int argc, char **argv)
sk_X509_pop_free(sign_other, X509_free);
sk_X509_pop_free(verify_other, X509_free);
sk_CONF_VALUE_pop_free(headers, X509V3_conf_free);
if (thost)
OPENSSL_free(thost);
if (tport)
OPENSSL_free(tport);
if (tpath)
OPENSSL_free(tpath);
OPENSSL_free(thost);
OPENSSL_free(tport);
OPENSSL_free(tpath);
return (ret);
}


+ 3
- 6
apps/openssl.c View File

@ -509,18 +509,15 @@ int main(int argc, char *argv[])
}
ret = 1;
end:
if (copied_argv)
OPENSSL_free(copied_argv);
if (to_free)
OPENSSL_free(to_free);
OPENSSL_free(copied_argv);
OPENSSL_free(to_free);
if (config != NULL) {
NCONF_free(config);
config = NULL;
}
if (prog != NULL)
lh_FUNCTION_free(prog);
if (arg.argv != NULL)
OPENSSL_free(arg.argv);
OPENSSL_free(arg.argv);
BIO_free(bio_in);
BIO_free_all(bio_out);


+ 2
- 4
apps/passwd.c View File

@ -284,10 +284,8 @@ int passwd_main(int argc, char **argv)
end:
ERR_print_errors(bio_err);
if (salt_malloc)
OPENSSL_free(salt_malloc);
if (passwd_malloc)
OPENSSL_free(passwd_malloc);
OPENSSL_free(salt_malloc);
OPENSSL_free(passwd_malloc);
BIO_free(in);
return (ret);
}


+ 2
- 4
apps/pkcs12.c View File

@ -556,10 +556,8 @@ int pkcs12_main(int argc, char **argv)
BIO_free_all(out);
if (canames)
sk_OPENSSL_STRING_free(canames);
if (passin)
OPENSSL_free(passin);
if (passout)
OPENSSL_free(passout);
OPENSSL_free(passin);
OPENSSL_free(passout);
return (ret);
}


+ 2
- 4
apps/pkcs8.c View File

@ -343,10 +343,8 @@ int pkcs8_main(int argc, char **argv)
EVP_PKEY_free(pkey);
BIO_free_all(out);
BIO_free(in);
if (passin)
OPENSSL_free(passin);
if (passout)
OPENSSL_free(passout);
OPENSSL_free(passin);
OPENSSL_free(passout);
return ret;
}

+ 2
- 4
apps/pkey.c View File

@ -208,10 +208,8 @@ int pkey_main(int argc, char **argv)
EVP_PKEY_free(pkey);
BIO_free_all(out);
BIO_free(in);
if (passin)
OPENSSL_free(passin);
if (passout)
OPENSSL_free(passout);
OPENSSL_free(passin);
OPENSSL_free(passout);
return ret;
}

+ 4
- 10
apps/pkeyutl.c View File

@ -322,12 +322,9 @@ int pkeyutl_main(int argc, char **argv)
EVP_PKEY_CTX_free(ctx);
BIO_free(in);
BIO_free_all(out);
if (buf_in)
OPENSSL_free(buf_in);
if (buf_out)
OPENSSL_free(buf_out);
if (sig)
OPENSSL_free(sig);
OPENSSL_free(buf_in);
OPENSSL_free(buf_out);
OPENSSL_free(sig);
return ret;
}
@ -413,10 +410,7 @@ static EVP_PKEY_CTX *init_ctx(int *pkeysize,
}
end:
if (passin)
OPENSSL_free(passin);
OPENSSL_free(passin);
return ctx;
}


+ 3
- 6
apps/req.c View File

@ -886,15 +886,12 @@ int req_main(int argc, char **argv)
if (gen_eng)
ENGINE_free(gen_eng);
#endif
if (keyalgstr)
OPENSSL_free(keyalgstr);
OPENSSL_free(keyalgstr);
X509_REQ_free(req);
X509_free(x509ss);
ASN1_INTEGER_free(serial);
if (passargin && passin)
OPENSSL_free(passin);
if (passargout && passout)
OPENSSL_free(passout);
OPENSSL_free(passin);
OPENSSL_free(passout);
OBJ_cleanup();
return (ret);
}


+ 2
- 4
apps/rsa.c View File

@ -388,10 +388,8 @@ int rsa_main(int argc, char **argv)
end:
BIO_free_all(out);
RSA_free(rsa);
if (passin)
OPENSSL_free(passin);
if (passout)
OPENSSL_free(passout);
OPENSSL_free(passin);
OPENSSL_free(passout);
return (ret);
}
#else /* !OPENSSL_NO_RSA */


+ 3
- 6
apps/rsautl.c View File

@ -315,12 +315,9 @@ int rsautl_main(int argc, char **argv)
RSA_free(rsa);
BIO_free(in);
BIO_free_all(out);
if (rsa_in)
OPENSSL_free(rsa_in);
if (rsa_out)
OPENSSL_free(rsa_out);
if (passin)
OPENSSL_free(passin);
OPENSSL_free(rsa_in);
OPENSSL_free(rsa_out);
OPENSSL_free(passin);
return ret;
}


+ 2
- 8
apps/s_client.c View File

@ -1985,24 +1985,18 @@ int s_client_main(int argc, char **argv)
SSL_free(con);
}
#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
if (next_proto.data)
OPENSSL_free(next_proto.data);
OPENSSL_free(next_proto.data);
#endif
SSL_CTX_free(ctx);
X509_free(cert);
sk_X509_CRL_pop_free(crls, X509_CRL_free);
EVP_PKEY_free(key);
sk_X509_pop_free(chain, X509_free);
if (pass)
OPENSSL_free(pass);
OPENSSL_free(pass);
X509_VERIFY_PARAM_free(vpm);
ssl_excert_free(exc);
sk_OPENSSL_STRING_free(ssl_args);
SSL_CONF_CTX_free(cctx);
#ifndef OPENSSL_NO_JPAKE
if (jpake_secret && psk_key)
OPENSSL_free(psk_key);
#endif
OPENSSL_clear_free(cbuf, BUFSIZZ);
OPENSSL_clear_free(sbuf, BUFSIZZ);
OPENSSL_clear_free(mbuf, BUFSIZZ);


+ 2
- 8
apps/s_server.c View File

@ -1956,10 +1956,6 @@ int s_server_main(int argc, char *argv[])
ssl_excert_free(exc);
sk_OPENSSL_STRING_free(ssl_args);
SSL_CONF_CTX_free(cctx);
#ifndef OPENSSL_NO_JPAKE
if (jpake_secret && psk_key)
OPENSSL_free(psk_key);
#endif
BIO_free(bio_s_out);
bio_s_out = NULL;
BIO_free(bio_s_msg);
@ -2931,8 +2927,7 @@ static int www_body(char *hostname, int s, int stype, unsigned char *context)
err:
if (ret >= 0)
BIO_printf(bio_s_out, "ACCEPT\n");
if (buf != NULL)
OPENSSL_free(buf);
OPENSSL_free(buf);
BIO_free_all(io);
return (ret);
}
@ -3065,8 +3060,7 @@ static int rev_body(char *hostname, int s, int stype, unsigned char *context)
err:
if (buf != NULL)
OPENSSL_free(buf);
OPENSSL_free(buf);
BIO_free_all(io);
return (ret);
}


+ 1
- 2
apps/s_socket.c View File

@ -354,8 +354,7 @@ int do_server(int port, int type, int *ret,
} else
sock = accept_socket;
i = (*cb) (name, sock, type, context);
if (name != NULL)
OPENSSL_free(name);
OPENSSL_free(name);
if (type == SOCK_STREAM)
SHUTDOWN2(sock);
if (naccept != -1)


+ 1
- 2
apps/smime.c View File

@ -664,8 +664,7 @@ int smime_main(int argc, char **argv)
BIO_free(in);
BIO_free(indata);
BIO_free_all(out);
if (passin)
OPENSSL_free(passin);
OPENSSL_free(passin);
return (ret);
}


+ 2
- 4
apps/speed.c View File

@ -2529,8 +2529,6 @@ static void multiblock_speed(const EVP_CIPHER *evp_cipher)
fprintf(stdout, "\n");
}
if (inp)
OPENSSL_free(inp);
if (out)
OPENSSL_free(out);
OPENSSL_free(inp);
OPENSSL_free(out);
}

+ 1
- 2
apps/spkac.c View File

@ -240,7 +240,6 @@ int spkac_main(int argc, char **argv)
BIO_free(in);
BIO_free_all(out);
EVP_PKEY_free(pkey);
if (passin)
OPENSSL_free(passin);
OPENSSL_free(passin);
return (ret);
}

+ 12
- 25
apps/srp.c View File

@ -384,10 +384,8 @@ int srp_main(int argc, char **argv)
errorline, configfile);
goto end;
}
if (tofree) {
OPENSSL_free(tofree);
tofree = NULL;
}
OPENSSL_free(tofree);
tofree = NULL;
/* Lets get the config section we are using */
if (section == NULL) {
@ -519,26 +517,16 @@ int srp_main(int argc, char **argv)
row[DB_srpgN] = BUF_strdup(gNid);
if (!row[DB_srpid] || !row[DB_srpgN] || !row[DB_srptype]
|| !row[DB_srpverifier] || !row[DB_srpsalt] || (userinfo
&&
(!(row
[DB_srpinfo]
=
BUF_strdup
(userinfo))))
|| !row[DB_srpverifier] || !row[DB_srpsalt]
|| (userinfo &&
(!(row [DB_srpinfo] = BUF_strdup (userinfo))))
|| !update_index(db, row)) {
if (row[DB_srpid])
OPENSSL_free(row[DB_srpid]);
if (row[DB_srpgN])
OPENSSL_free(row[DB_srpgN]);
if (row[DB_srpinfo])
OPENSSL_free(row[DB_srpinfo]);
if (row[DB_srptype])
OPENSSL_free(row[DB_srptype]);
if (row[DB_srpverifier])
OPENSSL_free(row[DB_srpverifier]);
if (row[DB_srpsalt])
OPENSSL_free(row[DB_srpsalt]);
OPENSSL_free(row[DB_srpid]);
OPENSSL_free(row[DB_srpgN]);
OPENSSL_free(row[DB_srpinfo]);
OPENSSL_free(row[DB_srptype]);
OPENSSL_free(row[DB_srpverifier]);
OPENSSL_free(row[DB_srpsalt]);
goto end;
}
doupdatedb = 1;
@ -676,8 +664,7 @@ int srp_main(int argc, char **argv)
if (verbose)
BIO_printf(bio_err, "SRP terminating with code %d.\n", ret);
if (tofree)
OPENSSL_free(tofree);
OPENSSL_free(tofree);
if (ret)
ERR_print_errors(bio_err);
if (randfile)


+ 2
- 4
apps/x509.c View File

@ -955,8 +955,7 @@ int x509_main(int argc, char **argv)
ASN1_INTEGER_free(sno);
sk_ASN1_OBJECT_pop_free(trust, ASN1_OBJECT_free);
sk_ASN1_OBJECT_pop_free(reject, ASN1_OBJECT_free);
if (passin)
OPENSSL_free(passin);
OPENSSL_free(passin);
return (ret);
}
@ -996,8 +995,7 @@ static ASN1_INTEGER *x509_load_serial(char *CAfile, char *serialfile,
goto end;
end:
if (buf)
OPENSSL_free(buf);
OPENSSL_free(buf);
BN_free(serial);
return bs;
}


+ 1
- 2
crypto/asn1/a_bitstr.c View File

@ -168,8 +168,7 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
s = NULL;
ret->length = (int)len;
if (ret->data != NULL)
OPENSSL_free(ret->data);
OPENSSL_free(ret->data);
ret->data = s;
ret->type = V_ASN1_BIT_STRING;
if (a != NULL)


+ 1
- 2
crypto/asn1/a_enum.c View File

@ -75,8 +75,7 @@ int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
a->type = V_ASN1_ENUMERATED;
if (a->length < (int)(sizeof(long) + 1)) {
if (a->data != NULL)
OPENSSL_free(a->data);
OPENSSL_free(a->data);
if ((a->data = OPENSSL_malloc(sizeof(long) + 1)) != NULL)
memset((char *)a->data, 0, sizeof(long) + 1);
}


+ 1
- 2
crypto/asn1/a_gentm.c View File

@ -243,8 +243,7 @@ ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ, ERR_R_MALLOC_FAILURE);
return (NULL);
}
if (s->data != NULL)
OPENSSL_free(s->data);
OPENSSL_free(s->data);
s->data = (unsigned char *)p;
}


+ 3
- 6
crypto/asn1/a_int.c View File

@ -258,8 +258,7 @@ ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp,
memcpy(s, p, (int)len);
}
if (ret->data != NULL)
OPENSSL_free(ret->data);
OPENSSL_free(ret->data);
ret->data = s;
ret->length = (int)len;
if (a != NULL)
@ -327,8 +326,7 @@ ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp,
p += len;
}
if (ret->data != NULL)
OPENSSL_free(ret->data);
OPENSSL_free(ret->data);
ret->data = s;
ret->length = (int)len;
if (a != NULL)
@ -349,8 +347,7 @@ int ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
unsigned char buf[sizeof(long) + 1];
if (a->length < (int)(sizeof(long) + 1)) {
if (a->data != NULL)
OPENSSL_free(a->data);
OPENSSL_free(a->data);
if ((a->data = OPENSSL_malloc(sizeof(long) + 1)) != NULL)
memset((char *)a->data, 0, sizeof(long) + 1);
}


+ 3
- 5
crypto/asn1/a_mbstr.c View File

@ -190,11 +190,9 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
if (*out) {
free_out = 0;
dest = *out;
if (dest->data) {
dest->length = 0;
OPENSSL_free(dest->data);
dest->data = NULL;
}
OPENSSL_free(dest->data);
dest->data = NULL;
dest->length = 0;
dest->type = str_type;
} else {
free_out = 1;


+ 4
- 8
crypto/asn1/a_object.c View File

@ -313,8 +313,7 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
/* once detached we can change it */
if ((data == NULL) || (ret->length < length)) {
ret->length = 0;
if (data != NULL)
OPENSSL_free(data);
OPENSSL_free(data);
data = OPENSSL_malloc(length);
if (data == NULL) {
i = ERR_R_MALLOC_FAILURE;
@ -368,16 +367,13 @@ void ASN1_OBJECT_free(ASN1_OBJECT *a)
#ifndef CONST_STRICT /* disable purely for compile-time strict
* const checking. Doing this on a "real"
* compile will cause memory leaks */
if (a->sn != NULL)
OPENSSL_free((void *)a->sn);
if (a->ln != NULL)
OPENSSL_free((void *)a->ln);
OPENSSL_free((void*)a->sn);
OPENSSL_free((void*)a->ln);
#endif
a->sn = a->ln = NULL;
}
if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) {
if (a->data != NULL)
OPENSSL_free((void *)a->data);
OPENSSL_free((void*)a->data);
a->data = NULL;
a->length = 0;
}


+ 2
- 4
crypto/asn1/a_sign.c View File

@ -190,8 +190,7 @@ int ASN1_sign(i2d_of_void *i2d, X509_ALGOR *algor1, X509_ALGOR *algor2,
ASN1err(ASN1_F_ASN1_SIGN, ERR_R_EVP_LIB);
goto err;
}
if (signature->data != NULL)
OPENSSL_free(signature->data);
OPENSSL_free(signature->data);
signature->data = buf_out;
buf_out = NULL;
signature->length = outl;
@ -300,8 +299,7 @@ int ASN1_item_sign_ctx(const ASN1_ITEM *it,
ASN1err(ASN1_F_ASN1_ITEM_SIGN_CTX, ERR_R_EVP_LIB);
goto err;
}
if (signature->data != NULL)
OPENSSL_free(signature->data);
OPENSSL_free(signature->data);
signature->data = buf_out;
buf_out = NULL;
signature->length = outl;


+ 1
- 2
crypto/asn1/a_utctm.c View File

@ -218,8 +218,7 @@ ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t,
ASN1err(ASN1_F_ASN1_UTCTIME_ADJ, ERR_R_MALLOC_FAILURE);
goto err;
}
if (s->data != NULL)
OPENSSL_free(s->data);
OPENSSL_free(s->data);
s->data = (unsigned char *)p;
}


+ 2
- 4
crypto/asn1/ameth_lib.c View File

@ -384,10 +384,8 @@ void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst,
void EVP_PKEY_asn1_free(EVP_PKEY_ASN1_METHOD *ameth)
{
if (ameth && (ameth->pkey_flags & ASN1_PKEY_DYNAMIC)) {
if (ameth->pem_str)
OPENSSL_free(ameth->pem_str);
if (ameth->info)
OPENSSL_free(ameth->info);
OPENSSL_free(ameth->pem_str);
OPENSSL_free(ameth->info);
OPENSSL_free(ameth);
}
}


+ 3
- 6
crypto/asn1/asn1_gen.c View File

@ -280,10 +280,8 @@ static ASN1_TYPE *generate_v3(char *str, X509V3_CTX *cnf, int depth,
ret = d2i_ASN1_TYPE(NULL, &cp, len);
err:
if (orig_der)
OPENSSL_free(orig_der);
if (new_der)
OPENSSL_free(new_der);
OPENSSL_free(orig_der);
OPENSSL_free(new_der);
return ret;
@ -510,8 +508,7 @@ static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf,
bad:
if (der)
OPENSSL_free(der);
OPENSSL_free(der);
sk_ASN1_TYPE_pop_free(sk, ASN1_TYPE_free);
if (sect)


+ 2
- 3
crypto/asn1/asn1_lib.c View File

@ -335,8 +335,7 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len)
{
if (str->data)
OPENSSL_free(str->data);
OPENSSL_free(str->data);
str->data = data;
str->length = len;
}
@ -366,7 +365,7 @@ void ASN1_STRING_free(ASN1_STRING *a)
{
if (a == NULL)
return;
if (a->data && !(a->flags & ASN1_STRING_FLAG_NDEF))
if (!(a->flags & ASN1_STRING_FLAG_NDEF))
OPENSSL_free(a->data);
OPENSSL_free(a);
}


+ 10
- 20
crypto/asn1/asn_mime.c View File

@ -854,12 +854,9 @@ static MIME_HEADER *mime_hdr_new(char *name, char *value)
return mhdr;
err:
if (tmpname != NULL)
OPENSSL_free(tmpname);
if (tmpval != NULL)
OPENSSL_free(tmpval);
if (mhdr != NULL)
OPENSSL_free(mhdr);
OPENSSL_free(tmpname);
OPENSSL_free(tmpval);
OPENSSL_free(mhdr);
return NULL;
}
@ -895,12 +892,9 @@ static int mime_hdr_addparam(MIME_HEADER *mhdr, char *name, char *value)
goto err;
return 1;
err:
if (tmpname != NULL)
OPENSSL_free(tmpname);
if (tmpval != NULL)
OPENSSL_free(tmpval);
if (mparam != NULL)
OPENSSL_free(mparam);
OPENSSL_free(tmpname);
OPENSSL_free(tmpval);
OPENSSL_free(mparam);
return 0;
}
@ -947,10 +941,8 @@ static MIME_PARAM *mime_param_find(MIME_HEADER *hdr, char *name)
static void mime_hdr_free(MIME_HEADER *hdr)
{
if (hdr->name)
OPENSSL_free(hdr->name);
if (hdr->value)
OPENSSL_free(hdr->value);
OPENSSL_free(hdr->name);
OPENSSL_free(hdr->value);
if (hdr->params)
sk_MIME_PARAM_pop_free(hdr->params, mime_param_free);
OPENSSL_free(hdr);
@ -958,10 +950,8 @@ static void mime_hdr_free(MIME_HEADER *hdr)
static void mime_param_free(MIME_PARAM *param)
{
if (param->param_name)
OPENSSL_free(param->param_name);
if (param->param_value)
OPENSSL_free(param->param_value);
OPENSSL_free(param->param_name);
OPENSSL_free(param->param_value);
OPENSSL_free(param);
}


+ 2
- 4
crypto/asn1/asn_pack.c View File

@ -77,10 +77,8 @@ ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
} else
octmp = *oct;
if (octmp->data) {
OPENSSL_free(octmp->data);
octmp->data = NULL;
}
OPENSSL_free(octmp->data);
octmp->data = NULL;
if (!(octmp->length = ASN1_item_i2d(obj, &octmp->data, it))) {
ASN1err(ASN1_F_ASN1_ITEM_PACK, ASN1_R_ENCODE_ERROR);


+ 1
- 2
crypto/asn1/bio_asn1.c View File

@ -183,8 +183,7 @@ static int asn1_bio_free(BIO *b)
if (ctx == NULL)
return 0;
if (ctx->buf)
OPENSSL_free(ctx->buf);
OPENSSL_free(ctx->buf);
OPENSSL_free(ctx);
b->init = 0;
b->ptr = NULL;


+ 2
- 4
crypto/asn1/bio_ndef.c View File

@ -143,8 +143,7 @@ BIO *BIO_new_NDEF(BIO *out, ASN1_VALUE *val, const ASN1_ITEM *it)
err:
BIO_free(asn_bio);
if (ndef_aux)
OPENSSL_free(ndef_aux);
OPENSSL_free(ndef_aux);
return NULL;
}
@ -186,8 +185,7 @@ static int ndef_prefix_free(BIO *b, unsigned char **pbuf, int *plen,
ndef_aux = *(NDEF_SUPPORT **)parg;
if (ndef_aux->derbuf)
OPENSSL_free(ndef_aux->derbuf);
OPENSSL_free(ndef_aux->derbuf);
ndef_aux->derbuf = NULL;
*pbuf = NULL;


+ 1
- 2
crypto/asn1/f_enum.c View File

@ -154,8 +154,7 @@ int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size)
sp = OPENSSL_realloc(s, (unsigned int)num + i * 2);
if (sp == NULL) {
ASN1err(ASN1_F_A2I_ASN1_ENUMERATED, ERR_R_MALLOC_FAILURE);
if (s != NULL)
OPENSSL_free(s);
OPENSSL_free(s);
goto err;
}
s = sp;


+ 1
- 2
crypto/asn1/f_int.c View File

@ -168,8 +168,7 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size)
sp = OPENSSL_realloc_clean(s, slen, num + i * 2);
if (sp == NULL) {
ASN1err(ASN1_F_A2I_ASN1_INTEGER, ERR_R_MALLOC_FAILURE);
if (s != NULL)
OPENSSL_free(s);
OPENSSL_free(s);
goto err;
}
s = sp;


+ 1
- 2
crypto/asn1/f_string.c View File

@ -160,8 +160,7 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size)
sp = OPENSSL_realloc(s, (unsigned int)num + i * 2);
if (sp == NULL) {
ASN1err(ASN1_F_A2I_ASN1_STRING, ERR_R_MALLOC_FAILURE);
if (s != NULL)
OPENSSL_free(s);
OPENSSL_free(s);
goto err;
}
s = sp;


+ 2
- 4
crypto/asn1/t_x509.c View File

@ -249,8 +249,7 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags,
}
ret = 1;
err:
if (m != NULL)
OPENSSL_free(m);
OPENSSL_free(m);
return (ret);
}
@ -299,8 +298,7 @@ int X509_ocspid_print(BIO *bp, X509 *x)
return (1);
err:
if (der != NULL)
OPENSSL_free(der);
OPENSSL_free(der);
return (0);
}


+ 2
- 3
crypto/asn1/tasn_dec.c View File

@ -765,7 +765,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
*in = p;
ret = 1;
err:
if (free_cont && buf.data)
if (free_cont)
OPENSSL_free(buf.data);
return ret;
}
@ -882,8 +882,7 @@ static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
}
/* If we've already allocated a buffer use it */
if (*free_cont) {
if (stmp->data)
OPENSSL_free(stmp->data);
OPENSSL_free(stmp->data);
stmp->data = (unsigned char *)cont; /* UGLY CAST! RL */
stmp->length = len;
*free_cont = 0;


+ 1
- 2
crypto/asn1/tasn_prn.c View File

@ -100,8 +100,7 @@ ASN1_PCTX *ASN1_PCTX_new(void)
void ASN1_PCTX_free(ASN1_PCTX *p)
{
if (p)
OPENSSL_free(p);
OPENSSL_free(p);
}
unsigned long ASN1_PCTX_get_flags(ASN1_PCTX *p)


+ 1
- 2
crypto/asn1/tasn_scn.c View File

@ -86,8 +86,7 @@ ASN1_SCTX *ASN1_SCTX_new(int (*scan_cb) (ASN1_SCTX *ctx))
void ASN1_SCTX_free(ASN1_SCTX *p)
{
if (p)
OPENSSL_free(p);
OPENSSL_free(p);
}
const ASN1_ITEM *ASN1_SCTX_get_item(ASN1_SCTX *p)


+ 2
- 4
crypto/asn1/tasn_utl.c View File

@ -154,8 +154,7 @@ void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
ASN1_ENCODING *enc;
enc = asn1_get_enc_ptr(pval, it);
if (enc) {
if (enc->enc)
OPENSSL_free(enc->enc);
OPENSSL_free(enc->enc);
enc->enc = NULL;
enc->len = 0;
enc->modified = 1;
@ -170,8 +169,7 @@ int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,
if (!enc)
return 1;
if (enc->enc)
OPENSSL_free(enc->enc);
OPENSSL_free(enc->enc);
enc->enc = OPENSSL_malloc(inlen);
if (!enc->enc)
return 0;


+ 1
- 2
crypto/asn1/x_info.c View File

@ -106,7 +106,6 @@ void X509_INFO_free(X509_INFO *x)
X509_free(x->x509);
X509_CRL_free(x->crl);
X509_PKEY_free(x->x_pkey);
if (x->enc_data != NULL)
OPENSSL_free(x->enc_data);
OPENSSL_free(x->enc_data);
OPENSSL_free(x);
}

+ 1
- 1
crypto/asn1/x_pkey.c View File

@ -113,7 +113,7 @@ void X509_PKEY_free(X509_PKEY *x)
X509_ALGOR_free(x->enc_algor);
ASN1_OCTET_STRING_free(x->enc_pkey);
EVP_PKEY_free(x->dec_pkey);
if ((x->key_data != NULL) && (x->key_free))
if (x->key_free)
OPENSSL_free(x->key_data);
OPENSSL_free(x);
}

+ 1
- 2
crypto/asn1/x_pubkey.c View File

@ -340,8 +340,7 @@ int X509_PUBKEY_set0_param(X509_PUBKEY *pub, ASN1_OBJECT *aobj,
if (!X509_ALGOR_set0(pub->algor, aobj, ptype, pval))
return 0;
if (penc) {
if (pub->public_key->data)
OPENSSL_free(pub->public_key->data);
OPENSSL_free(pub->public_key->data);
pub->public_key->data = penc;
pub->public_key->length = penclen;
/* Set number of unused bits to zero */


+ 2
- 5
crypto/asn1/x_x509.c View File

@ -103,8 +103,7 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
break;
case ASN1_OP_D2I_POST:
if (ret->name != NULL)
OPENSSL_free(ret->name);
OPENSSL_free(ret->name);
ret->name = X509_NAME_oneline(ret->cert_info->subject, NULL, 0);
break;
@ -119,9 +118,7 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
NAME_CONSTRAINTS_free(ret->nc);
sk_IPAddressFamily_pop_free(ret->rfc3779_addr, IPAddressFamily_free);
ASIdentifiers_free(ret->rfc3779_asid);
if (ret->name != NULL)
OPENSSL_free(ret->name);
OPENSSL_free(ret->name);
break;
}


+ 1
- 2
crypto/bio/b_sock.c View File

@ -572,8 +572,7 @@ int BIO_get_accept_socket(char *host, int bind_mode)
}
ret = 1;
err:
if (str != NULL)
OPENSSL_free(str);
OPENSSL_free(str);
if ((ret == 0) && (s != INVALID_SOCKET)) {
closesocket(s);
s = INVALID_SOCKET;


+ 3
- 6
crypto/bio/bf_buff.c View File

@ -127,10 +127,8 @@ static int buffer_free(BIO *a)
if (a == NULL)
return (0);
b = (BIO_F_BUFFER_CTX *)a->ptr;
if (b->ibuf != NULL)
OPENSSL_free(b->ibuf);
if (b->obuf != NULL)
OPENSSL_free(b->obuf);
OPENSSL_free(b->ibuf);
OPENSSL_free(b->obuf);
OPENSSL_free(a->ptr);
a->ptr = NULL;
a->init = 0;
@ -339,8 +337,7 @@ static long buffer_ctrl(BIO *b, int cmd, long num, void *ptr)
p1 = OPENSSL_malloc((int)num);
if (p1 == NULL)
goto malloc_error;
if (ctx->ibuf != NULL)
OPENSSL_free(ctx->ibuf);
OPENSSL_free(ctx->ibuf);
ctx->ibuf = p1;
}
ctx->ibuf_off = 0;


+ 1
- 2
crypto/bio/bf_lbuf.c View File

@ -128,8 +128,7 @@ static int linebuffer_free(BIO *a)
if (a == NULL)
return (0);
b = (BIO_LINEBUFFER_CTX *)a->ptr;
if (b->obuf != NULL)
OPENSSL_free(b->obuf);
OPENSSL_free(b->obuf);
OPENSSL_free(a->ptr);
a->ptr = NULL;
a->init = 0;


+ 1
- 2
crypto/bio/bf_nbio.c View File

@ -116,8 +116,7 @@ static int nbiof_free(BIO *a)
{
if (a == NULL)
return (0);
if (a->ptr != NULL)
OPENSSL_free(a->ptr);
OPENSSL_free(a->ptr);
a->ptr = NULL;
a->init = 0;
a->flags = 0;


+ 3
- 6
crypto/bio/bss_acpt.c View File

@ -151,10 +151,8 @@ static void BIO_ACCEPT_free(BIO_ACCEPT *a)
if (a == NULL)
return;
if (a->param_addr != NULL)
OPENSSL_free(a->param_addr);
if (a->addr != NULL)
OPENSSL_free(a->addr);
OPENSSL_free(a->param_addr);
OPENSSL_free(a->addr);
BIO_free(a->bio_chain);
OPENSSL_free(a);
}
@ -353,8 +351,7 @@ static long acpt_ctrl(BIO *b, int cmd, long num, void *ptr)
if (ptr != NULL) {
if (num == 0) {
b->init = 1;
if (data->param_addr != NULL)
OPENSSL_free(data->param_addr);
OPENSSL_free(data->param_addr);
data->param_addr = BUF_strdup(ptr);
} else if (num == 1) {
data->accept_nbio = (ptr != NULL);


+ 3
- 8
crypto/bio/bss_bio.c View File

@ -170,10 +170,7 @@ static int bio_free(BIO *bio)
if (b->peer)
bio_destroy_pair(bio);
if (b->buf != NULL) {
OPENSSL_free(b->buf);
}
OPENSSL_free(b->buf);
OPENSSL_free(b);
return 1;
@ -507,10 +504,8 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
size_t new_size = num;
if (b->size != new_size) {
if (b->buf) {
OPENSSL_free(b->buf);
b->buf = NULL;
}
OPENSSL_free(b->buf);
b->buf = NULL;
b->size = new_size;
}