Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
steam
systemd
Commits
ef42202a
Commit
ef42202a
authored
Apr 22, 2013
by
Zbigniew Jędrzejewski-Szmek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add set_consume which always takes ownership
Freeing in error path is the common pattern with set_put().
parent
c79bb9e4
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
40 additions
and
59 deletions
+40
-59
src/core/dbus-manager.c
src/core/dbus-manager.c
+2
-4
src/core/load-fragment.c
src/core/load-fragment.c
+2
-4
src/core/manager.c
src/core/manager.c
+2
-4
src/core/mount-setup.c
src/core/mount-setup.c
+1
-2
src/journal/coredumpctl.c
src/journal/coredumpctl.c
+5
-7
src/libsystemd-bus/sd-bus.c
src/libsystemd-bus/sd-bus.c
+3
-7
src/locale/localectl.c
src/locale/localectl.c
+7
-15
src/readahead/readahead-collect.c
src/readahead/readahead-collect.c
+3
-2
src/shared/install.c
src/shared/install.c
+2
-4
src/shared/set.c
src/shared/set.c
+7
-0
src/shared/set.h
src/shared/set.h
+1
-0
src/systemctl/systemctl.c
src/systemctl/systemctl.c
+1
-2
src/test/test-prioq.c
src/test/test-prioq.c
+1
-1
src/tmpfiles/tmpfiles.c
src/tmpfiles/tmpfiles.c
+3
-7
No files found.
src/core/dbus-manager.c
View file @
ef42202a
...
...
@@ -1186,11 +1186,9 @@ static DBusHandlerResult bus_manager_message_handler(DBusConnection *connection,
if
(
!
client
)
goto
oom
;
r
=
set_put
(
s
,
client
);
if
(
r
<
0
)
{
free
(
client
);
r
=
set_consume
(
s
,
client
);
if
(
r
<
0
)
return
bus_send_error_reply
(
connection
,
message
,
NULL
,
r
);
}
reply
=
dbus_message_new_method_return
(
message
);
if
(
!
reply
)
...
...
src/core/load-fragment.c
View file @
ef42202a
...
...
@@ -2095,11 +2095,9 @@ static int open_follow(char **filename, FILE **_f, Set *names, char **_final) {
if
(
!
id
)
return
-
ENOMEM
;
r
=
set_put
(
names
,
id
);
if
(
r
<
0
)
{
free
(
id
);
r
=
set_consume
(
names
,
id
);
if
(
r
<
0
)
return
r
;
}
}
}
...
...
src/core/manager.c
View file @
ef42202a
...
...
@@ -806,11 +806,9 @@ static void manager_build_unit_path_cache(Manager *m) {
goto
fail
;
}
r
=
set_put
(
m
->
unit_path_cache
,
p
);
if
(
r
<
0
)
{
free
(
p
);
r
=
set_consume
(
m
->
unit_path_cache
,
p
);
if
(
r
<
0
)
goto
fail
;
}
}
closedir
(
d
);
...
...
src/core/mount-setup.c
View file @
ef42202a
...
...
@@ -251,10 +251,9 @@ int mount_cgroup_controllers(char ***join_controllers) {
continue
;
}
r
=
set_
put
(
controllers
,
controller
);
r
=
set_
consume
(
controllers
,
controller
);
if
(
r
<
0
)
{
log_error
(
"Failed to add controller to set."
);
free
(
controller
);
goto
finish
;
}
}
...
...
src/journal/coredumpctl.c
View file @
ef42202a
...
...
@@ -68,10 +68,9 @@ static Set *new_matches(void) {
return
NULL
;
}
r
=
set_
put
(
set
,
tmp
);
r
=
set_
consume
(
set
,
tmp
);
if
(
r
<
0
)
{
log_error
(
"failed to add to set: %s"
,
strerror
(
-
r
));
free
(
tmp
);
set_free
(
set
);
return
NULL
;
}
...
...
@@ -125,18 +124,17 @@ static int add_match(Set *set, const char *match) {
if
(
!
pattern
)
goto
fail
;
r
=
set_put
(
set
,
pattern
);
log_debug
(
"Adding pattern: %s"
,
pattern
);
r
=
set_consume
(
set
,
pattern
);
if
(
r
<
0
)
{
log_error
(
"
f
ailed to add pattern '%s': %s"
,
log_error
(
"
F
ailed to add pattern '%s': %s"
,
pattern
,
strerror
(
-
r
));
goto
fail
;
}
log_debug
(
"Added pattern: %s"
,
pattern
);
return
0
;
fail:
free
(
pattern
);
log_error
(
"failed to add match: %s"
,
strerror
(
-
r
));
log_error
(
"Failed to add match: %s"
,
strerror
(
-
r
));
return
r
;
}
...
...
src/libsystemd-bus/sd-bus.c
View file @
ef42202a
...
...
@@ -1841,13 +1841,9 @@ static int process_introspect(sd_bus *bus, sd_bus_message *m) {
if
(
p
)
*
p
=
0
;
r
=
set_put
(
s
,
a
);
if
(
r
<
0
)
{
free
(
a
);
if
(
r
!=
-
EEXIST
)
return
r
;
}
r
=
set_consume
(
s
,
a
);
if
(
r
<
0
&&
r
!=
-
EEXIST
)
return
r
;
}
f
=
open_memstream
(
&
introspection
,
&
size
);
...
...
src/locale/localectl.c
View file @
ef42202a
...
...
@@ -369,9 +369,8 @@ static int add_locales_from_archive(Set *locales) {
goto
finish
;
}
r
=
set_
put
(
locales
,
z
);
r
=
set_
consume
(
locales
,
z
);
if
(
r
<
0
)
{
free
(
z
);
log_error
(
"Failed to add locale: %s"
,
strerror
(
-
r
));
goto
finish
;
}
...
...
@@ -411,14 +410,10 @@ static int add_locales_from_libdir (Set *locales) {
if
(
!
z
)
return
log_oom
();
r
=
set_put
(
locales
,
z
);
if
(
r
<
0
)
{
free
(
z
);
if
(
r
!=
-
EEXIST
)
{
log_error
(
"Failed to add locale: %s"
,
strerror
(
-
r
));
return
r
;
}
r
=
set_consume
(
locales
,
z
);
if
(
r
<
0
&&
r
!=
-
EEXIST
)
{
log_error
(
"Failed to add locale: %s"
,
strerror
(
-
r
));
return
r
;
}
errno
=
0
;
...
...
@@ -526,12 +521,9 @@ static int nftw_cb(
if
(
e
)
*
e
=
0
;
r
=
set_put
(
keymaps
,
p
);
if
(
r
==
-
EEXIST
)
free
(
p
);
else
if
(
r
<
0
)
{
r
=
set_consume
(
keymaps
,
p
);
if
(
r
<
0
&&
r
!=
-
EEXIST
)
{
log_error
(
"Can't add keymap: %s"
,
strerror
(
-
r
));
free
(
p
);
return
r
;
}
...
...
src/readahead/readahead-collect.c
View file @
ef42202a
...
...
@@ -479,8 +479,9 @@ static int collect(const char *root) {
}
entry
->
bin
=
(
entrytime
-
starttime
)
/
2000000
;
if
((
k
=
hashmap_put
(
files
,
p
,
entry
))
<
0
)
{
log_warning
(
"set_put() failed: %s"
,
strerror
(
-
k
));
k
=
hashmap_put
(
files
,
p
,
entry
);
if
(
k
<
0
)
{
log_warning
(
"hashmap_put() failed: %s"
,
strerror
(
-
k
));
free
(
p
);
}
}
...
...
src/shared/install.c
View file @
ef42202a
...
...
@@ -178,11 +178,9 @@ static int mark_symlink_for_removal(
path_kill_slashes
(
n
);
r
=
set_put
(
*
remove_symlinks_to
,
n
);
if
(
r
<
0
)
{
free
(
n
);
r
=
set_consume
(
*
remove_symlinks_to
,
n
);
if
(
r
<
0
)
return
r
==
-
EEXIST
?
0
:
r
;
}
return
0
;
}
...
...
src/shared/set.c
View file @
ef42202a
...
...
@@ -49,6 +49,13 @@ int set_put(Set *s, void *value) {
return
hashmap_put
(
MAKE_HASHMAP
(
s
),
value
,
value
);
}
int
set_consume
(
Set
*
s
,
void
*
value
)
{
int
r
=
set_put
(
s
,
value
);
if
(
r
<
0
)
free
(
value
);
return
r
;
}
int
set_replace
(
Set
*
s
,
void
*
value
)
{
return
hashmap_replace
(
MAKE_HASHMAP
(
s
),
value
,
value
);
}
...
...
src/shared/set.h
View file @
ef42202a
...
...
@@ -46,6 +46,7 @@ Set* set_copy(Set *s);
int
set_ensure_allocated
(
Set
**
s
,
hash_func_t
hash_func
,
compare_func_t
compare_func
);
int
set_put
(
Set
*
s
,
void
*
value
);
int
set_consume
(
Set
*
s
,
void
*
value
);
int
set_replace
(
Set
*
s
,
void
*
value
);
void
*
set_get
(
Set
*
s
,
void
*
value
);
bool
set_contains
(
Set
*
s
,
void
*
value
);
...
...
src/systemctl/systemctl.c
View file @
ef42202a
...
...
@@ -1843,9 +1843,8 @@ static int start_unit_one(
if
(
!
p
)
return
log_oom
();
r
=
set_
put
(
s
,
p
);
r
=
set_
consume
(
s
,
p
);
if
(
r
<
0
)
{
free
(
p
);
log_error
(
"Failed to add path to set."
);
return
r
;
}
...
...
src/test/test-prioq.c
View file @
ef42202a
...
...
@@ -119,7 +119,7 @@ static void test_struct(void) {
assert_se
(
r
>=
0
);
if
(
i
%
4
==
0
)
{
r
=
set_
put
(
s
,
t
);
r
=
set_
consume
(
s
,
t
);
assert_se
(
r
>=
0
);
}
}
...
...
src/tmpfiles/tmpfiles.c
View file @
ef42202a
...
...
@@ -186,13 +186,9 @@ static void load_unix_sockets(void) {
path_kill_slashes
(
s
);
k
=
set_put
(
unix_sockets
,
s
);
if
(
k
<
0
)
{
free
(
s
);
if
(
k
!=
-
EEXIST
)
goto
fail
;
}
k
=
set_consume
(
unix_sockets
,
s
);
if
(
k
<
0
&&
k
!=
-
EEXIST
)
goto
fail
;
}
return
;
...
...
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