From 1d2d1654c6f8a3b4bfd6afeb9ea2fa8e08c84be9 Mon Sep 17 00:00:00 2001 From: Susant Sahani Date: Mon, 18 Jan 2021 13:17:20 +0100 Subject: [PATCH] varlink: use hashmap_ensure_put --- src/shared/varlink.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/shared/varlink.c b/src/shared/varlink.c index c18081e438..274709abd5 100644 --- a/src/shared/varlink.c +++ b/src/shared/varlink.c @@ -2391,14 +2391,13 @@ int varlink_server_bind_method(VarlinkServer *s, const char *method, VarlinkMeth if (startswith(method, "org.varlink.service.")) return log_debug_errno(SYNTHETIC_ERRNO(EEXIST), "Cannot bind server to '%s'.", method); - if (hashmap_ensure_allocated(&s->methods, &string_hash_ops) < 0) - return log_oom_debug(); - m = strdup(method); if (!m) return log_oom_debug(); - r = hashmap_put(s->methods, m, callback); + r = hashmap_ensure_put(&s->methods, &string_hash_ops, m, callback); + if (r == -ENOMEM) + return log_oom_debug(); if (r < 0) return log_debug_errno(r, "Failed to register callback: %m"); if (r > 0)