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
e649c803
Commit
e649c803
authored
Apr 11, 2013
by
Stéphane Graber
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
python: Fix memory management
Signed-off-by:
Stéphane Graber
<
stgraber@ubuntu.com
>
parent
75129865
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
5 deletions
+23
-5
lxc.c
src/python-lxc/lxc.c
+23
-5
No files found.
src/python-lxc/lxc.c
View file @
e649c803
/*
/*
* python-lxc: Python bindings for LXC
* python-lxc: Python bindings for LXC
*
*
* (C) Copyright Canonical Ltd. 2012
* (C) Copyright Canonical Ltd. 2012
-2013
*
*
* Authors:
* Authors:
* Stéphane Graber <stgraber@ubuntu.com>
* Stéphane Graber <stgraber@ubuntu.com>
...
@@ -43,9 +43,10 @@ convert_tuple_to_char_pointer_array(PyObject *argv) {
...
@@ -43,9 +43,10 @@ convert_tuple_to_char_pointer_array(PyObject *argv) {
PyObject
*
pyobj
=
PyTuple_GetItem
(
argv
,
i
);
PyObject
*
pyobj
=
PyTuple_GetItem
(
argv
,
i
);
char
*
str
=
NULL
;
char
*
str
=
NULL
;
PyObject
*
pystr
;
PyObject
*
pystr
=
NULL
;
if
(
!
PyUnicode_Check
(
pyobj
))
{
if
(
!
PyUnicode_Check
(
pyobj
))
{
PyErr_SetString
(
PyExc_ValueError
,
"Expected a string"
);
PyErr_SetString
(
PyExc_ValueError
,
"Expected a string"
);
free
(
result
);
return
NULL
;
return
NULL
;
}
}
...
@@ -62,6 +63,7 @@ convert_tuple_to_char_pointer_array(PyObject *argv) {
...
@@ -62,6 +63,7 @@ convert_tuple_to_char_pointer_array(PyObject *argv) {
static
void
static
void
Container_dealloc
(
Container
*
self
)
Container_dealloc
(
Container
*
self
)
{
{
lxc_container_put
(
self
->
container
);
Py_TYPE
(
self
)
->
tp_free
((
PyObject
*
)
self
);
Py_TYPE
(
self
)
->
tp_free
((
PyObject
*
)
self
);
}
}
...
@@ -190,9 +192,11 @@ Container_create(Container *self, PyObject *args, PyObject *kwds)
...
@@ -190,9 +192,11 @@ Container_create(Container *self, PyObject *args, PyObject *kwds)
}
}
if
(
self
->
container
->
create
(
self
->
container
,
template_name
,
create_args
))
{
if
(
self
->
container
->
create
(
self
->
container
,
template_name
,
create_args
))
{
free
(
create_args
);
Py_RETURN_TRUE
;
Py_RETURN_TRUE
;
}
}
free
(
create_args
);
Py_RETURN_FALSE
;
Py_RETURN_FALSE
;
}
}
...
@@ -222,6 +226,7 @@ Container_get_cgroup_item(Container *self, PyObject *args, PyObject *kwds)
...
@@ -222,6 +226,7 @@ Container_get_cgroup_item(Container *self, PyObject *args, PyObject *kwds)
static
char
*
kwlist
[]
=
{
"key"
,
NULL
};
static
char
*
kwlist
[]
=
{
"key"
,
NULL
};
char
*
key
=
NULL
;
char
*
key
=
NULL
;
int
len
=
0
;
int
len
=
0
;
PyObject
*
ret
=
NULL
;
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"s|"
,
kwlist
,
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"s|"
,
kwlist
,
&
key
))
&
key
))
...
@@ -235,10 +240,13 @@ Container_get_cgroup_item(Container *self, PyObject *args, PyObject *kwds)
...
@@ -235,10 +240,13 @@ Container_get_cgroup_item(Container *self, PyObject *args, PyObject *kwds)
char
*
value
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
len
+
1
);
char
*
value
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
len
+
1
);
if
(
self
->
container
->
get_cgroup_item
(
self
->
container
,
key
,
value
,
len
+
1
)
!=
len
)
{
if
(
self
->
container
->
get_cgroup_item
(
self
->
container
,
key
,
value
,
len
+
1
)
!=
len
)
{
free
(
value
);
Py_RETURN_FALSE
;
Py_RETURN_FALSE
;
}
}
return
PyUnicode_FromString
(
value
);
ret
=
PyUnicode_FromString
(
value
);
free
(
value
);
return
ret
;
}
}
static
PyObject
*
static
PyObject
*
...
@@ -247,6 +255,7 @@ Container_get_config_item(Container *self, PyObject *args, PyObject *kwds)
...
@@ -247,6 +255,7 @@ Container_get_config_item(Container *self, PyObject *args, PyObject *kwds)
static
char
*
kwlist
[]
=
{
"key"
,
NULL
};
static
char
*
kwlist
[]
=
{
"key"
,
NULL
};
char
*
key
=
NULL
;
char
*
key
=
NULL
;
int
len
=
0
;
int
len
=
0
;
PyObject
*
ret
=
NULL
;
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"s|"
,
kwlist
,
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"s|"
,
kwlist
,
&
key
))
&
key
))
...
@@ -260,10 +269,13 @@ Container_get_config_item(Container *self, PyObject *args, PyObject *kwds)
...
@@ -260,10 +269,13 @@ Container_get_config_item(Container *self, PyObject *args, PyObject *kwds)
char
*
value
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
len
+
1
);
char
*
value
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
len
+
1
);
if
(
self
->
container
->
get_config_item
(
self
->
container
,
key
,
value
,
len
+
1
)
!=
len
)
{
if
(
self
->
container
->
get_config_item
(
self
->
container
,
key
,
value
,
len
+
1
)
!=
len
)
{
free
(
value
);
Py_RETURN_FALSE
;
Py_RETURN_FALSE
;
}
}
return
PyUnicode_FromString
(
value
);
ret
=
PyUnicode_FromString
(
value
);
free
(
value
);
return
ret
;
}
}
static
PyObject
*
static
PyObject
*
...
@@ -278,6 +290,7 @@ Container_get_keys(Container *self, PyObject *args, PyObject *kwds)
...
@@ -278,6 +290,7 @@ Container_get_keys(Container *self, PyObject *args, PyObject *kwds)
static
char
*
kwlist
[]
=
{
"key"
,
NULL
};
static
char
*
kwlist
[]
=
{
"key"
,
NULL
};
char
*
key
=
NULL
;
char
*
key
=
NULL
;
int
len
=
0
;
int
len
=
0
;
PyObject
*
ret
=
NULL
;
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"|s"
,
kwlist
,
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"|s"
,
kwlist
,
&
key
))
&
key
))
...
@@ -291,10 +304,13 @@ Container_get_keys(Container *self, PyObject *args, PyObject *kwds)
...
@@ -291,10 +304,13 @@ Container_get_keys(Container *self, PyObject *args, PyObject *kwds)
char
*
value
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
len
+
1
);
char
*
value
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
len
+
1
);
if
(
self
->
container
->
get_keys
(
self
->
container
,
key
,
value
,
len
+
1
)
!=
len
)
{
if
(
self
->
container
->
get_keys
(
self
->
container
,
key
,
value
,
len
+
1
)
!=
len
)
{
free
(
value
);
Py_RETURN_FALSE
;
Py_RETURN_FALSE
;
}
}
return
PyUnicode_FromString
(
value
);
ret
=
PyUnicode_FromString
(
value
);
free
(
value
);
return
ret
;
}
}
static
PyObject
*
static
PyObject
*
...
@@ -427,9 +443,11 @@ Container_start(Container *self, PyObject *args, PyObject *kwds)
...
@@ -427,9 +443,11 @@ Container_start(Container *self, PyObject *args, PyObject *kwds)
self
->
container
->
want_daemonize
(
self
->
container
);
self
->
container
->
want_daemonize
(
self
->
container
);
if
(
self
->
container
->
start
(
self
->
container
,
init_useinit
,
init_args
))
{
if
(
self
->
container
->
start
(
self
->
container
,
init_useinit
,
init_args
))
{
free
(
init_args
);
Py_RETURN_TRUE
;
Py_RETURN_TRUE
;
}
}
free
(
init_args
);
Py_RETURN_FALSE
;
Py_RETURN_FALSE
;
}
}
...
...
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