[lxc-devel] [PATCH] fix memory leaks reported by cppcheck in src/lxc/lxc_monitor.c. Since this is a cli tool it doesn't really matter but might silence some warnings for debugging

Serge Hallyn serge.hallyn at ubuntu.com
Mon Nov 18 15:32:01 UTC 2013


Quoting S.Çağlar Onur (caglar at 10ur.org):
> Signed-off-by: S.Çağlar Onur <caglar at 10ur.org>

Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>

> ---
>  src/lxc/lxc_monitor.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/src/lxc/lxc_monitor.c b/src/lxc/lxc_monitor.c
> index 0c27723..4f56308 100644
> --- a/src/lxc/lxc_monitor.c
> +++ b/src/lxc/lxc_monitor.c
> @@ -89,8 +89,10 @@ int main(int argc, char *argv[])
>  
>  	if (regcomp(&preg, regexp, REG_NOSUB|REG_EXTENDED)) {
>  		ERROR("failed to compile the regex '%s'", my_args.name);
> +		free(regexp);
>  		return -1;
>  	}
> +	free(regexp);
>  
>  	if (my_args.lxcpath_cnt > FD_SETSIZE) {
>  		ERROR("too many paths requested, only the first %d will be monitored", FD_SETSIZE);
> @@ -104,8 +106,10 @@ int main(int argc, char *argv[])
>  		lxc_monitord_spawn(my_args.lxcpath[i]);
>  
>  		fd = lxc_monitor_open(my_args.lxcpath[i]);
> -		if (fd < 0)
> +		if (fd < 0) {
> +			regfree(&preg);
>  			return -1;
> +		}
>  		FD_SET(fd, &rfds);
>  		if (fd > nfds)
>  			nfds = fd;
> @@ -118,8 +122,10 @@ int main(int argc, char *argv[])
>  	for (;;) {
>  		memcpy(&rfds, &rfds_save, sizeof(rfds));
>  
> -		if (lxc_monitor_read_fdset(&rfds, nfds, &msg, -1) < 0)
> +		if (lxc_monitor_read_fdset(&rfds, nfds, &msg, -1) < 0) {
> +			regfree(&preg);
>  			return -1;
> +		}
>  
>  		msg.name[sizeof(msg.name)-1] = '\0';
>  		if (regexec(&preg, msg.name, 0, NULL, 0))
> -- 
> 1.8.3.2
> 
> 
> ------------------------------------------------------------------------------
> DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
> OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
> Free app hosting. Or install the open source package on any LAMP server.
> Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
> http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
> _______________________________________________
> Lxc-devel mailing list
> Lxc-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/lxc-devel




More information about the lxc-devel mailing list