From 1d1cef76dfa9873806e87e019a4ac31d7a30085b Mon Sep 17 00:00:00 2001 From: Nathan Hjelm Date: Thu, 15 May 2014 15:59:41 +0000 Subject: [PATCH] opal: fix leaks Two leaks are fixed by this commit: - opal_dss.lookup_data_type returns an allocated string. Free it. - opal_ifaddrtokindex was leaking a struct addrinfo. Ensure that is released before returning. cmr=v1.8.2:reviewer=rhc This commit was SVN r31777. --- opal/mca/dstore/hash/dstore_hash.c | 13 +++++++++---- opal/util/if.c | 17 +++++++++++------ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/opal/mca/dstore/hash/dstore_hash.c b/opal/mca/dstore/hash/dstore_hash.c index 9e7d9b8d8f..0c71e06812 100644 --- a/opal/mca/dstore/hash/dstore_hash.c +++ b/opal/mca/dstore/hash/dstore_hash.c @@ -1,11 +1,12 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2010 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2004-2011 The University of Tennessee and The University * of Tennessee Research Foundation. All rights * reserved. - * Copyright (c) 2011-2013 Los Alamos National Security, LLC. All rights + * Copyright (c) 2011-2014 Los Alamos National Security, LLC. All rights * reserved. - * $COPYRIGHT$ + * $COPYRIGHT$ * * Additional copyrights may follow * @@ -126,11 +127,15 @@ static int store(struct opal_dstore_base_module_t *imod, * a pre-existing value */ kv = opal_dstore_base_lookup_keyval(proc_data, val->key); +#if OPAL_ENABLE_DEBUG + char *_data_type = opal_dss.lookup_data_type(val->type); OPAL_OUTPUT_VERBOSE((5, opal_dstore_base_framework.framework_output, "dstore:hash:store: %s key %s[%s] for proc %" PRIu64 "", (NULL == kv ? "storing" : "updating"), - val->key, opal_dss.lookup_data_type(val->type), id)); - + val->key, _data_type, id)); + free (_data_type); +#endif + if (NULL != kv) { opal_list_remove_item(&proc_data->data, &kv->super); OBJ_RELEASE(kv); diff --git a/opal/util/if.c b/opal/util/if.c index f24e7cd9b0..a2fe440033 100644 --- a/opal/util/if.c +++ b/opal/util/if.c @@ -1,3 +1,4 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana * University Research and Technology @@ -11,6 +12,8 @@ * All rights reserved. * Copyright (c) 2008 Sun Microsystems, Inc. All rights reserved. * Copyright (c) 2010-2013 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2014 Los Alamos National Security, LLC. All rights + * reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -264,6 +267,7 @@ int16_t opal_ifaddrtokindex(const char* if_addr) opal_if_t* intf; int error; struct addrinfo hints, *res = NULL, *r; + int if_kernel_index; size_t len; if (OPAL_SUCCESS != mca_base_framework_open(&opal_if_base_framework, 0)) { @@ -283,16 +287,15 @@ int16_t opal_ifaddrtokindex(const char* if_addr) } for (r = res; r != NULL; r = r->ai_next) { - for (intf = (opal_if_t*)opal_list_get_first(&opal_if_list); - intf != (opal_if_t*)opal_list_get_end(&opal_if_list); - intf = (opal_if_t*)opal_list_get_next(intf)) { - + OPAL_LIST_FOREACH(intf, &opal_if_list, opal_if_t) { if (AF_INET == r->ai_family && AF_INET == intf->af_family) { struct sockaddr_in ipv4; len = (r->ai_addrlen < sizeof(struct sockaddr_in)) ? r->ai_addrlen : sizeof(struct sockaddr_in); memcpy(&ipv4, r->ai_addr, len); if (opal_net_samenetwork((struct sockaddr*)&ipv4, (struct sockaddr*)&intf->if_addr, intf->if_mask)) { - return intf->if_kernel_index; + if_kernel_index = intf->if_kernel_index; + freeaddrinfo (res); + return if_kernel_index; } } #if OPAL_ENABLE_IPV6 @@ -302,7 +305,9 @@ int16_t opal_ifaddrtokindex(const char* if_addr) memcpy(&ipv6, r->ai_addr, len); if (opal_net_samenetwork((struct sockaddr*)((struct sockaddr_in6*)&intf->if_addr), (struct sockaddr*)&ipv6, intf->if_mask)) { - return intf->if_kernel_index; + if_kernel_index = intf->if_kernel_index; + freeaddrinfo (res); + return if_kernel_index; } } #endif