From 171ef826e1489031bc48745f29fa2d4657bf165f Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 28 Mar 2019 10:49:05 +0100 Subject: make all library-internal static buffers thread-local We have a number of library-internal static global buffers which are mainly used for various stringification functions. This worked as all of the related Osmocom programs were strictly single-threaded. Let's make those buffers at least thread-local. This way every thread gets their own set of buffers, and it's safe for multiple threads to execute the same functions once. They're of course still not re-entrant. If you need re-entrancy, you will need to use the _c() or _buf() suffix version of those functions and work with your own (stack or heap) buffers. Change-Id: I50eb2436a7c1261d79a9d2955584dce92780ca07 --- src/socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/socket.c') diff --git a/src/socket.c b/src/socket.c index 37976e2f..1e303bfc 100644 --- a/src/socket.c +++ b/src/socket.c @@ -824,7 +824,7 @@ int osmo_sock_get_name_buf(char *str, size_t str_len, int fd) */ const char *osmo_sock_get_name2(int fd) { - static char str[OSMO_SOCK_NAME_MAXLEN]; + static __thread char str[OSMO_SOCK_NAME_MAXLEN]; osmo_sock_get_name_buf(str, sizeof(str), fd); return str; } -- cgit v1.2.3