The OpenSSL library function provides two functions to destroy SSL connection channels: Ssl_shutdown, Ssl_free, the same, the two take one, can not be used at the same time, otherwise there will be two destruction of the object error.
Take a look at the following code snippet:
......
if (Ssl_shutdown (SSL)! = 1)
{
Close (SFD);
printf ("SSL shutdown failed\n");
}
Ssl_free (SSL);
......
Compiling with the-lssl parameter succeeds, but at run time, a double free or corruption error occurs, destroying an object that has already been destroyed. The detailed error message is similar to the following:
[email protected]:/home#./s
GLIBC detected * * *./s:double free or Corruption (!prev): 0x095c0f60 * * *
======= BackTrace: =========
/lib/i386-linux-gnu/libc.so.6 (+0X75EE2) [0x251ee2]
/lib/i386-linux-gnu/libcrypto.so.1.0.0 (CRYPTO_FREE+0X3A) [0x3bf95a]
/lib/i386-linux-gnu/libcrypto.so.1.0.0 (BIO_FREE+0XE0) [0x430610]
/lib/i386-linux-gnu/libcrypto.so.1.0.0 (BIO_FREE_ALL+0X34) [0x431194]
/lib/i386-linux-gnu/libssl.so.1.0.0 (ssl_set_bio+0x49) [0x889d79]
/lib/i386-linux-gnu/libssl.so.1.0.0 (ssl_set_fd+0x57) [0x889f17]
./s[0x8048aee]
/lib/i386-linux-gnu/libpthread.so.0 (+0X6D4C) [0xb93d4c]
/lib/i386-linux-gnu/libc.so.6 (CLONE+0X5E) [0x2cbbae]
======= Memory Map: ========
00110000-00124000 R-xp 00000000 08:02 4893/lib/i386-linux-gnu/libz.so.1.2.3.4
00124000-00125000 r--p 00013000 08:02 4893/lib/i386-linux-gnu/libz.so.1.2.3.4
00125000-00126000 rw-p 00014000 08:02 4893/lib/i386-linux-gnu/libz.so.1.2.3.4
00126000-00142000 R-xp 00000000 08:02 760/lib/i386-linux-gnu/libgcc_s.so.1
00142000-00143000 r--p 0001b000 08:02 760/lib/i386-linux-gnu/libgcc_s.so.1
00143000-00144000 rw-p 0001c000 08:02 760/lib/i386-linux-gnu/libgcc_s.so.1
001dc000-00380000 R-xp 00000000 08:02 3232/lib/i386-linux-gnu/libc-2.15.so
00380000-00382000 r--p 001a4000 08:02 3232/lib/i386-linux-gnu/libc-2.15.so
00382000-00383000 rw-p 001a6000 08:02 3232/lib/i386-linux-gnu/libc-2.15.so
00383000-00386000 Rw-p 00000000 00:00 0
00386000-00519000 R-xp 00000000 08:02 5861/lib/i386-linux-gnu/libcrypto.so.1.0.0
00519000-00528000 r--p 00193000 08:02 5861/lib/i386-linux-gnu/libcrypto.so.1.0.0
00528000-0052f000 rw-p 001a2000 08:02 5861/lib/i386-linux-gnu/libcrypto.so.1.0.0
0052f000-00532000 Rw-p 00000000 00:00 0
00759000-0075c000 R-xp 00000000 08:02 3231/lib/i386-linux-gnu/libdl-2.15.so
0075c000-0075d000 r--p 00002000 08:02 3231/lib/i386-linux-gnu/libdl-2.15.so
0075d000-0075e000 rw-p 00003000 08:02 3231/lib/i386-linux-gnu/libdl-2.15.so
00858000-008a9000 R-xp 00000000 08:02 5862/lib/i386-linux-gnu/libssl.so.1.0.0
008a9000-008ab000 r--p 00051000 08:02 5862/lib/i386-linux-gnu/libssl.so.1.0.0
008ab000-008af000 rw-p 00053000 08:02 5862/lib/i386-linux-gnu/libssl.so.1.0.0
00af6000-00b16000 R-xp 00000000 08:02 3222/lib/i386-linux-gnu/ld-2.15.so
00b16000-00b17000 r--p 0001f000 08:02 3222/lib/i386-linux-gnu/ld-2.15.so
00b17000-00b18000 rw-p 00020000 08:02 3222/lib/i386-linux-gnu/ld-2.15.so
00b8d000-00ba4000 R-xp 00000000 08:02 3221/lib/i386-linux-gnu/libpthread-2.15.so
00ba4000-00ba5000 r--p 00016000 08:02 3221/lib/i386-linux-gnu/libpthread-2.15.so
00ba5000-00ba6000 rw-p 00017000 08:02 3221/lib/i386-linux-gnu/libpthread-2.15.so
00ba6000-00ba8000 Rw-p 00000000 00:00 0
00fed000-00fee000 R-xp 00000000 00:00 0 [VDSO]
08048000-0804a000 R-xp 00000000 08:02 260187/home/s
0804a000-0804b000 r--p 00001000 08:02 260187/home/s
0804b000-0804c000 rw-p 00002000 08:02 260187/home/s
095b3000-095d4000 Rw-p 00000000 00:00 0 [Heap]
b4c00000-b4c21000 Rw-p 00000000 00:00 0
b4c21000-b4d00000---P 00000000 00:00 0
b4e00000-b4e21000 Rw-p 00000000 00:00 0
b4e21000-b4f00000---P 00000000 00:00 0
b4f52000-b4f53000---P 00000000 00:00 0
b4f53000-b5753000 Rw-p 00000000 00:00 0
b5753000-b5754000---P 00000000 00:00 0
b5754000-b5f54000 Rw-p 00000000 00:00 0
b5f54000-b5f55000---P 00000000 00:00 0
b5f55000-b6755000 Rw-p 00000000 00:00 0
b6755000-b6756000---P 00000000 00:00 0
b6756000-b6f56000 Rw-p 00000000 00:00 0
b6f56000-b6f57000---P 00000000 00:00 0
b6f57000-b775a000 Rw-p 00000000 00:00 0
b7763000-b7766000 Rw-p 00000000 00:00 0
bf89e000-bf8bf000 Rw-p 00000000 00:00 0 [Stack]
Aborted
Both functions can be used either, but not both.
Ssl_shutdown, Ssl_free cannot be used simultaneously in the OpenSSL library function