shared/unit-file: make sure the old hashmaps and sets are freed upon replacement

Possibly fixes #15220. (There might be another leak. I'm still investigating.)

The leak would occur when the path cache was rebuilt. So in normal circumstances
it wouldn't be too bad, since usually the path cache is not rebuilt too often. But
the case in #15220, where new unit files are created in a loop and started, the leak
occurs once for each unit file:

$ for i in {1..300}; do cp ~/.config/systemd/user/test0001.service ~/.config/systemd/user/test$(printf %04d $i).service; systemctl --user start test$(printf %04d $i).service;done
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2020-05-28 18:51:52 +02:00
parent db868d45f9
commit 3fb2326f3e
6 changed files with 33 additions and 12 deletions
+8
View File
@@ -5,6 +5,14 @@
#include "hashmap.h"
#include "macro.h"
#define set_free_and_replace(a, b) \
({ \
set_free(a); \
(a) = (b); \
(b) = NULL; \
0; \
})
Set *internal_set_new(const struct hash_ops *hash_ops HASHMAP_DEBUG_PARAMS);
#define set_new(ops) internal_set_new(ops HASHMAP_DEBUG_SRC_ARGS)