Skip to content

Commit

Permalink
transport: free LogTransportBIO BIO_meth instance at shutdown
Browse files Browse the repository at this point in the history
This was a one-off allocation, but it's better if it is freed.

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
  • Loading branch information
bazsi committed Feb 6, 2025
1 parent d4a7589 commit 704ded6
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 7 deletions.
3 changes: 3 additions & 0 deletions lib/apphook.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "timeutils/cache.h"
#include "multi-line/multi-line-factory.h"
#include "filterx/filterx-globals.h"
#include "transport/transport-globals.h"

#include <iv.h>
#include <iv_work.h>
Expand Down Expand Up @@ -243,6 +244,7 @@ app_startup(void)
timeutils_global_init();
multi_line_global_init();
filterx_global_init();
log_transport_global_init();
}

void
Expand Down Expand Up @@ -270,6 +272,7 @@ app_shutdown(void)
msg_stats_deinit();
run_application_hook(AH_SHUTDOWN);

log_transport_global_deinit();
filterx_global_deinit();
multi_line_global_deinit();
main_loop_thread_resource_deinit();
Expand Down
2 changes: 2 additions & 0 deletions lib/transport/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set(TRANSPORT_HEADERS
transport/transport-stack.h
transport/transport-factory-tls.h
transport/transport-factory-haproxy.h
transport/transport-globals.h
transport/tls-context.h
transport/tls-verifier.h
transport/tls-session.h
Expand All @@ -29,6 +30,7 @@ set(TRANSPORT_SOURCES
transport/transport-stack.c
transport/transport-factory-tls.c
transport/transport-factory-haproxy.c
transport/transport-globals.c
transport/tls-context.c
transport/tls-verifier.c
transport/tls-session.c
Expand Down
2 changes: 2 additions & 0 deletions lib/transport/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ transportinclude_HEADERS = \
lib/transport/transport-stack.h \
lib/transport/transport-factory-tls.h \
lib/transport/transport-factory-haproxy.h \
lib/transport/transport-globals.h \
lib/transport/tls-context.h \
lib/transport/tls-verifier.h \
lib/transport/tls-session.h
Expand All @@ -31,6 +32,7 @@ transport_sources = \
lib/transport/transport-stack.c \
lib/transport/transport-factory-tls.c \
lib/transport/transport-factory-haproxy.c \
lib/transport/transport-globals.c \
lib/transport/tls-context.c \
lib/transport/tls-verifier.c \
lib/transport/tls-session.c
Expand Down
34 changes: 34 additions & 0 deletions lib/transport/transport-globals.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2025 Axoflow
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As an additional exemption you are allowed to compile & link against the
* OpenSSL libraries as published by the OpenSSL project. See the file
* COPYING for details.
*/
#include "transport-tls.h"

void
log_transport_global_init(void)
{
log_transport_tls_global_init();
}

void
log_transport_global_deinit(void)
{
log_transport_tls_global_deinit();
}
31 changes: 31 additions & 0 deletions lib/transport/transport-globals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2025 Axoflow
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As an additional exemption you are allowed to compile & link against the
* OpenSSL libraries as published by the OpenSSL project. See the file
* COPYING for details.
*/

#ifndef TRANSPORT_GLOBALS_H_INCLUDED
#define TRANSPORT_GLOBALS_H_INCLUDED

#include "syslog-ng.h"

void log_transport_global_init(void);
void log_transport_global_deinit(void);

#endif
24 changes: 17 additions & 7 deletions lib/transport/transport-tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ typedef struct _LogTransportTLS
} LogTransportTLS;

const gchar *TLS_TRANSPORT_NAME = "tls";
static BIO_METHOD *meth_transport = NULL;

static int
_BIO_transport_write(BIO *bio, const char *buf, size_t buflen, size_t *written_bytes)
Expand Down Expand Up @@ -112,23 +113,19 @@ _BIO_transport_ctrl(BIO *bio, int cmd, long num, void *ptr)
return ret;
}

BIO_METHOD *
static BIO_METHOD *
BIO_s_transport(void)
{
static BIO_METHOD *meth = NULL;
BIO_METHOD *meth = BIO_meth_new(BIO_TYPE_NONE, "LogTransportBIO");

if (meth)
return meth;

meth = BIO_meth_new(BIO_TYPE_NONE, "LogTransportBIO");
BIO_meth_set_write_ex(meth, _BIO_transport_write);
BIO_meth_set_read_ex(meth, _BIO_transport_read);
BIO_meth_set_ctrl(meth, _BIO_transport_ctrl);

return meth;
}

BIO *
static BIO *
BIO_transport_new(LogTransportTLS *transport)
{
BIO *bio = BIO_new(BIO_s_transport());
Expand Down Expand Up @@ -379,3 +376,16 @@ log_transport_tls_free_method(LogTransport *s)
tls_session_free(self->tls_session);
log_transport_adapter_free_method(s);
}

void
log_transport_tls_global_init(void)
{
meth_transport = BIO_s_transport();
}

void
log_transport_tls_global_deinit(void)
{
BIO_meth_free(meth_transport);
meth_transport = NULL;
}
3 changes: 3 additions & 0 deletions lib/transport/transport-tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@
LogTransport *log_transport_tls_new(TLSSession *tls_session, LogTransportIndex base_index);
TLSSession *log_tansport_tls_get_session(LogTransport *s);

void log_transport_tls_global_init(void);
void log_transport_tls_global_deinit(void);

#endif
1 change: 1 addition & 0 deletions tests/copyright/policy
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ lib/generic-number\.[ch]
lib/tests/test_generic_number\.c
lib/severity-aliases\.table
lib/transport/transport-adapter\.[ch]
lib/transport/transport-globals\.[ch]
syslog-ng-ctl/commands/log-level.[ch]
syslog-ng-ctl/commands/attach.[ch]
modules/afsocket/afsocket-signals.h
Expand Down

0 comments on commit 704ded6

Please sign in to comment.