From 1d42b3ea7ebe64c02a156043e2b3adc92458daac Mon Sep 17 00:00:00 2001 From: Alfred Klomp Date: Mon, 14 Jul 2014 22:09:21 +0200 Subject: [PATCH] pem2der.c: fix double-free bug Found with Clang's `scan-build` tool. load_file() allocates memory to a char** parameter. It then tries to fread() a file, and if that fails, frees the memory and returns to caller. However, the char** is not reset to NULL, which causes a double-free error when the caller later passes it to free(). --- programs/util/pem2der.c | 1 + 1 file changed, 1 insertion(+) diff --git a/programs/util/pem2der.c b/programs/util/pem2der.c index 5386fdb9c..dfd7a4966 100644 --- a/programs/util/pem2der.c +++ b/programs/util/pem2der.c @@ -134,6 +134,7 @@ static int load_file( const char *path, unsigned char **buf, size_t *n ) { fclose( f ); free( *buf ); + *buf = NULL; return( -1 ); }