From 1134de3c89c5a07699365031d0cb88383e365929 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Mon, 10 Aug 2015 10:08:03 +0100 Subject: [PATCH] libdm: fix FILE leak in _program_id_from_proc() (Coverity) Make sure comm is closed in the error path of _program_id_from_proc(). libdm/libdm-stats.c: 98 in dm_stats_create() - Variable "comm" going out of scope leaks the storage it points to. --- libdm/libdm-stats.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libdm/libdm-stats.c b/libdm/libdm-stats.c index bf3cad0e0..64ca23f57 100644 --- a/libdm/libdm-stats.c +++ b/libdm/libdm-stats.c @@ -79,11 +79,13 @@ static char *_program_id_from_proc(void) if (!(comm = fopen(PROC_SELF_COMM, "r"))) return_NULL; - if (!fgets(buf, sizeof(buf), comm)) - return_NULL; + if (!fgets(buf, sizeof(buf), comm)) { + log_error("Could not read from %s", PROC_SELF_COMM); + fclose(comm); + return NULL; + } - if (fclose(comm)) - return_NULL; + fclose(comm); return dm_strdup(buf); }