Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
44b9ae4b
Unverified
Commit
44b9ae4b
authored
Feb 19, 2014
by
Stéphane Graber
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rundir: Fix memory leaks
Signed-off-by:
Stéphane Graber
<
stgraber@ubuntu.com
>
parent
0130df54
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
13 deletions
+27
-13
lxclock.c
src/lxc/lxclock.c
+9
-2
monitor.c
src/lxc/monitor.c
+5
-1
utils.c
src/lxc/utils.c
+13
-10
No files found.
src/lxc/lxclock.c
View file @
44b9ae4b
...
...
@@ -98,7 +98,7 @@ static char *lxclock_name(const char *p, const char *n)
int
ret
;
int
len
;
char
*
dest
;
c
onst
c
har
*
rundir
;
char
*
rundir
;
/* lockfile will be:
* "/run" + "/lock/lxc/$lxcpath/$lxcname + '\0' if root
...
...
@@ -113,12 +113,15 @@ static char *lxclock_name(const char *p, const char *n)
return
NULL
;
len
+=
strlen
(
rundir
);
if
((
dest
=
malloc
(
len
))
==
NULL
)
if
((
dest
=
malloc
(
len
))
==
NULL
)
{
free
(
rundir
);
return
NULL
;
}
ret
=
snprintf
(
dest
,
len
,
"%s/lock/lxc/%s"
,
rundir
,
p
);
if
(
ret
<
0
||
ret
>=
len
)
{
free
(
dest
);
free
(
rundir
);
return
NULL
;
}
ret
=
mkdir_p
(
dest
,
0755
);
...
...
@@ -130,6 +133,7 @@ static char *lxclock_name(const char *p, const char *n)
d
=
realloc
(
dest
,
l2
);
if
(
!
d
)
{
free
(
dest
);
free
(
rundir
);
return
NULL
;
}
len
=
l2
;
...
...
@@ -138,12 +142,15 @@ static char *lxclock_name(const char *p, const char *n)
ret
=
snprintf
(
dest
,
len
,
"/tmp/%d/lxc/%s"
,
geteuid
(),
p
);
if
(
ret
<
0
||
ret
>=
len
)
{
free
(
dest
);
free
(
rundir
);
return
NULL
;
}
ret
=
snprintf
(
dest
,
len
,
"/tmp/%d/lxc/%s/%s"
,
geteuid
(),
p
,
n
);
}
else
ret
=
snprintf
(
dest
,
len
,
"%s/lock/lxc/%s/%s"
,
rundir
,
p
,
n
);
free
(
rundir
);
if
(
ret
<
0
||
ret
>=
len
)
{
free
(
dest
);
return
NULL
;
...
...
src/lxc/monitor.c
View file @
44b9ae4b
...
...
@@ -54,7 +54,7 @@ int lxc_monitor_fifo_name(const char *lxcpath, char *fifo_path, size_t fifo_path
int
do_mkdirp
)
{
int
ret
;
c
onst
c
har
*
rundir
;
char
*
rundir
;
rundir
=
get_rundir
();
if
(
!
rundir
)
...
...
@@ -64,19 +64,23 @@ int lxc_monitor_fifo_name(const char *lxcpath, char *fifo_path, size_t fifo_path
ret
=
snprintf
(
fifo_path
,
fifo_path_sz
,
"%s/lxc/%s"
,
rundir
,
lxcpath
);
if
(
ret
<
0
||
ret
>=
fifo_path_sz
)
{
ERROR
(
"rundir/lxcpath (%s/%s) too long for monitor fifo"
,
rundir
,
lxcpath
);
free
(
rundir
);
return
-
1
;
}
ret
=
mkdir_p
(
fifo_path
,
0755
);
if
(
ret
<
0
)
{
ERROR
(
"unable to create monitor fifo dir %s"
,
fifo_path
);
free
(
rundir
);
return
ret
;
}
}
ret
=
snprintf
(
fifo_path
,
fifo_path_sz
,
"%s/lxc/%s/monitor-fifo"
,
rundir
,
lxcpath
);
if
(
ret
<
0
||
ret
>=
fifo_path_sz
)
{
ERROR
(
"rundir/lxcpath (%s/%s) too long for monitor fifo"
,
rundir
,
lxcpath
);
free
(
rundir
);
return
-
1
;
}
free
(
rundir
);
return
0
;
}
...
...
src/lxc/utils.c
View file @
44b9ae4b
...
...
@@ -376,7 +376,7 @@ out:
return
values
[
i
];
}
c
onst
c
har
*
get_rundir
()
char
*
get_rundir
()
{
char
*
rundir
;
const
char
*
homedir
;
...
...
@@ -387,18 +387,21 @@ const char *get_rundir()
}
rundir
=
getenv
(
"XDG_RUNTIME_DIR"
);
if
(
!
rundir
)
{
INFO
(
"XDG_RUNTIME_DIR isn't set in the environment."
);
homedir
=
getenv
(
"HOME"
);
if
(
!
homedir
)
{
ERROR
(
"HOME isn't set in the environment."
);
return
NULL
;
}
if
(
rundir
)
{
rundir
=
strdup
(
rundir
);
return
rundir
;
}
rundir
=
malloc
(
sizeof
(
char
)
*
(
17
+
strlen
(
homedir
)));
sprintf
(
rundir
,
"%s/.cache/lxc/run/"
,
homedir
);
INFO
(
"XDG_RUNTIME_DIR isn't set in the environment."
);
homedir
=
getenv
(
"HOME"
);
if
(
!
homedir
)
{
ERROR
(
"HOME isn't set in the environment."
);
return
NULL
;
}
rundir
=
malloc
(
sizeof
(
char
)
*
(
17
+
strlen
(
homedir
)));
sprintf
(
rundir
,
"%s/.cache/lxc/run/"
,
homedir
);
return
rundir
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment