Handle rare case where the last frame during flushing is NULL

Signed-off-by: Carlos Rafael Giani <dv@pseudoterminal.org>