journald: remove rotated file from hashmap when rotation fails

Before, when the user journal file was rotated, journal_file_rotate
could close the old file and fail to open the new file. In that
case, we would leave the old (deallocated) file in the hashmap.
On subsequent accesses, we could retrieve this stale entry, leading
to a segfault.

When journal_file_rotate fails with the file pointer set to 0,
old file is certainly gone, and cannot be used anymore.

https://bugzilla.redhat.com/show_bug.cgi?id=890463
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2013-10-09 22:13:13 -04:00
parent e8fc3ef0fc
commit 03e321c7b6
+3 -1
View File
@@ -337,8 +337,10 @@ void server_rotate(Server *s) {
if (r < 0)
if (f)
log_error("Failed to rotate %s: %s", f->path, strerror(-r));
else
else {
log_error("Failed to create user journal: %s", strerror(-r));
hashmap_remove(s->user_journals, k);
}
else {
hashmap_replace(s->user_journals, k, f);
server_fix_perms(s, f, PTR_TO_UINT32(k));