1
1

iof/base: fix misc memory leak

as reported by Coverity with CID 1196732
Этот коммит содержится в:
Gilles Gouaillardet 2015-03-10 14:37:53 +09:00
родитель f7f7fa73dd
Коммит dc0bc756dc
2 изменённых файлов: 14 добавлений и 1 удалений

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

@ -10,7 +10,7 @@
* 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) 2009-2014 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2009-2014 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2014 Research Organization for Information Science * Copyright (c) 2014-2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved. * and Technology (RIST). All rights reserved.
* Copyright (c) 2014 Intel, Inc. All rights reserved. * Copyright (c) 2014 Intel, Inc. All rights reserved.
* $COPYRIGHT$ * $COPYRIGHT$
@ -103,6 +103,9 @@ char* opal_dirname(const char* filename)
{ {
#if defined(HAVE_DIRNAME) || OPAL_HAVE_DIRNAME #if defined(HAVE_DIRNAME) || OPAL_HAVE_DIRNAME
char* safe_tmp = strdup(filename), *result; char* safe_tmp = strdup(filename), *result;
if (NULL == safe_tmp) {
return NULL;
}
result = strdup(dirname(safe_tmp)); result = strdup(dirname(safe_tmp));
free(safe_tmp); free(safe_tmp);
return result; return result;
@ -122,6 +125,9 @@ char* opal_dirname(const char* filename)
} }
if( p != filename ) { if( p != filename ) {
char* ret = (char*)malloc( p - filename + 1 ); char* ret = (char*)malloc( p - filename + 1 );
if (NULL == ret) {
return NULL;
}
#ifdef HAVE_STRNCPY_S #ifdef HAVE_STRNCPY_S
strncpy_s( ret, (p - filename + 1), filename, p - filename ); strncpy_s( ret, (p - filename + 1), filename, p - filename );
#else #else

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

@ -12,6 +12,8 @@
* Copyright (c) 2013 Los Alamos National Security, LLC. All rights reserved. * Copyright (c) 2013 Los Alamos National Security, LLC. All rights reserved.
* Copyright (c) 2013 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2013 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2015 Intel, Inc. All rights reserved. * Copyright (c) 2015 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
@ -234,14 +236,19 @@ static int orte_iof_base_open(mca_base_open_flag_t flags)
*/ */
char *path; char *path;
path = opal_dirname(orte_output_filename); path = opal_dirname(orte_output_filename);
if (NULL == path) {
return ORTE_ERR_OUT_OF_RESOURCE;
}
if (0 != strcmp(path, orte_output_filename)) { if (0 != strcmp(path, orte_output_filename)) {
/* there is a path in this name - ensure that the directory /* there is a path in this name - ensure that the directory
* exists, and create it if not * exists, and create it if not
*/ */
if (ORTE_SUCCESS != (rc = opal_os_dirpath_create(path, S_IRWXU))) { if (ORTE_SUCCESS != (rc = opal_os_dirpath_create(path, S_IRWXU))) {
free(path);
return rc; return rc;
} }
} }
free(path);
} }
/* daemons do not need to do this as they do not write out stdout/err */ /* daemons do not need to do this as they do not write out stdout/err */