From f6bf4ab16437ab0aec6202d5f2bb6daef35adec4 Mon Sep 17 00:00:00 2001 From: Chris Desjardins Date: Wed, 8 Feb 2023 12:59:00 +0100 Subject: [PATCH] Do not call lfs_free if the buffer to free is NULL This can happen if lfs_malloc fails, or if the file doesn't exist, all "goto cleanup" clauses before and including the the lfs_malloc will cause this. --- lfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lfs.c b/lfs.c index 26280fa8..fa822a0b 100644 --- a/lfs.c +++ b/lfs.c @@ -3014,7 +3014,7 @@ static int lfs_file_rawclose(lfs_t *lfs, lfs_file_t *file) { lfs_mlist_remove(lfs, (struct lfs_mlist*)file); // clean up memory - if (!file->cfg->buffer) { + if ((!file->cfg->buffer) && (file->cache.buffer)) { lfs_free(file->cache.buffer); }