From e16da663a1dab3918adf8b0f10e7d740a393312c Mon Sep 17 00:00:00 2001 From: Martijn van Brummelen Date: Fri, 5 Oct 2018 22:58:58 +0200 Subject: [PATCH] fix more memory leaks --- src/method.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/method.c b/src/method.c index fed21d1..03a523f 100644 --- a/src/method.c +++ b/src/method.c @@ -421,6 +421,7 @@ void *nwipe_ops2( void *ptr ) nwipe_perror( errno, __FUNCTION__, "malloc" ); nwipe_log( NWIPE_LOG_FATAL, "Unable to allocate the complement character array." ); c->result = -1; + free(s); return NULL; } @@ -436,6 +437,8 @@ void *nwipe_ops2( void *ptr ) nwipe_perror( errno, __FUNCTION__, "malloc" ); nwipe_log( NWIPE_LOG_FATAL, "Unable to allocate the pattern array." ); c->result = -1; + free(s); + free(t); return NULL; } @@ -448,10 +451,24 @@ void *nwipe_ops2( void *ptr ) r = errno; nwipe_perror( r, __FUNCTION__, "read" ); nwipe_log( NWIPE_LOG_FATAL, "Unable to seed the %s method.", nwipe_ops2_label ); - - /* Ensure a negative return. */ - if( r < 0 ) { c->result = r; return NULL; } - else { c->result = -1; return NULL; } + + if( r < 0 ) + { + c->result = r; + free(s); + free(t); + free(patterns); + return NULL; + } + else + { + c->result = -1; + free(s); + free(t); + free(patterns); + return NULL; + } + }