diff --git a/src/libsystemd/sd-bus/bus-match.c b/src/libsystemd/sd-bus/bus-match.c index db8da6ee12..2a3e7039a7 100644 --- a/src/libsystemd/sd-bus/bus-match.c +++ b/src/libsystemd/sd-bus/bus-match.c @@ -846,7 +846,7 @@ fail: } char *bus_match_to_string(struct bus_match_component *components, unsigned n_components) { - char *buffer = NULL; + _cleanup_free_ char *buffer = NULL; size_t size = 0; int r; @@ -855,7 +855,7 @@ char *bus_match_to_string(struct bus_match_component *components, unsigned n_com assert(components); - _cleanup_fclose_ FILE *f = open_memstream_unlocked(&buffer, &size); + FILE *f = open_memstream_unlocked(&buffer, &size); if (!f) return NULL; @@ -878,10 +878,10 @@ char *bus_match_to_string(struct bus_match_component *components, unsigned n_com } r = fflush_and_check(f); + safe_fclose(f); if (r < 0) return NULL; - - return buffer; + return TAKE_PTR(buffer); } int bus_match_add(