1
1

opal/util: fix misc memory leaks reported by Coverity

fixes CID 996174, 996920, 1196735, 1196769 and 1196770
Этот коммит содержится в:
Gilles Gouaillardet 2015-02-13 14:28:59 +09:00
родитель b68e1cd579
Коммит ca3a275823
3 изменённых файлов: 31 добавлений и 21 удалений

Просмотреть файл

@ -10,6 +10,8 @@
* Copyright (c) 2004-2005 The Regents of the University of California. * Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved. * All rights reserved.
* Copyright (c) 2008 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2008 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -244,18 +246,17 @@ static int find_topic(const char *base, const char *topic)
*/ */
static int read_topic(char ***array) static int read_topic(char ***array)
{ {
char *tmp; int token, rc;
int token;
while (1) { while (1) {
token = opal_show_help_yylex(); token = opal_show_help_yylex();
switch (token) { switch (token) {
case OPAL_SHOW_HELP_PARSE_MESSAGE: case OPAL_SHOW_HELP_PARSE_MESSAGE:
tmp = strdup(opal_show_help_yytext); /* opal_argv_append_nosize does strdup(opal_show_help_yytext) */
if (NULL == tmp) { rc = opal_argv_append_nosize(array, opal_show_help_yytext);
return OPAL_ERR_OUT_OF_RESOURCE; if (rc != OPAL_SUCCESS) {
return rc;
} }
opal_argv_append_nosize(array, tmp);
break; break;
default: default:

Просмотреть файл

@ -13,6 +13,8 @@
* Copyright (c) 2013 Los Alamos National Security, LLC. * Copyright (c) 2013 Los Alamos National Security, LLC.
* All rights reserved. * All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved. * Copyright (c) 2014 Intel, Inc. All rights reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -107,7 +109,7 @@ static int opal_setlimit(int resource, char *value, rlim_t *out)
int opal_util_init_sys_limits(char **errmsg) int opal_util_init_sys_limits(char **errmsg)
{ {
char **lims, **lim=NULL, *setlim; char **lims, **lim=NULL, *setlim;
int i; int i, rc = OPAL_ERROR;
rlim_t value; rlim_t value;
/* if limits were not given, then nothing to do */ /* if limits were not given, then nothing to do */
@ -136,14 +138,14 @@ int opal_util_init_sys_limits(char **errmsg)
if (OPAL_SUCCESS != if (OPAL_SUCCESS !=
opal_setlimit(RLIMIT_NOFILE, "max", &value)) { opal_setlimit(RLIMIT_NOFILE, "max", &value)) {
*errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "openfiles", "max"); *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "openfiles", "max");
return OPAL_ERROR; goto out;
} }
opal_sys_limits.num_files = value; opal_sys_limits.num_files = value;
#endif #endif
#if HAVE_DECL_RLIMIT_NPROC #if HAVE_DECL_RLIMIT_NPROC
if (OPAL_SUCCESS != opal_setlimit(RLIMIT_NPROC, "max", &value)) { if (OPAL_SUCCESS != opal_setlimit(RLIMIT_NPROC, "max", &value)) {
*errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "maxchildren", "max"); *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "maxchildren", "max");
return OPAL_ERROR; goto out;
} }
opal_sys_limits.num_procs = value; opal_sys_limits.num_procs = value;
#endif #endif
@ -151,7 +153,7 @@ int opal_util_init_sys_limits(char **errmsg)
if (OPAL_SUCCESS != if (OPAL_SUCCESS !=
opal_setlimit(RLIMIT_FSIZE, "max", &value)) { opal_setlimit(RLIMIT_FSIZE, "max", &value)) {
*errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "filesize", "max"); *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "filesize", "max");
return OPAL_ERROR; goto out;
} }
opal_sys_limits.file_size = value; opal_sys_limits.file_size = value;
#endif #endif
@ -166,14 +168,14 @@ int opal_util_init_sys_limits(char **errmsg)
#if HAVE_DECL_RLIMIT_CORE #if HAVE_DECL_RLIMIT_CORE
if (OPAL_SUCCESS != opal_setlimit(RLIMIT_CORE, setlim, &value)) { if (OPAL_SUCCESS != opal_setlimit(RLIMIT_CORE, setlim, &value)) {
*errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "openfiles", setlim); *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "openfiles", setlim);
return OPAL_ERROR; goto out;
} }
#endif #endif
} else if (0 == strcmp(lim[0], "filesize")) { } else if (0 == strcmp(lim[0], "filesize")) {
#if HAVE_DECL_RLIMIT_FSIZE #if HAVE_DECL_RLIMIT_FSIZE
if (OPAL_SUCCESS != opal_setlimit(RLIMIT_FSIZE, setlim, &value)) { if (OPAL_SUCCESS != opal_setlimit(RLIMIT_FSIZE, setlim, &value)) {
*errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "filesize", setlim); *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "filesize", setlim);
return OPAL_ERROR; goto out;
} }
opal_sys_limits.file_size = value; opal_sys_limits.file_size = value;
#endif #endif
@ -181,14 +183,14 @@ int opal_util_init_sys_limits(char **errmsg)
#if HAVE_DECL_RLIMIT_AS #if HAVE_DECL_RLIMIT_AS
if (OPAL_SUCCESS != opal_setlimit(RLIMIT_AS, setlim, &value)) { if (OPAL_SUCCESS != opal_setlimit(RLIMIT_AS, setlim, &value)) {
*errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "maxmem", setlim); *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "maxmem", setlim);
return OPAL_ERROR; goto out;
} }
#endif #endif
} else if (0 == strcmp(lim[0], "openfiles")) { } else if (0 == strcmp(lim[0], "openfiles")) {
#if HAVE_DECL_RLIMIT_NOFILE #if HAVE_DECL_RLIMIT_NOFILE
if (OPAL_SUCCESS != opal_setlimit(RLIMIT_NOFILE, setlim, &value)) { if (OPAL_SUCCESS != opal_setlimit(RLIMIT_NOFILE, setlim, &value)) {
*errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "openfiles", setlim); *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "openfiles", setlim);
return OPAL_ERROR; goto out;
} }
opal_sys_limits.num_files = value; opal_sys_limits.num_files = value;
#endif #endif
@ -196,23 +198,29 @@ int opal_util_init_sys_limits(char **errmsg)
#if HAVE_DECL_RLIMIT_STACK #if HAVE_DECL_RLIMIT_STACK
if (OPAL_SUCCESS != opal_setlimit(RLIMIT_STACK, setlim, &value)) { if (OPAL_SUCCESS != opal_setlimit(RLIMIT_STACK, setlim, &value)) {
*errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "stacksize", setlim); *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "stacksize", setlim);
return OPAL_ERROR; goto out;
} }
#endif #endif
} else if (0 == strcmp(lim[0], "maxchildren")) { } else if (0 == strcmp(lim[0], "maxchildren")) {
#if HAVE_DECL_RLIMIT_NPROC #if HAVE_DECL_RLIMIT_NPROC
if (OPAL_SUCCESS != opal_setlimit(RLIMIT_NPROC, setlim, &value)) { if (OPAL_SUCCESS != opal_setlimit(RLIMIT_NPROC, setlim, &value)) {
*errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "maxchildren", setlim); *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-failed", true, "maxchildren", setlim);
return OPAL_ERROR; goto out;
} }
opal_sys_limits.num_procs = value; opal_sys_limits.num_procs = value;
#endif #endif
} else { } else {
*errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-unrecognized", true, lim[0], setlim); *errmsg = opal_show_help_string("help-opal-util.txt", "sys-limit-unrecognized", true, lim[0], setlim);
return OPAL_ERROR; goto out;
} }
} }
/* indicate we initialized the limits structure */
opal_sys_limits.initialized = true;
rc = OPAL_SUCCESS;
out:
if (NULL != lim) { if (NULL != lim) {
opal_argv_free(lim); opal_argv_free(lim);
} }
@ -220,10 +228,7 @@ int opal_util_init_sys_limits(char **errmsg)
opal_argv_free(lims); opal_argv_free(lims);
} }
/* indicate we initialized the limits structure */ return rc;
opal_sys_limits.initialized = true;
return OPAL_SUCCESS;
} }
int opal_getpagesize(void) int opal_getpagesize(void)

Просмотреть файл

@ -1,6 +1,8 @@
/* /*
* Copyright (c) 2012 Los Alamos National Security, LLC. * Copyright (c) 2012 Los Alamos National Security, LLC.
* All rights reserved. * All rights reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
* *
* Additional copyrights may follow * Additional copyrights may follow
@ -33,6 +35,7 @@ char *opal_uri_get_scheme(const char *uri)
if (NULL == (ptr = strchr(turi, ':'))) { if (NULL == (ptr = strchr(turi, ':'))) {
opal_show_help("help-opal-util.txt", "malformed-uri", opal_show_help("help-opal-util.txt", "malformed-uri",
true, uri); true, uri);
free(turi);
return NULL; return NULL;
} }
*ptr = '\0'; *ptr = '\0';
@ -117,6 +120,7 @@ char *opal_filename_from_uri(const char *uri,
if (NULL == (ptr = strchr(turi, ':'))) { if (NULL == (ptr = strchr(turi, ':'))) {
opal_show_help("help-opal-util.txt", "malformed-uri", opal_show_help("help-opal-util.txt", "malformed-uri",
true, uri); true, uri);
free(turi);
return NULL; return NULL;
} }
*ptr = '\0'; *ptr = '\0';