diff options
author | Akira TAGOH <akira@tagoh.org> | 2021-08-25 15:52:53 +0900 |
---|---|---|
committer | Akira TAGOH <akira@tagoh.org> | 2021-08-25 15:52:53 +0900 |
commit | 57032f489b2cbe98c8e7927f4c18738869831f41 (patch) | |
tree | a80c1fefeadac2e4bb52f8e77d8d07d033de7644 /src | |
parent | c7891755cbf1fefc20fc15651373995b1e7ca06f (diff) | |
download | fontconfig-57032f489b2cbe98c8e7927f4c18738869831f41.tar.gz |
Fix a memory leak when trying to open a non-existing file
https://bugzilla.redhat.com/show_bug.cgi?id=1914716
Diffstat (limited to 'src')
-rw-r--r-- | src/fccache.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/fccache.c b/src/fccache.c index ae3b9e3..d8ffe09 100644 --- a/src/fccache.c +++ b/src/fccache.c @@ -1111,7 +1111,7 @@ FcCache * FcDirCacheLoadFile (const FcChar8 *cache_file, struct stat *file_stat) { int fd; - FcCache *cache; + FcCache *cache = NULL; struct stat my_file_stat; FcConfig *config; @@ -1121,11 +1121,13 @@ FcDirCacheLoadFile (const FcChar8 *cache_file, struct stat *file_stat) if (!config) return NULL; fd = FcDirCacheOpenFile (cache_file, file_stat); - if (fd < 0) - return NULL; - cache = FcDirCacheMapFd (config, fd, file_stat, NULL); + if (fd >= 0) + { + cache = FcDirCacheMapFd (config, fd, file_stat, NULL); + close (fd); + } FcConfigDestroy (config); - close (fd); + return cache; } |