[CRIU] [PATCH] cgroup: don't leak old paths when rewriting

Tycho Andersen tycho.andersen at canonical.com
Thu Mar 10 08:51:02 PST 2016


Remember to set tmp2 when allocating the new path so that we can free it
later. Also, don't leak tmp2 in the error case.

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 criu/cgroup.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/criu/cgroup.c b/criu/cgroup.c
index 9047aa5..676cd0e 100644
--- a/criu/cgroup.c
+++ b/criu/cgroup.c
@@ -1604,6 +1604,7 @@ static int rewrite_cgsets(CgroupEntry *cge, char **controllers, int n_controller
 				 */
 				if (!set_from) {
 					set_from = true;
+					tmp2 = *from;
 					/* -1 because cgns_prefix includes leading / */
 					*from = xsprintf("%s%s", to, (*from) + cg->cgns_prefix - 1);
 				}
@@ -1617,15 +1618,15 @@ static int rewrite_cgsets(CgroupEntry *cge, char **controllers, int n_controller
 							strlen(*from) + 1);
 				if (!set_from) {
 					set_from = true;
+					tmp2 = *from;
 					*from = xstrdup(to);
 				}
 			}
 
 			if (tmp2) {
+				xfree(tmp2);
 				if (!*from)
 					return -1;
-
-				xfree(tmp2);
 			}
 
 			if (!cg->path)
-- 
2.7.0



More information about the CRIU mailing list