X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=src%2Fcommon%2Fconfig%2Fconfig.c;h=0b8e13f454b88df565e5506339d0e72f3c7deb01;hb=5b365375b92e517b7e41069799679b7835efd7ef;hp=b2a0912b8f5531d75c530875e5593812335803b8;hpb=30c6ce92983318886a7779fe29418d5824d50092;p=lttng-tools.git diff --git a/src/common/config/config.c b/src/common/config/config.c index b2a0912b8..0b8e13f45 100644 --- a/src/common/config/config.c +++ b/src/common/config/config.c @@ -2443,6 +2443,23 @@ end: return ret; } +/* Allocate dirent as recommended by READDIR(3), NOTES on readdir_r */ +static +struct dirent *alloc_dirent(const char *path) +{ + size_t len; + long name_max; + struct dirent *entry; + + name_max = pathconf(path, _PC_NAME_MAX); + if (name_max == -1) { + name_max = PATH_MAX; + } + len = offsetof(struct dirent, d_name) + name_max + 1; + entry = zmalloc(len); + return entry; +} + static int load_session_from_path(const char *path, const char *session_name, struct session_config_validation_ctx *validation_ctx, int override) @@ -2478,7 +2495,7 @@ int load_session_from_path(const char *path, const char *session_name, goto end; } - entry = zmalloc(sizeof(*entry)); + entry = alloc_dirent(path); if (!entry) { ret = -LTTNG_ERR_NOMEM; goto end;