[PATCH] libosmocore[master]: fix logging talloc ctx: add osmo_init_logging2()

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Wed Mar 28 17:07:49 UTC 2018


Review at  https://gerrit.osmocom.org/7558

fix logging talloc ctx: add osmo_init_logging2()

Deprecate osmo_init_logging() for the benefit of adding an explicit talloc
context argument to new function osmo_init_logging2().  Pass a ctx to
log_init() instead of hardcoded NULL.

Before now, *all* of our code uses a NULL ctx for logging, which amounts to
talloc "leaks" hit by address sanitizer builds on newer gcc (e.g. gcc 7.3.0 on
debian 9).

This commit helps fixing "leaks" detected in e.g. osmo-bsc unit tests by a
sanitize build with gcc (Debian 7.3.0-12) 7.3.0.

Change-Id: I216837780e9405fdaec8059c63d10699c695b360
---
M include/osmocom/core/application.h
M src/application.c
2 files changed, 11 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/58/7558/1

diff --git a/include/osmocom/core/application.h b/include/osmocom/core/application.h
index 266fa9b..edf59ed 100644
--- a/include/osmocom/core/application.h
+++ b/include/osmocom/core/application.h
@@ -1,5 +1,7 @@
 #pragma once
 
+#include <osmocom/core/defs.h>
+
 /*!
  * \file application.h
  * Routines for helping with the osmocom application setup.
@@ -15,6 +17,8 @@
 extern struct log_target *osmo_stderr_target;
 
 void osmo_init_ignore_signals(void);
-int osmo_init_logging(const struct log_info *);
+int osmo_init_logging(const struct log_info *)
+	OSMO_DEPRECATED("use osmo_init_logging2() instead to avoid a NULL talloc ctx");
+int osmo_init_logging2(void *ctx, const struct log_info *log_info);
 
 int osmo_daemonize(void);
diff --git a/src/application.c b/src/application.c
index 2d237e2..d912eb7 100644
--- a/src/application.c
+++ b/src/application.c
@@ -114,13 +114,18 @@
  */
 int osmo_init_logging(const struct log_info *log_info)
 {
+	return osmo_init_logging2(NULL, log_info);
+}
+
+int osmo_init_logging2(void *ctx, const struct log_info *log_info)
+{
 	static int logging_initialized = 0;
 
 	if (logging_initialized)
 		return -EEXIST;
 
 	logging_initialized = 1;
-	log_init(log_info, NULL);
+	log_init(log_info, ctx);
 	osmo_stderr_target = log_target_create_stderr();
 	if (!osmo_stderr_target)
 		return -1;

-- 
To view, visit https://gerrit.osmocom.org/7558
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I216837780e9405fdaec8059c63d10699c695b360
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list