From 1776867489750566cf73800c4e9b8ed684ae1e26 Mon Sep 17 00:00:00 2001 From: Jean-Roland Date: Thu, 17 Oct 2024 19:46:11 +0200 Subject: [PATCH] fix: zbuf init code --- src/protocol/iobuf.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/protocol/iobuf.c b/src/protocol/iobuf.c index cccb5dfcb..7b4b361dc 100644 --- a/src/protocol/iobuf.c +++ b/src/protocol/iobuf.c @@ -168,13 +168,16 @@ _z_iosli_t *_z_iosli_clone(const _z_iosli_t *src) { /*------------------ ZBuf ------------------*/ _z_zbuf_t _z_zbuf_make(size_t capacity) { - _z_zbuf_t zbf; + _z_zbuf_t zbf = {0}; zbf._ios = _z_iosli_make(capacity); + if (_z_zbuf_capacity(&zbf) == 0) { + return zbf; + } _z_slice_t s = _z_slice_from_buf_custom_deleter(zbf._ios._buf, zbf._ios._capacity, _z_delete_context_default()); zbf._slice = _z_slice_simple_rc_new_from_val(&s); if (_Z_RC_IS_NULL(&zbf._slice)) { _Z_ERROR("slice rc creation failed"); - _z_zbuf_clear(&zbf); + _z_iosli_clear(&zbf._ios); } zbf._ios._is_alloc = false; return zbf;