Avoid sequences of malloc(0) / free() by checking the length.

This has an impact on heap fragmentation.

Signed-off-by: Matthieu Herrb <matthieu.herrb@laas.fr>
4 jobs for master in 4 minutes and 56 seconds (queued for 1 second)
Status Name Job ID Coverage
  Docker Image
passed debian-buster #7822978

00:00:11

 
  Build And Test
passed autotools #7822979

00:04:44

passed meson #7822980

00:02:50

passed meson-noglamor #7822981

00:02:03