提交 f3f1cf84 编写于 作者: R Rich Salz 提交者: Rich Salz

Move to REF_DEBUG, for consistency.

Add utility macros REF_ASSERT_NOT and REF_PRINT_COUNT
This is also RT 4181
Reviewed-by: NRichard Levitte <levitte@openssl.org>
上级 7823d792
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
Changes between 1.0.2f and 1.1.0 [xx XXX xxxx] Changes between 1.0.2f and 1.1.0 [xx XXX xxxx]
*) Rename REF_CHECK to REF_DEBUG.
[Rich Salz]
*) New "unified" build system *) New "unified" build system
The "unified" build system is aimed to be a common system for all The "unified" build system is aimed to be a common system for all
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
"vos-gcc" => { "vos-gcc" => {
cc => "gcc", cc => "gcc",
cflags => "-Wall -DOPENSSL_SYS_VOS -D_POSIX_C_SOURCE=200112L -D_BSD -D_VOS_EXTENDED_NAMES -DB_ENDIAN", cflags => "-Wall -DOPENSSL_SYS_VOS -D_POSIX_C_SOURCE=200112L -D_BSD -D_VOS_EXTENDED_NAMES -DB_ENDIAN",
debug_cflags => "-O0 -g -DBN_DEBUG -DREF_CHECK -DCONF_DEBUG", debug_cflags => "-O0 -g -DBN_DEBUG -DREF_DEBUG -DCONF_DEBUG",
release_cflags => "-O3", release_cflags => "-O3",
thread_cflag => "(unknown)", thread_cflag => "(unknown)",
sys_id => "VOS", sys_id => "VOS",
...@@ -134,7 +134,7 @@ ...@@ -134,7 +134,7 @@
# -mcpu=ultrasparc # -mcpu=ultrasparc
inherit_from => [ "solaris-sparcv7-gcc", asm("sparcv9_asm") ], inherit_from => [ "solaris-sparcv7-gcc", asm("sparcv9_asm") ],
cflags => add_before(" ", "-m32 -mcpu=ultrasparc"), cflags => add_before(" ", "-m32 -mcpu=ultrasparc"),
debug_cflags => "-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DPEDANTIC -O -g -pedantic -ansi -Wshadow -Wno-long-long -D__EXTENSIONS__", debug_cflags => "-DBN_DEBUG -DREF_DEBUG -DCONF_DEBUG -DBN_CTX_DEBUG -DPEDANTIC -O -g -pedantic -ansi -Wshadow -Wno-long-long -D__EXTENSIONS__",
}, },
"solaris64-sparcv9-gcc" => { "solaris64-sparcv9-gcc" => {
inherit_from => [ "solaris-sparcv9-gcc" ], inherit_from => [ "solaris-sparcv9-gcc" ],
...@@ -152,7 +152,7 @@ ...@@ -152,7 +152,7 @@
inherit_from => [ "solaris-common" ], inherit_from => [ "solaris-common" ],
cc => "cc", cc => "cc",
cflags => add_before("-xstrconst -Xa -DB_ENDIAN -DBN_DIV2W"), cflags => add_before("-xstrconst -Xa -DB_ENDIAN -DBN_DIV2W"),
debug_cflags => "-g -DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG", debug_cflags => "-g -DBN_DEBUG -DREF_DEBUG -DCONF_DEBUG -DBN_CTX_DEBUG",
release_cflags => "-xO5 -xdepend", release_cflags => "-xO5 -xdepend",
thread_cflag => "-D_REENTRANT", thread_cflag => "-D_REENTRANT",
lflags => add("-mt"), lflags => add("-mt"),
...@@ -496,7 +496,7 @@ ...@@ -496,7 +496,7 @@
"linux-generic32" => { "linux-generic32" => {
cc => "gcc", cc => "gcc",
cflags => "-Wall", cflags => "-Wall",
debug_cflags => "-O0 -g -DBN_DEBUG -DREF_CHECK -DCONF_DEBUG", debug_cflags => "-O0 -g -DBN_DEBUG -DREF_DEBUG -DCONF_DEBUG",
release_cflags => "-O3", release_cflags => "-O3",
thread_cflag => "-pthread", thread_cflag => "-pthread",
ex_libs => "-ldl", ex_libs => "-ldl",
...@@ -607,7 +607,7 @@ ...@@ -607,7 +607,7 @@
inherit_from => [ "linux-generic32", asm("x86_elf_asm") ], inherit_from => [ "linux-generic32", asm("x86_elf_asm") ],
cc => "gcc", cc => "gcc",
cflags => "-march=i486 -DL_ENDIAN -Wall", cflags => "-march=i486 -DL_ENDIAN -Wall",
debug_cflags => "-O0 -g -DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG", debug_cflags => "-O0 -g -DBN_DEBUG -DREF_DEBUG -DCONF_DEBUG -DBN_CTX_DEBUG",
release_cflags => "-O3 -fomit-frame-pointer", release_cflags => "-O3 -fomit-frame-pointer",
debug_ex_libs => "-lefence", debug_ex_libs => "-lefence",
bn_ops => "BN_LLONG", bn_ops => "BN_LLONG",
...@@ -1467,7 +1467,7 @@ ...@@ -1467,7 +1467,7 @@
}, },
"vxworks-ppc750-debug" => { "vxworks-ppc750-debug" => {
cc => "ccppc", cc => "ccppc",
cflags => "-ansi -nostdinc -DPPC750 -D_REENTRANT -fvolatile -fno-builtin -fno-for-scope -fsigned-char -Wall -msoft-float -mlongcall -DCPU=PPC604 -I\$(WIND_BASE)/target/h -DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DPEDANTIC -DDEBUG_SAFESTACK -DDEBUG -g", cflags => "-ansi -nostdinc -DPPC750 -D_REENTRANT -fvolatile -fno-builtin -fno-for-scope -fsigned-char -Wall -msoft-float -mlongcall -DCPU=PPC604 -I\$(WIND_BASE)/target/h -DBN_DEBUG -DREF_DEBUG -DCONF_DEBUG -DBN_CTX_DEBUG -DPEDANTIC -DDEBUG_SAFESTACK -DDEBUG -g",
sys_id => "VXWORKS", sys_id => "VXWORKS",
lflags => "-r", lflags => "-r",
}, },
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
}, },
"debug" => { "debug" => {
cc => "gcc", cc => "gcc",
cflags => "-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DOPENSSL_NO_ASM -ggdb -g2 -Wformat -Wshadow -Wmissing-prototypes -Wmissing-declarations -Werror", cflags => "-DBN_DEBUG -DREF_DEBUG -DCONF_DEBUG -DBN_CTX_DEBUG -DOPENSSL_NO_ASM -ggdb -g2 -Wformat -Wshadow -Wmissing-prototypes -Wmissing-declarations -Werror",
thread_cflag => "(unknown)", thread_cflag => "(unknown)",
ex_libs => "-lefence", ex_libs => "-lefence",
}, },
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
"debug-linux-pentium" => { "debug-linux-pentium" => {
inherit_from => [ "x86_elf_asm" ], inherit_from => [ "x86_elf_asm" ],
cc => "gcc", cc => "gcc",
cflags => "-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DL_ENDIAN -g -mcpu=pentium -Wall", cflags => "-DBN_DEBUG -DREF_DEBUG -DCONF_DEBUG -DBN_CTX_DEBUG -DL_ENDIAN -g -mcpu=pentium -Wall",
thread_cflag => "-D_REENTRANT", thread_cflag => "-D_REENTRANT",
ex_libs => "-ldl", ex_libs => "-ldl",
bn_ops => "BN_LLONG", bn_ops => "BN_LLONG",
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
"debug-linux-ppro" => { "debug-linux-ppro" => {
inherit_from => [ "x86_elf_asm" ], inherit_from => [ "x86_elf_asm" ],
cc => "gcc", cc => "gcc",
cflags => "-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DL_ENDIAN -g -mcpu=pentiumpro -Wall", cflags => "-DBN_DEBUG -DREF_DEBUG -DCONF_DEBUG -DBN_CTX_DEBUG -DL_ENDIAN -g -mcpu=pentiumpro -Wall",
thread_cflag => "-D_REENTRANT", thread_cflag => "-D_REENTRANT",
ex_libs => "-ldl", ex_libs => "-ldl",
bn_ops => "BN_LLONG", bn_ops => "BN_LLONG",
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
"debug-linux-elf-noefence" => { "debug-linux-elf-noefence" => {
inherit_from => [ "x86_elf_asm" ], inherit_from => [ "x86_elf_asm" ],
cc => "gcc", cc => "gcc",
cflags => "-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DL_ENDIAN -g -march=i486 -Wall", cflags => "-DBN_DEBUG -DREF_DEBUG -DCONF_DEBUG -DBN_CTX_DEBUG -DL_ENDIAN -g -march=i486 -Wall",
thread_cflag => "-D_REENTRANT", thread_cflag => "-D_REENTRANT",
ex_libs => "-ldl", ex_libs => "-ldl",
bn_ops => "BN_LLONG", bn_ops => "BN_LLONG",
......
...@@ -8,17 +8,17 @@ ...@@ -8,17 +8,17 @@
%targets = ( %targets = (
"debug-ben" => { "debug-ben" => {
cc => "gcc", cc => "gcc",
cflags => "$gcc_devteam_warn -DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DDEBUG_SAFESTACK -O2 -pipe", cflags => "$gcc_devteam_warn -DBN_DEBUG -DREF_DEBUG -DCONF_DEBUG -DBN_CTX_DEBUG -DDEBUG_SAFESTACK -O2 -pipe",
thread_cflag => "(unknown)", thread_cflag => "(unknown)",
}, },
"debug-ben-openbsd" => { "debug-ben-openbsd" => {
cc => "gcc", cc => "gcc",
cflags => "-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DPEDANTIC -DDEBUG_SAFESTACK -DOPENSSL_OPENBSD_DEV_CRYPTO -DOPENSSL_NO_ASM -O2 -pedantic -Wall -Wshadow -Werror -pipe", cflags => "-DBN_DEBUG -DREF_DEBUG -DCONF_DEBUG -DBN_CTX_DEBUG -DPEDANTIC -DDEBUG_SAFESTACK -DOPENSSL_OPENBSD_DEV_CRYPTO -DOPENSSL_NO_ASM -O2 -pedantic -Wall -Wshadow -Werror -pipe",
thread_cflag => "(unknown)", thread_cflag => "(unknown)",
}, },
"debug-ben-openbsd-debug" => { "debug-ben-openbsd-debug" => {
cc => "gcc", cc => "gcc",
cflags => "-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DPEDANTIC -DDEBUG_SAFESTACK -DOPENSSL_OPENBSD_DEV_CRYPTO -DOPENSSL_NO_ASM -g3 -O2 -pedantic -Wall -Wshadow -Werror -pipe", cflags => "-DBN_DEBUG -DREF_DEBUG -DCONF_DEBUG -DBN_CTX_DEBUG -DPEDANTIC -DDEBUG_SAFESTACK -DOPENSSL_OPENBSD_DEV_CRYPTO -DOPENSSL_NO_ASM -g3 -O2 -pedantic -Wall -Wshadow -Werror -pipe",
thread_cflag => "(unknown)", thread_cflag => "(unknown)",
}, },
"debug-ben-debug" => { "debug-ben-debug" => {
...@@ -74,7 +74,7 @@ ...@@ -74,7 +74,7 @@
}, },
"debug-ben-strict" => { "debug-ben-strict" => {
cc => "gcc", cc => "gcc",
cflags => "-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DBN_CTX_DEBUG -DCONST_STRICT -O2 -Wall -Wshadow -Werror -Wpointer-arith -Wcast-qual -Wwrite-strings -pipe", cflags => "-DBN_DEBUG -DREF_DEBUG -DCONF_DEBUG -DBN_CTX_DEBUG -DCONST_STRICT -O2 -Wall -Wshadow -Werror -Wpointer-arith -Wcast-qual -Wwrite-strings -pipe",
thread_cflag => "(unknown)", thread_cflag => "(unknown)",
}, },
"debug-ben-darwin64" => { "debug-ben-darwin64" => {
......
...@@ -80,7 +80,7 @@ my $usage="Usage: Configure [no-<cipher> ...] [enable-<cipher> ...] [experimenta ...@@ -80,7 +80,7 @@ my $usage="Usage: Configure [no-<cipher> ...] [enable-<cipher> ...] [experimenta
# Minimum warning options... any contributions to OpenSSL should at least get # Minimum warning options... any contributions to OpenSSL should at least get
# past these. # past these.
my $gcc_devteam_warn = "-Wall -pedantic -DPEDANTIC -Wno-long-long -Wsign-compare -Wmissing-prototypes -Wshadow -Wformat -Wtype-limits -Werror -DREF_CHECK -DDEBUG_UNUSED"; my $gcc_devteam_warn = "-Wall -pedantic -DPEDANTIC -Wno-long-long -Wsign-compare -Wmissing-prototypes -Wshadow -Wformat -Wtype-limits -Werror -DREF_DEBUG -DDEBUG_UNUSED";
# These are used in addition to $gcc_devteam_warn when the compiler is clang. # These are used in addition to $gcc_devteam_warn when the compiler is clang.
# TODO(openssl-team): fix problems and investigate if (at least) the # TODO(openssl-team): fix problems and investigate if (at least) the
......
...@@ -76,7 +76,7 @@ ENGINESDIR={- use File::Spec::Functions; ...@@ -76,7 +76,7 @@ ENGINESDIR={- use File::Spec::Functions;
# NULL encryption ciphers. # NULL encryption ciphers.
# #
# LOCK_DEBUG - turns on lots of lock debug output :-) # LOCK_DEBUG - turns on lots of lock debug output :-)
# REF_CHECK - turn on some xyz_free() assertions. # REF_DEBUG - turn on some xyz_free() assertions.
# REF_PRINT - prints some stuff on structure free. # REF_PRINT - prints some stuff on structure free.
# MFUNC - Make all Malloc/Free/Realloc calls call # MFUNC - Make all Malloc/Free/Realloc calls call
# CRYPTO_malloc/CRYPTO_free/CRYPTO_realloc which can be setup to # CRYPTO_malloc/CRYPTO_free/CRYPTO_realloc which can be setup to
......
...@@ -118,12 +118,9 @@ int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it) ...@@ -118,12 +118,9 @@ int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it)
} }
ret = CRYPTO_add(lck, op, aux->ref_lock); ret = CRYPTO_add(lck, op, aux->ref_lock);
#ifdef REF_PRINT #ifdef REF_PRINT
fprintf(stderr, "%s: Reference Count: %d\n", it->sname, *lck); fprintf(stderr, "%p:%4d:%s\n", it, *lck, it->sname);
#endif
#ifdef REF_CHECK
if (ret < 0)
fprintf(stderr, "%s, bad reference count\n", it->sname);
#endif #endif
REF_ASSERT_ISNT(ret < 0);
return ret; return ret;
} }
......
...@@ -82,17 +82,10 @@ void X509_INFO_free(X509_INFO *x) ...@@ -82,17 +82,10 @@ void X509_INFO_free(X509_INFO *x)
return; return;
i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_X509_INFO); i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_X509_INFO);
#ifdef REF_PRINT REF_PRINT_COUNT("X509_INFO", x);
REF_PRINT("X509_INFO", x);
#endif
if (i > 0) if (i > 0)
return; return;
#ifdef REF_CHECK REF_ASSERT_ISNT(i < 0);
if (i < 0) {
fprintf(stderr, "X509_INFO_free, bad reference count\n");
abort();
}
#endif
X509_free(x->x509); X509_free(x->x509);
X509_CRL_free(x->crl); X509_CRL_free(x->crl);
......
...@@ -90,17 +90,10 @@ void X509_PKEY_free(X509_PKEY *x) ...@@ -90,17 +90,10 @@ void X509_PKEY_free(X509_PKEY *x)
return; return;
i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_X509_PKEY); i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_X509_PKEY);
#ifdef REF_PRINT REF_PRINT_COUNT("X509_PKEY", x);
REF_PRINT("X509_PKEY", x);
#endif
if (i > 0) if (i > 0)
return; return;
#ifdef REF_CHECK REF_ASSERT_ISNT(i < 0);
if (i < 0) {
fprintf(stderr, "X509_PKEY_free, bad reference count\n");
abort();
}
#endif
X509_ALGOR_free(x->enc_algor); X509_ALGOR_free(x->enc_algor);
ASN1_OCTET_STRING_free(x->enc_pkey); ASN1_OCTET_STRING_free(x->enc_pkey);
......
/* crypto/bio/bio_err.c */
/* ==================================================================== /* ====================================================================
* Copyright (c) 1999-2016 The OpenSSL Project. All rights reserved. * Copyright (c) 1999-2016 The OpenSSL Project. All rights reserved.
* *
...@@ -96,6 +97,7 @@ static ERR_STRING_DATA BIO_str_functs[] = { ...@@ -96,6 +97,7 @@ static ERR_STRING_DATA BIO_str_functs[] = {
{ERR_FUNC(BIO_F_BIO_PUTS), "BIO_puts"}, {ERR_FUNC(BIO_F_BIO_PUTS), "BIO_puts"},
{ERR_FUNC(BIO_F_BIO_READ), "BIO_read"}, {ERR_FUNC(BIO_F_BIO_READ), "BIO_read"},
{ERR_FUNC(BIO_F_BIO_SOCKET), "BIO_socket"}, {ERR_FUNC(BIO_F_BIO_SOCKET), "BIO_socket"},
{ERR_FUNC(BIO_F_BIO_SOCKET_NBIO), "BIO_socket_nbio"},
{ERR_FUNC(BIO_F_BIO_SOCK_INFO), "BIO_sock_info"}, {ERR_FUNC(BIO_F_BIO_SOCK_INFO), "BIO_sock_info"},
{ERR_FUNC(BIO_F_BIO_SOCK_INIT), "BIO_sock_init"}, {ERR_FUNC(BIO_F_BIO_SOCK_INIT), "BIO_sock_init"},
{ERR_FUNC(BIO_F_BIO_WRITE), "BIO_write"}, {ERR_FUNC(BIO_F_BIO_WRITE), "BIO_write"},
......
...@@ -110,17 +110,10 @@ int BIO_free(BIO *a) ...@@ -110,17 +110,10 @@ int BIO_free(BIO *a)
return (0); return (0);
i = CRYPTO_add(&a->references, -1, CRYPTO_LOCK_BIO); i = CRYPTO_add(&a->references, -1, CRYPTO_LOCK_BIO);
#ifdef REF_PRINT REF_PRINT_COUNT("BIO", a);
REF_PRINT("BIO", a);
#endif
if (i > 0) if (i > 0)
return (1); return (1);
#ifdef REF_CHECK REF_ASSERT_ISNT(i < 0);
if (i < 0) {
fprintf(stderr, "BIO_free, bad reference count\n");
abort();
}
#endif
if ((a->callback != NULL) && if ((a->callback != NULL) &&
((i = (int)a->callback(a, BIO_CB_FREE, NULL, 0, 0L, 1L)) <= 0)) ((i = (int)a->callback(a, BIO_CB_FREE, NULL, 0, 0L, 1L)) <= 0))
return (i); return (i);
......
...@@ -157,17 +157,10 @@ void DH_free(DH *r) ...@@ -157,17 +157,10 @@ void DH_free(DH *r)
if (r == NULL) if (r == NULL)
return; return;
i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_DH); i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_DH);
#ifdef REF_PRINT REF_PRINT_COUNT("DH", r);
REF_PRINT("DH", r);
#endif
if (i > 0) if (i > 0)
return; return;
#ifdef REF_CHECK REF_ASSERT_ISNT(i < 0);
if (i < 0) {
fprintf(stderr, "DH_free, bad reference count\n");
abort();
}
#endif
if (r->meth->finish) if (r->meth->finish)
r->meth->finish(r); r->meth->finish(r);
...@@ -192,15 +185,9 @@ void DH_free(DH *r) ...@@ -192,15 +185,9 @@ void DH_free(DH *r)
int DH_up_ref(DH *r) int DH_up_ref(DH *r)
{ {
int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_DH); int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_DH);
#ifdef REF_PRINT
REF_PRINT("DH", r); REF_PRINT_COUNT("DH", r);
#endif REF_ASSERT_ISNT(i < 2);
#ifdef REF_CHECK
if (i < 2) {
fprintf(stderr, "DH_up, bad reference count\n");
abort();
}
#endif
return ((i > 1) ? 1 : 0); return ((i > 1) ? 1 : 0);
} }
......
...@@ -165,17 +165,10 @@ void DSA_free(DSA *r) ...@@ -165,17 +165,10 @@ void DSA_free(DSA *r)
return; return;
i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_DSA); i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_DSA);
#ifdef REF_PRINT REF_PRINT_COUNT("DSA", r);
REF_PRINT("DSA", r);
#endif
if (i > 0) if (i > 0)
return; return;
#ifdef REF_CHECK REF_ASSERT_ISNT(i < 0);
if (i < 0) {
fprintf(stderr, "DSA_free, bad reference count\n");
abort();
}
#endif
if (r->meth->finish) if (r->meth->finish)
r->meth->finish(r); r->meth->finish(r);
...@@ -199,15 +192,9 @@ void DSA_free(DSA *r) ...@@ -199,15 +192,9 @@ void DSA_free(DSA *r)
int DSA_up_ref(DSA *r) int DSA_up_ref(DSA *r)
{ {
int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_DSA); int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_DSA);
#ifdef REF_PRINT
REF_PRINT("DSA", r); REF_PRINT_COUNT("DSA", r);
#endif REF_ASSERT_ISNT(i < 2);
#ifdef REF_CHECK
if (i < 2) {
fprintf(stderr, "DSA_up_ref, bad reference count\n");
abort();
}
#endif
return ((i > 1) ? 1 : 0); return ((i > 1) ? 1 : 0);
} }
......
...@@ -136,17 +136,10 @@ int DSO_free(DSO *dso) ...@@ -136,17 +136,10 @@ int DSO_free(DSO *dso)
return (1); return (1);
i = CRYPTO_add(&dso->references, -1, CRYPTO_LOCK_DSO); i = CRYPTO_add(&dso->references, -1, CRYPTO_LOCK_DSO);
#ifdef REF_PRINT REF_PRINT_COUNT("DSO", dso);
REF_PRINT("DSO", dso);
#endif
if (i > 0) if (i > 0)
return (1); return (1);
#ifdef REF_CHECK REF_ASSERT_ISNT(i < 0);
if (i < 0) {
fprintf(stderr, "DSO_free, bad reference count\n");
abort();
}
#endif
if ((dso->meth->dso_unload != NULL) && !dso->meth->dso_unload(dso)) { if ((dso->meth->dso_unload != NULL) && !dso->meth->dso_unload(dso)) {
DSOerr(DSO_F_DSO_FREE, DSO_R_UNLOAD_FAILED); DSOerr(DSO_F_DSO_FREE, DSO_R_UNLOAD_FAILED);
......
...@@ -99,17 +99,10 @@ void EC_KEY_free(EC_KEY *r) ...@@ -99,17 +99,10 @@ void EC_KEY_free(EC_KEY *r)
return; return;
i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_EC); i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_EC);
#ifdef REF_PRINT REF_PRINT_COUNT("EC_KEY", r);
REF_PRINT("EC_KEY", r);
#endif
if (i > 0) if (i > 0)
return; return;
#ifdef REF_CHECK REF_ASSERT_ISNT(i < 0);
if (i < 0) {
fprintf(stderr, "EC_KEY_free, bad reference count\n");
abort();
}
#endif
if (r->meth->finish != NULL) if (r->meth->finish != NULL)
r->meth->finish(r); r->meth->finish(r);
...@@ -213,15 +206,9 @@ EC_KEY *EC_KEY_dup(EC_KEY *ec_key) ...@@ -213,15 +206,9 @@ EC_KEY *EC_KEY_dup(EC_KEY *ec_key)
int EC_KEY_up_ref(EC_KEY *r) int EC_KEY_up_ref(EC_KEY *r)
{ {
int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_EC); int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_EC);
#ifdef REF_PRINT
REF_PRINT("EC_KEY", r); REF_PRINT_COUNT("EC_KEY", r);
#endif REF_ASSERT_ISNT(i < 2);
#ifdef REF_CHECK
if (i < 2) {
fprintf(stderr, "EC_KEY_up, bad reference count\n");
abort();
}
#endif
return ((i > 1) ? 1 : 0); return ((i > 1) ? 1 : 0);
} }
......
...@@ -108,12 +108,7 @@ int engine_unlocked_finish(ENGINE *e, int unlock_for_handlers) ...@@ -108,12 +108,7 @@ int engine_unlocked_finish(ENGINE *e, int unlock_for_handlers)
if (!to_return) if (!to_return)
return 0; return 0;
} }
#ifdef REF_CHECK REF_ASSERT_ISNT(e->funct_ref < 0);
if (e->funct_ref < 0) {
fprintf(stderr, "ENGINE_finish, bad functional reference count\n");
abort();
}
#endif
/* Release the structural reference too */ /* Release the structural reference too */
if (!engine_free_util(e, 0)) { if (!engine_free_util(e, 0)) {
ENGINEerr(ENGINE_F_ENGINE_UNLOCKED_FINISH, ENGINE_R_FINISH_FAILED); ENGINEerr(ENGINE_F_ENGINE_UNLOCKED_FINISH, ENGINE_R_FINISH_FAILED);
......
...@@ -114,12 +114,7 @@ int engine_free_util(ENGINE *e, int locked) ...@@ -114,12 +114,7 @@ int engine_free_util(ENGINE *e, int locked)
engine_ref_debug(e, 0, -1) engine_ref_debug(e, 0, -1)
if (i > 0) if (i > 0)
return 1; return 1;
#ifdef REF_CHECK REF_ASSERT_ISNT(i < 0);
if (i < 0) {
fprintf(stderr, "ENGINE_free, bad structural reference count\n");
abort();
}
#endif
/* Free up any dynamically allocated public key methods */ /* Free up any dynamically allocated public key methods */
engine_pkey_meths_free(e); engine_pkey_meths_free(e);
engine_pkey_asn1_meths_free(e); engine_pkey_asn1_meths_free(e);
......
...@@ -241,9 +241,13 @@ static void int_thread_del_item(const ERR_STATE *); ...@@ -241,9 +241,13 @@ static void int_thread_del_item(const ERR_STATE *);
/* /*
* The internal state * The internal state
*/ */
/* This is a struct so that REF_PRINT_COUNT works. */
static struct refcount {
int references;
} refcount = { 0 };
static LHASH_OF(ERR_STRING_DATA) *int_error_hash = NULL; static LHASH_OF(ERR_STRING_DATA) *int_error_hash = NULL;
static LHASH_OF(ERR_STATE) *int_thread_hash = NULL; static LHASH_OF(ERR_STATE) *int_thread_hash = NULL;
static int int_thread_hash_references = 0;
static int int_err_library_number = ERR_LIB_USER; static int int_err_library_number = ERR_LIB_USER;
static unsigned long get_error_values(int inc, int top, const char **file, static unsigned long get_error_values(int inc, int top, const char **file,
...@@ -317,7 +321,7 @@ static LHASH_OF(ERR_STATE) *int_thread_get(int create, int lockit) ...@@ -317,7 +321,7 @@ static LHASH_OF(ERR_STATE) *int_thread_get(int create, int lockit)
int_thread_hash = lh_ERR_STATE_new(err_state_hash, err_state_cmp); int_thread_hash = lh_ERR_STATE_new(err_state_hash, err_state_cmp);
} }
if (int_thread_hash != NULL) { if (int_thread_hash != NULL) {
int_thread_hash_references++; refcount.references++;
ret = int_thread_hash; ret = int_thread_hash;
} }
if (lockit) if (lockit)
...@@ -332,19 +336,12 @@ static void int_thread_release(LHASH_OF(ERR_STATE) **hash) ...@@ -332,19 +336,12 @@ static void int_thread_release(LHASH_OF(ERR_STATE) **hash)
if (hash == NULL || *hash == NULL) if (hash == NULL || *hash == NULL)
return; return;
i = CRYPTO_add(&int_thread_hash_references, -1, CRYPTO_LOCK_ERR); i = CRYPTO_add(&refcount.references, -1, CRYPTO_LOCK_ERR);
#ifdef REF_PRINT REF_PRINT_COUNT(&refcount, "ERR");
fprintf(stderr, "%4d:%s\n", int_thread_hash_references, "ERR");
#endif
if (i > 0) if (i > 0)
return; return;
#ifdef REF_CHECK REF_ASSERT_ISNT(i < 0);
if (i < 0) {
fprintf(stderr, "int_thread_release, bad reference count\n");
abort(); /* ok */
}
#endif
*hash = NULL; *hash = NULL;
} }
...@@ -389,10 +386,10 @@ static void int_thread_del_item(const ERR_STATE *d) ...@@ -389,10 +386,10 @@ static void int_thread_del_item(const ERR_STATE *d)
p = lh_ERR_STATE_delete(hash, d); p = lh_ERR_STATE_delete(hash, d);
/* If there are no other references, and we just removed the /* If there are no other references, and we just removed the
* last item, delete the int_thread_hash */ * last item, delete the int_thread_hash */
if (int_thread_hash_references == 1 if (refcount.references == 1
&& int_thread_hash && int_thread_hash
&& lh_ERR_STATE_num_items(int_thread_hash) == 0) { && lh_ERR_STATE_num_items(int_thread_hash) == 0) {
int_thread_hash_references = 0; refcount.references = 0;
lh_ERR_STATE_free(int_thread_hash); lh_ERR_STATE_free(int_thread_hash);
int_thread_hash = NULL; int_thread_hash = NULL;
hash = NULL; hash = NULL;
......
...@@ -425,17 +425,10 @@ void EVP_PKEY_free(EVP_PKEY *x) ...@@ -425,17 +425,10 @@ void EVP_PKEY_free(EVP_PKEY *x)
return; return;
i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_EVP_PKEY); i = CRYPTO_add(&x->references, -1, CRYPTO_LOCK_EVP_PKEY);
#ifdef REF_PRINT REF_PRINT_COUNT("EVP_PKEY", x);
REF_PRINT("EVP_PKEY", x);
#endif
if (i > 0) if (i > 0)
return; return;
#ifdef REF_CHECK REF_ASSERT_ISNT(i < 0);
if (i < 0) {
fprintf(stderr, "EVP_PKEY_free, bad reference count\n");
abort();
}
#endif
EVP_PKEY_free_it(x); EVP_PKEY_free_it(x);
sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free); sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free);
OPENSSL_free(x); OPENSSL_free(x);
......
...@@ -305,7 +305,7 @@ void CRYPTO_destroy_dynlockid(int i) ...@@ -305,7 +305,7 @@ void CRYPTO_destroy_dynlockid(int i)
pointer = sk_CRYPTO_dynlock_value(dyn_locks, i); pointer = sk_CRYPTO_dynlock_value(dyn_locks, i);
if (pointer != NULL) { if (pointer != NULL) {
--pointer->references; --pointer->references;
#ifdef REF_CHECK #ifdef REF_DEBUG
if (pointer->references < 0) { if (pointer->references < 0) {
OPENSSL_showfatal("CRYPTO_destroy_dynlockid, bad reference count\n"); OPENSSL_showfatal("CRYPTO_destroy_dynlockid, bad reference count\n");
abort(); abort();
......
...@@ -183,17 +183,10 @@ void RSA_free(RSA *r) ...@@ -183,17 +183,10 @@ void RSA_free(RSA *r)
return; return;
i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_RSA); i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_RSA);
#ifdef REF_PRINT REF_PRINT_COUNT("RSA", r);
REF_PRINT("RSA", r);
#endif
if (i > 0) if (i > 0)
return; return;
#ifdef REF_CHECK REF_ASSERT_ISNT(i < 0);
if (i < 0) {
fprintf(stderr, "RSA_free, bad reference count\n");
abort();
}
#endif
if (r->meth->finish) if (r->meth->finish)
r->meth->finish(r); r->meth->finish(r);
...@@ -221,15 +214,9 @@ void RSA_free(RSA *r) ...@@ -221,15 +214,9 @@ void RSA_free(RSA *r)
int RSA_up_ref(RSA *r) int RSA_up_ref(RSA *r)
{ {
int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_RSA); int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_RSA);
#ifdef REF_PRINT
REF_PRINT("RSA", r); REF_PRINT_COUNT("RSA", r);
#endif REF_ASSERT_ISNT(i < 2);
#ifdef REF_CHECK
if (i < 2) {
fprintf(stderr, "RSA_up_ref, bad reference count\n");
abort();
}
#endif
return ((i > 1) ? 1 : 0); return ((i > 1) ? 1 : 0);
} }
......
...@@ -229,17 +229,10 @@ void X509_STORE_free(X509_STORE *vfy) ...@@ -229,17 +229,10 @@ void X509_STORE_free(X509_STORE *vfy)
return; return;
i = CRYPTO_add(&vfy->references, -1, CRYPTO_LOCK_X509_STORE); i = CRYPTO_add(&vfy->references, -1, CRYPTO_LOCK_X509_STORE);
#ifdef REF_PRINT REF_PRINT_COUNT("X509_STORE", vfy);
REF_PRINT("X509_STORE", vfy);
#endif
if (i > 0) if (i > 0)
return; return;
#ifdef REF_CHECK REF_ASSERT_ISNT(i < 0);
if (i < 0) {
fprintf(stderr, "X509_STORE_free, bad reference count\n");
abort(); /* ok */
}
#endif
sk = vfy->get_cert_methods; sk = vfy->get_cert_methods;
for (i = 0; i < sk_X509_LOOKUP_num(sk); i++) { for (i = 0; i < sk_X509_LOOKUP_num(sk); i++) {
......
...@@ -71,15 +71,26 @@ extern "C" { ...@@ -71,15 +71,26 @@ extern "C" {
#endif #endif
/* Used to checking reference counts, most while doing perl5 stuff :-) */ /* Used to checking reference counts, most while doing perl5 stuff :-) */
# ifdef REF_PRINT # if defined(OPENSSL_NO_STDIO)
# undef REF_PRINT # if defined(REF_DEBUG)
# define REF_PRINT(a,b) fprintf(stderr,"%08X:%4d:%s\n",(int)b,b->references,a) # error "REF_DEBUG requires stdio"
# endif
# if defined(REF_PRINT)
# error "REF_PRINT requires stdio"
# endif
# endif # endif
# if defined(OPENSSL_NO_STDIO) && defined(REF_CHECK)
# error "Cannot have REF_CHECK with no-stdio" # if defined(REF_DEBUG)
# define REF_ASSERT_ISNT(test) \
(void)((test) ? (OpenSSLDie(__FILE__, __LINE__, "refcount error"), 1) : 0)
# else
# define REF_ASSERT_ISNT(i)
# endif # endif
# if defined(OPENSSL_NO_STDIO) && defined(REF_PRINT) # ifdef REF_PRINT
# error "Cannot have REF_PRINT with no-stdio" # define REF_PRINT_COUNT(a, b) \
fprintf(stderr, "%p:%4d:%s\n", b, b->references, a)
# else
# define REF_PRINT_COUNT(a, b)
# endif # endif
# ifndef DEVRANDOM # ifndef DEVRANDOM
......
...@@ -857,6 +857,7 @@ void ERR_load_BIO_strings(void); ...@@ -857,6 +857,7 @@ void ERR_load_BIO_strings(void);
# define BIO_F_BIO_PUTS 110 # define BIO_F_BIO_PUTS 110
# define BIO_F_BIO_READ 111 # define BIO_F_BIO_READ 111
# define BIO_F_BIO_SOCKET 140 # define BIO_F_BIO_SOCKET 140
# define BIO_F_BIO_SOCKET_NBIO 142
# define BIO_F_BIO_SOCK_INFO 141 # define BIO_F_BIO_SOCK_INFO 141
# define BIO_F_BIO_SOCK_INIT 112 # define BIO_F_BIO_SOCK_INIT 112
# define BIO_F_BIO_WRITE 113 # define BIO_F_BIO_WRITE 113
......
...@@ -335,17 +335,10 @@ void ssl_cert_free(CERT *c) ...@@ -335,17 +335,10 @@ void ssl_cert_free(CERT *c)
return; return;
i = CRYPTO_add(&c->references, -1, CRYPTO_LOCK_SSL_CERT); i = CRYPTO_add(&c->references, -1, CRYPTO_LOCK_SSL_CERT);
#ifdef REF_PRINT REF_PRINT_COUNT("CERT", c);
REF_PRINT("CERT", c);
#endif
if (i > 0) if (i > 0)
return; return;
#ifdef REF_CHECK REF_ASSERT_ISNT(i < 0);
if (i < 0) {
fprintf(stderr, "ssl_cert_free, bad reference count\n");
abort(); /* ok */
}
#endif
#ifndef OPENSSL_NO_DH #ifndef OPENSSL_NO_DH
EVP_PKEY_free(c->dh_tmp); EVP_PKEY_free(c->dh_tmp);
......
...@@ -55,9 +55,6 @@ ...@@ -55,9 +55,6 @@
* *
*/ */
#ifdef REF_CHECK
# include <assert.h>
#endif
#include <stdio.h> #include <stdio.h>
#include "ssl_locl.h" #include "ssl_locl.h"
#include <openssl/conf.h> #include <openssl/conf.h>
......
...@@ -142,7 +142,7 @@ ...@@ -142,7 +142,7 @@
* OTHERWISE. * OTHERWISE.
*/ */
#ifdef REF_CHECK #ifdef REF_DEBUG
# include <assert.h> # include <assert.h>
#endif #endif
#include <stdio.h> #include <stdio.h>
...@@ -995,17 +995,10 @@ void SSL_free(SSL *s) ...@@ -995,17 +995,10 @@ void SSL_free(SSL *s)
return; return;
i = CRYPTO_add(&s->references, -1, CRYPTO_LOCK_SSL); i = CRYPTO_add(&s->references, -1, CRYPTO_LOCK_SSL);
#ifdef REF_PRINT REF_PRINT_COUNT("SSL", s);
REF_PRINT("SSL", s);
#endif
if (i > 0) if (i > 0)
return; return;
#ifdef REF_CHECK REF_ASSERT_ISNT(i < 0);
if (i < 0) {
fprintf(stderr, "SSL_free, bad reference count\n");
abort(); /* ok */
}
#endif
X509_VERIFY_PARAM_free(s->param); X509_VERIFY_PARAM_free(s->param);
dane_final(&s->dane); dane_final(&s->dane);
...@@ -2400,17 +2393,10 @@ void SSL_CTX_free(SSL_CTX *a) ...@@ -2400,17 +2393,10 @@ void SSL_CTX_free(SSL_CTX *a)
return; return;
i = CRYPTO_add(&a->references, -1, CRYPTO_LOCK_SSL_CTX); i = CRYPTO_add(&a->references, -1, CRYPTO_LOCK_SSL_CTX);
#ifdef REF_PRINT REF_PRINT_COUNT("SSL_CTX", a);
REF_PRINT("SSL_CTX", a);
#endif
if (i > 0) if (i > 0)
return; return;
#ifdef REF_CHECK REF_ASSERT_ISNT(i < 0);
if (i < 0) {
fprintf(stderr, "SSL_CTX_free, bad reference count\n");
abort(); /* ok */
}
#endif
X509_VERIFY_PARAM_free(a->param); X509_VERIFY_PARAM_free(a->param);
dane_ctx_final(&a->dane); dane_ctx_final(&a->dane);
...@@ -3274,8 +3260,11 @@ void ssl_free_wbio_buffer(SSL *s) ...@@ -3274,8 +3260,11 @@ void ssl_free_wbio_buffer(SSL *s)
if (s->bbio == s->wbio) { if (s->bbio == s->wbio) {
/* remove buffering */ /* remove buffering */
s->wbio = BIO_pop(s->wbio); s->wbio = BIO_pop(s->wbio);
#ifdef REF_CHECK /* not the usual REF_CHECK, but this avoids #ifdef REF_DEBUG
* adding one more preprocessor symbol */ /*
* not the usual REF_DEBUG, but this avoids
* adding one more preprocessor symbol
*/
assert(s->wbio != NULL); assert(s->wbio != NULL);
#endif #endif
} }
......
...@@ -814,17 +814,10 @@ void SSL_SESSION_free(SSL_SESSION *ss) ...@@ -814,17 +814,10 @@ void SSL_SESSION_free(SSL_SESSION *ss)
return; return;
i = CRYPTO_add(&ss->references, -1, CRYPTO_LOCK_SSL_SESSION); i = CRYPTO_add(&ss->references, -1, CRYPTO_LOCK_SSL_SESSION);
#ifdef REF_PRINT REF_PRINT_COUNT("SSL_SESSION", ss);
REF_PRINT("SSL_SESSION", ss);
#endif
if (i > 0) if (i > 0)
return; return;
#ifdef REF_CHECK REF_ASSERT_ISNT(i < 0);
if (i < 0) {
fprintf(stderr, "SSL_SESSION_free, bad reference count\n");
abort(); /* ok */
}
#endif
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data); CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data);
......
...@@ -11,7 +11,7 @@ $rm='/bin/rm -f'; ...@@ -11,7 +11,7 @@ $rm='/bin/rm -f';
$cc='gcc'; $cc='gcc';
if ($debug) if ($debug)
{ $cflags="-g2 -ggdb -DREF_CHECK"; } { $cflags="-g2 -ggdb -DREF_DEBUG"; }
elsif ($profile) elsif ($profile)
{ $cflags="-pg -O3"; } { $cflags="-pg -O3"; }
else else
......
...@@ -11,7 +11,7 @@ $rm='/bin/rm -f'; ...@@ -11,7 +11,7 @@ $rm='/bin/rm -f';
$cc='cc'; $cc='cc';
if ($debug) if ($debug)
{ $cflags="-g -DREF_CHECK"; } { $cflags="-g -DREF_DEBUG"; }
else else
{ $cflags="-O2"; } { $cflags="-O2"; }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册