crypto-api: always allocate memory when serializing iovec_t

The AEAD iov interface falls back to serializing the input buffers if
the low-level cipher doesn't support scatter/gather encryption.
However, there was a bug in the functions used for the serialization,
which causes memory leaks under a certain condition (i.e. the number
of input buffers is 1).

This patch makes the logic of the functions simpler, by removing a
micro-optimization that tries to minimize the number of calls to
malloc/free.

The original problem was reported by Marius Steffen in:
https://bugzilla.samba.org/show_bug.cgi?id=14399
and the cause was investigated by Alexander Haase in:
!1277

Signed-off-by: Daiki Ueno <[email protected]>
23 jobs for tmp-iov-memleak in 72 minutes and 3 seconds (queued for 1 second)
Status Job ID Name Coverage
  Stage1 Testing
passed #583667551
linux docker shared
Debian.cross.aarch64-linux-gnu

01:05:20

passed #583667546
linux docker shared
Debian.cross.arm-linux-gnueabihf

01:11:57

passed #583667543
linux docker shared
Debian.cross.i686-linux-gnu

00:34:02

passed #583667549
linux docker shared
Debian.cross.mips-linux-gnu

01:05:08

passed #583667534
linux shared
Debian.x86_64

00:27:23

passed #583667495
linux shared
FIPS140-2.Fedora.x86_64

00:29:30

passed #583667529
freebsd
FreeBSD.x86_64

00:36:30

passed #583667526
linux docker shared
MinGW32

00:27:21

passed #583667522
linux docker shared
MinGW64

00:21:42

passed #583667519
linux docker shared
MinGW64.Vista+

00:18:18

passed #583667491
linux shared
SSL-3.0.Fedora.x86_64

00:28:30

passed #583667531
linux shared
UB+ASAN-Werror.Fedora.x86_64.gcc

00:46:02

passed #583667481
linux shared
abi/coverage

00:33:14

77.1%
passed #583667477
commit-check

00:00:46

passed #583667478
linux shared
doc-dist.Fedora

00:40:49

passed #583667484
linux shared
minimal.Fedora.x86_64

00:19:53

passed #583667556
linux shared
nettle-master-minigmp.Fedora

00:24:41

passed #583667554
linux shared
nettle-master.Fedora

00:31:17

passed #583667514
linux shared
static-analyzers.Fedora.x86_64

00:28:04

passed #583667502
linux shared
threadsan.Fedora.x86_64

00:14:22

passed #583667498
linux shared
valgrind.Fedora.x86_64

00:53:55

 
  External
passed LGTM analysis: C/C++

00:28:21

passed LGTM analysis: JavaScript

00:05:52