config: fix valgrind leak

Submitted by Adrian Reber on July 24, 2018, 4:18 p.m.

Details

Message ID 20180724161829.24061-1-adrian@lisas.de
State Accepted
Series "config: fix valgrind leak"
Headers show

Commit Message

Adrian Reber July 24, 2018, 4:18 p.m.
From: Adrian Reber <areber@redhat.com>

Running 'criu dump -t <PID>' with a configuration file under valgrind
where <PID> does not exist, gives:

==14336== 600 bytes in 5 blocks are definitely lost in loss record 5 of 5
==14336==    at 0x4C29BC3: malloc (vg_replace_malloc.c:299)
==14336==    by 0x5D387A4: getdelim (in /usr/lib64/libc-2.17.so)
==14336==    by 0x439829: getline (stdio.h:117)
==14336==    by 0x439829: parse_config (config.c:69)
==14336==    by 0x439CB2: init_configuration.isra.1 (config.c:159)
==14336==    by 0x439F75: init_config (config.c:212)
==14336==    by 0x439F75: parse_options (config.c:487)
==14336==    by 0x42499F: main (crtools.c:140)

==14336== LEAK SUMMARY:
==14336==    definitely lost: 600 bytes in 5 blocks

With this patch:

==17892== LEAK SUMMARY:
==17892==    definitely lost: 0 bytes in 0 blocks

Signed-off-by: Adrian Reber <areber@redhat.com>
---
 criu/config.c | 2 ++
 1 file changed, 2 insertions(+)

Patch hide | download patch | download mbox

diff --git a/criu/config.c b/criu/config.c
index f3bf35b5f..a39696dc3 100644
--- a/criu/config.c
+++ b/criu/config.c
@@ -121,9 +121,11 @@  static char ** parse_config(char *filepath)
 			}
 			i++;
 		}
+		free(line);
 		line = NULL;
 	}
 
+	free(line);
 	fclose(configfile);
 	return configuration;
 }

Comments

Andrey Vagin July 24, 2018, 9:03 p.m.
Applied, thanks!

On Tue, Jul 24, 2018 at 06:18:29PM +0200, Adrian Reber wrote:
> From: Adrian Reber <areber@redhat.com>
> 
> Running 'criu dump -t <PID>' with a configuration file under valgrind
> where <PID> does not exist, gives:
> 
> ==14336== 600 bytes in 5 blocks are definitely lost in loss record 5 of 5
> ==14336==    at 0x4C29BC3: malloc (vg_replace_malloc.c:299)
> ==14336==    by 0x5D387A4: getdelim (in /usr/lib64/libc-2.17.so)
> ==14336==    by 0x439829: getline (stdio.h:117)
> ==14336==    by 0x439829: parse_config (config.c:69)
> ==14336==    by 0x439CB2: init_configuration.isra.1 (config.c:159)
> ==14336==    by 0x439F75: init_config (config.c:212)
> ==14336==    by 0x439F75: parse_options (config.c:487)
> ==14336==    by 0x42499F: main (crtools.c:140)
> 
> ==14336== LEAK SUMMARY:
> ==14336==    definitely lost: 600 bytes in 5 blocks
> 
> With this patch:
> 
> ==17892== LEAK SUMMARY:
> ==17892==    definitely lost: 0 bytes in 0 blocks
> 
> Signed-off-by: Adrian Reber <areber@redhat.com>
> ---
>  criu/config.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/criu/config.c b/criu/config.c
> index f3bf35b5f..a39696dc3 100644
> --- a/criu/config.c
> +++ b/criu/config.c
> @@ -121,9 +121,11 @@ static char ** parse_config(char *filepath)
>  			}
>  			i++;
>  		}
> +		free(line);
>  		line = NULL;
>  	}
>  
> +	free(line);
>  	fclose(configfile);
>  	return configuration;
>  }
> -- 
> 2.17.1
>