Fixes a thread safety issue with snd_pcm_open().
Signed-off-by: Jerome Forissier jerome@taodyne.com --- src/pcm/pcm_direct.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/src/pcm/pcm_direct.c b/src/pcm/pcm_direct.c index 6802ecc..38c6c66 100644 --- a/src/pcm/pcm_direct.c +++ b/src/pcm/pcm_direct.c @@ -1629,13 +1629,20 @@ int snd_pcm_direct_parse_open_conf(snd_config_t *root, snd_config_t *conf, continue; } if (isdigit(*group) == 0) { - struct group *grp = getgrnam(group); - if (grp == NULL) { + long clen = sysconf(_SC_GETGR_R_SIZE_MAX); + size_t len = (clen == -1) ? 1024 : (size_t)clen; + struct group grp, *pgrp; + char *buffer = (char *)malloc(len); + if (buffer == NULL) + return -ENOMEM; + int st = getgrnam_r(group, &grp, buffer, len, &pgrp); + if (st != 0) { SNDERR("The field ipc_gid must be a valid group (create group %s)", group); - free(group); + free(buffer); return -EINVAL; } - rec->ipc_gid = grp->gr_gid; + rec->ipc_gid = pgrp->gr_gid; + free(buffer); } else { rec->ipc_gid = strtol(group, &endp, 10); }