From 0c22b5830f59e59851f6eab65fd692de6c6c1a0c Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 19 Apr 2023 21:24:38 -0700 Subject: fixes #1610 nni_sock_open() in socket.c: use after free --- src/core/socket.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/core/socket.c') diff --git a/src/core/socket.c b/src/core/socket.c index 09535676..1e7d978e 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -1,5 +1,5 @@ // -// Copyright 2022 Staysail Systems, Inc. +// Copyright 2023 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -640,8 +640,10 @@ nni_sock_open(nni_sock **sockp, const nni_proto *proto) } nni_mtx_lock(&sock_lk); - if (nni_id_alloc(&sock_ids, &s->s_id, s) != 0) { + if ((rv = nni_id_alloc(&sock_ids, &s->s_id, s)) != 0) { + nni_mtx_unlock(&sock_lk); sock_destroy(s); + return (rv); } else { nni_list_append(&sock_list, s); s->s_sock_ops.sock_open(s->s_data); -- cgit v1.2.3-70-g09d2