fs/base: fix misc memory leak
as reported by Coverity with CID 72202
Этот коммит содержится в:
родитель
9f13425980
Коммит
e75b1e6435
@ -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-2011 University of Houston. All rights reserved.
|
* Copyright (c) 2008-2011 University of Houston. 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
|
||||||
@ -64,9 +66,8 @@ void mca_fs_base_get_parent_dir ( char *filename, char **dirnamep)
|
|||||||
* or not.
|
* or not.
|
||||||
*/
|
*/
|
||||||
int namelen;
|
int namelen;
|
||||||
char *linkbuf;
|
char linkbuf[PATH_MAX+1];
|
||||||
|
|
||||||
linkbuf = malloc(PATH_MAX+1);
|
|
||||||
namelen = readlink(filename, linkbuf, PATH_MAX+1);
|
namelen = readlink(filename, linkbuf, PATH_MAX+1);
|
||||||
if (namelen == -1) {
|
if (namelen == -1) {
|
||||||
/* something strange has happened between the time that
|
/* something strange has happened between the time that
|
||||||
@ -79,7 +80,6 @@ void mca_fs_base_get_parent_dir ( char *filename, char **dirnamep)
|
|||||||
/* successfully read the link */
|
/* successfully read the link */
|
||||||
linkbuf[namelen] = '\0'; /* readlink doesn't null terminate */
|
linkbuf[namelen] = '\0'; /* readlink doesn't null terminate */
|
||||||
dir = strdup(linkbuf);
|
dir = strdup(linkbuf);
|
||||||
free(linkbuf);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user