Journal-remote: modernize source_free() and fix memleak (#36430)

- modernize source_free().
- fix memleak introduced by cfaf78001c. Fixes CID#1591182.
This commit is contained in:
Yu Watanabe
2025-02-19 04:56:15 +09:00
committed by GitHub
3 changed files with 13 additions and 14 deletions
+7 -9
View File
@@ -186,24 +186,22 @@ static int build_accept_encoding(char **ret) {
}
static int request_meta(void **connection_cls, int fd, char *hostname) {
RemoteSource *source;
Writer *writer;
int r;
assert(connection_cls);
if (*connection_cls)
return 0;
if (*connection_cls)
return 0; /* already assigned. */
Writer *writer;
r = journal_remote_get_writer(journal_remote_server_global, hostname, &writer);
if (r < 0)
return log_warning_errno(r, "Failed to get writer for source %s: %m",
hostname);
source = source_new(fd, true, hostname, writer);
if (!source) {
writer_unref(writer);
_cleanup_(source_freep) RemoteSource *source = source_new(fd, true, hostname, writer);
if (!source)
return log_oom();
}
log_debug("Added RemoteSource as connection metadata %p", source);
@@ -212,7 +210,7 @@ static int request_meta(void **connection_cls, int fd, char *hostname) {
return log_oom();
source->compression = COMPRESSION_NONE;
*connection_cls = source;
*connection_cls = TAKE_PTR(source);
return 0;
}
+4 -4
View File
@@ -6,20 +6,20 @@
#include "parse-util.h"
#include "string-util.h"
void source_free(RemoteSource *source) {
RemoteSource* source_free(RemoteSource *source) {
if (!source)
return;
return NULL;
journal_importer_cleanup(&source->importer);
log_debug("Writer ref count %u", source->writer->n_ref);
log_trace("Writer ref count %u", source->writer->n_ref);
writer_unref(source->writer);
sd_event_source_unref(source->event);
sd_event_source_unref(source->buffer_event);
free(source->encoding);
free(source);
return mfree(source);
}
/**
+2 -1
View File
@@ -19,5 +19,6 @@ typedef struct RemoteSource {
} RemoteSource;
RemoteSource* source_new(int fd, bool passive_fd, char *name, Writer *writer);
void source_free(RemoteSource *source);
RemoteSource* source_free(RemoteSource *source);
DEFINE_TRIVIAL_CLEANUP_FUNC(RemoteSource*, source_free);
int process_source(RemoteSource *source, JournalFileFlags file_flags);