Avoid malloc/free - use C99 to allocate variable-length array on stack.

Follow-up on commit a5d5ddccd2372e8e846844521181ad6fea6fbdcb