Skip to content

Commit 44c061b

Browse files
committed
fixup: Avoid UB in valkeyReconnect when compiled with -DNDEBUG
Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>
1 parent 4c61901 commit 44c061b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/valkey.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -773,10 +773,10 @@ int valkeyReconnect(valkeyContext *c) {
773773
memset(c->errstr, '\0', strlen(c->errstr));
774774

775775
assert(c->funcs);
776-
if (c->funcs->close)
776+
if (c->funcs && c->funcs->close)
777777
c->funcs->close(c);
778778

779-
if (c->privctx && c->funcs->free_privctx) {
779+
if (c->privctx && c->funcs && c->funcs->free_privctx) {
780780
c->funcs->free_privctx(c->privctx);
781781
c->privctx = NULL;
782782
}
@@ -810,11 +810,13 @@ int valkeyReconnect(valkeyContext *c) {
810810
return VALKEY_ERR;
811811
}
812812

813-
if (c->funcs->connect(c, &options) != VALKEY_OK) {
813+
if (c->funcs && c->funcs->connect &&
814+
c->funcs->connect(c, &options) != VALKEY_OK) {
814815
return VALKEY_ERR;
815816
}
816817

817-
if (c->command_timeout != NULL && (c->flags & VALKEY_BLOCK) && c->fd != VALKEY_INVALID_FD) {
818+
if (c->command_timeout != NULL && (c->flags & VALKEY_BLOCK) &&
819+
c->fd != VALKEY_INVALID_FD && c->funcs && c->funcs->set_timeout) {
818820
c->funcs->set_timeout(c, *c->command_timeout);
819821
}
820822

0 commit comments

Comments
 (0)