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
680836fa
Commit
680836fa
authored
Jun 21, 2015
by
Henrik Kjölhede
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure to cleanup and exit with an error if malloc fails in append_alloted
Signed-off-by:
Henrik Kjölhede
<
hkjolhede@gmail.com
>
parent
21002b39
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
1 deletion
+9
-1
lxc_user_nic.c
src/lxc/lxc_user_nic.c
+9
-1
No files found.
src/lxc/lxc_user_nic.c
View file @
680836fa
...
@@ -194,6 +194,7 @@ static struct alloted_s *append_alloted(struct alloted_s **head, char *name, int
...
@@ -194,6 +194,7 @@ static struct alloted_s *append_alloted(struct alloted_s **head, char *name, int
if
(
head
==
NULL
||
name
==
NULL
)
{
if
(
head
==
NULL
||
name
==
NULL
)
{
// sanity check. parameters should not be null
// sanity check. parameters should not be null
fprintf
(
stderr
,
"NULL parameters to append_alloted not allowed
\n
"
);
return
NULL
;
return
NULL
;
}
}
...
@@ -201,6 +202,7 @@ static struct alloted_s *append_alloted(struct alloted_s **head, char *name, int
...
@@ -201,6 +202,7 @@ static struct alloted_s *append_alloted(struct alloted_s **head, char *name, int
if
(
al
==
NULL
)
{
if
(
al
==
NULL
)
{
// unable to allocate memory to new struct
// unable to allocate memory to new struct
fprintf
(
stderr
,
"Out of memory in append_alloted
\n
"
);
return
NULL
;
return
NULL
;
}
}
...
@@ -294,8 +296,14 @@ static int get_alloted(char *me, char *intype, char *link, struct alloted_s **al
...
@@ -294,8 +296,14 @@ static int get_alloted(char *me, char *intype, char *link, struct alloted_s **al
/* found the user or group with the appropriate settings, therefore finish the search.
/* found the user or group with the appropriate settings, therefore finish the search.
* what to do if there are more than one applicable lines? not specified in the docs.
* what to do if there are more than one applicable lines? not specified in the docs.
* since getline is implemented with realloc, we don't need to free line until exiting func.
* since getline is implemented with realloc, we don't need to free line until exiting func.
*
* if append_alloted returns NULL, e.g. due to a malloc error, we set count to 0 and break the loop,
* allowing cleanup and then exiting from main()
*/
*/
append_alloted
(
alloted
,
name
,
n
);
if
(
append_alloted
(
alloted
,
name
,
n
)
==
NULL
)
{
count
=
0
;
break
;
}
count
+=
n
;
count
+=
n
;
}
}
...
...
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