From 38bd263de5b83710898406640a77c15edea712fe Mon Sep 17 00:00:00 2001 From: Petr Cech Date: Thu, 18 Feb 2016 06:33:53 -0500 Subject: [PATCH 75/86] TOOLS: Fix memory leak after getline() failed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch fixes buffer freeing in case if getline() failed in function sss_colondb_readline(). ssize_t getline(char **lineptr, size_t *n, FILE *stream); If *lineptr is set to NULL and *n is set 0 before the call, then getline() will allocate a buffer for storing the line. This buffer should be freed by the user program even if getline() failed. man 3 getline This patch fix buffer freeing in case if getline() failed. Resolves: https://fedorahosted.org/sssd/ticket/2764 Reviewed-by: Lukáš Slebodník (cherry picked from commit 2dd75ea79a57615808754c0ce550786edbc17d69) (cherry picked from commit 34ba0c53d0d966c64ea11a6269cdd0ad985f4068) --- src/tools/common/sss_colondb.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/tools/common/sss_colondb.c b/src/tools/common/sss_colondb.c index b9af5f7e50c1166ca518a4e342637dc62518c567..e8aeb315c9ed0efde15553e2d741d04c5d895b1a 100644 --- a/src/tools/common/sss_colondb.c +++ b/src/tools/common/sss_colondb.c @@ -121,6 +121,10 @@ errno_t sss_colondb_readline(TALLOC_CTX *mem_ctx, readchars = getline(&line, &linelen, db->file); if (readchars == -1) { /* Nothing was read. */ + + free(line); + line = NULL; + if (errno != 0) { ret = errno; DEBUG(SSSDBG_CRIT_FAILURE, "Unable to read line [%d]: %s\n", -- 2.5.0