diff options
author | Thomas Haller <thaller@redhat.com> | 2024-05-06 09:56:46 (GMT) |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2024-05-06 10:03:35 (GMT) |
commit | 3381acef89b218e0c55018119603c5d498880a95 (patch) | |
tree | 98cfa47e21ce959b1cae71caf1b7b827ee97dc2d | |
parent | 32cb9f392c77aa4b8ea0a05f6876021a4816814d (diff) | |
download | libnl-3381acef89b218e0c55018119603c5d498880a95.zip libnl-3381acef89b218e0c55018119603c5d498880a95.tar.gz libnl-3381acef89b218e0c55018119603c5d498880a95.tar.bz2 |
cache: use cleanup attribute in nl_cache_mngr_alloc_ex()
No "goto errout".
-rw-r--r-- | include/nl-aux-core/nl-core.h | 6 | ||||
-rw-r--r-- | lib/cache_mngr.c | 32 |
2 files changed, 17 insertions, 21 deletions
diff --git a/include/nl-aux-core/nl-core.h b/include/nl-aux-core/nl-core.h index 5198296..f75df5c 100644 --- a/include/nl-aux-core/nl-core.h +++ b/include/nl-aux-core/nl-core.h @@ -44,6 +44,12 @@ void nl_socket_free(struct nl_sock *); _NL_AUTO_DEFINE_FCN_TYPED0(struct nl_sock *, _nl_auto_nl_socket_fcn, nl_socket_free); +struct nl_cache_mngr; +void nl_cache_mngr_free(struct nl_cache_mngr *mngr); +#define _nl_auto_nl_cache_mngr _nl_auto(_nl_auto_nl_cache_mngr_fcn) +_NL_AUTO_DEFINE_FCN_TYPED0(struct nl_cache_mngr *, _nl_auto_nl_cache_mngr_fcn, + nl_cache_mngr_free); + struct nl_addr *nl_addr_build(int, const void *, size_t); static inline struct nl_addr *_nl_addr_build(int family, const void *buf) diff --git a/lib/cache_mngr.c b/lib/cache_mngr.c index c62a2d8..8d8e262 100644 --- a/lib/cache_mngr.c +++ b/lib/cache_mngr.c @@ -168,7 +168,7 @@ int nl_cache_mngr_alloc(struct nl_sock *sk, int protocol, int flags, int nl_cache_mngr_alloc_ex(struct nl_sock *sk, struct nl_sock *sync_sk, int protocol, int flags, struct nl_cache_mngr **result) { - struct nl_cache_mngr *mngr; + _nl_auto_nl_cache_mngr struct nl_cache_mngr *mngr = NULL; int err; /* Catch abuse of flags */ @@ -183,19 +183,15 @@ int nl_cache_mngr_alloc_ex(struct nl_sock *sk, struct nl_sock *sync_sk, int prot mngr->cm_flags = flags; if (!sk) { - if (!(sk = nl_socket_alloc())) { - err = -NLE_NOMEM; - goto errout; - } + if (!(sk = nl_socket_alloc())) + return -NLE_NOMEM; mngr->cm_flags |= NL_ALLOCATED_SOCK; } mngr->cm_sock = sk; if(!sync_sk) { - if (!(sync_sk = nl_socket_alloc())) { - err = -NLE_NOMEM; - goto errout; - } + if (!(sync_sk = nl_socket_alloc())) + return -NLE_NOMEM; mngr->cm_flags |= NL_ALLOCATED_SYNC_SOCK; } mngr->cm_sync_sock = sync_sk; @@ -204,32 +200,26 @@ int nl_cache_mngr_alloc_ex(struct nl_sock *sk, struct nl_sock *sync_sk, int prot mngr->cm_protocol = protocol; mngr->cm_assocs = calloc(mngr->cm_nassocs, sizeof(struct nl_cache_assoc)); - if (!mngr->cm_assocs) { - err = -NLE_NOMEM; - goto errout; - } + if (!mngr->cm_assocs) + return -NLE_NOMEM; /* Required to receive async event notifications */ nl_socket_disable_seq_check(mngr->cm_sock); if ((err = nl_connect(mngr->cm_sock, protocol)) < 0) - goto errout; + return err; if ((err = nl_socket_set_nonblocking(mngr->cm_sock)) < 0) - goto errout; + return err; if ((err = nl_connect(mngr->cm_sync_sock, protocol)) < 0) - goto errout; + return err; NL_DBG(1, "Allocated cache manager %p, protocol %d, %d caches\n", mngr, protocol, mngr->cm_nassocs); - *result = mngr; + *result = _nl_steal_pointer(&mngr); return 0; - -errout: - nl_cache_mngr_free(mngr); - return err; } /** |