mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2026-02-23 01:40:06 -05:00
dlsym: fix the reference to the origin lib directory
There is reference to the variable on heap in
commit 33089f30a3 .
Cache the origin directory better.
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
d9c835d804
commit
8d866e4cd8
1 changed files with 24 additions and 22 deletions
46
src/dlmisc.c
46
src/dlmisc.c
|
|
@ -38,6 +38,24 @@
|
||||||
#ifndef PIC
|
#ifndef PIC
|
||||||
struct snd_dlsym_link *snd_dlsym_start = NULL;
|
struct snd_dlsym_link *snd_dlsym_start = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
static char *snd_libdir_origin = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBPTHREAD
|
||||||
|
static pthread_mutex_t snd_dlobj_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
|
static inline void snd_dlobj_lock(void)
|
||||||
|
{
|
||||||
|
pthread_mutex_lock(&snd_dlobj_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void snd_dlobj_unlock(void)
|
||||||
|
{
|
||||||
|
pthread_mutex_unlock(&snd_dlobj_mutex);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
static inline void snd_dlobj_lock(void) {}
|
||||||
|
static inline void snd_dlobj_unlock(void) {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -50,10 +68,10 @@ struct snd_dlsym_link *snd_dlsym_start = NULL;
|
||||||
*/
|
*/
|
||||||
int snd_dlpath(char *path, size_t path_len, const char *name)
|
int snd_dlpath(char *path, size_t path_len, const char *name)
|
||||||
{
|
{
|
||||||
static const char *origin_dir = NULL;
|
|
||||||
#ifdef HAVE_LIBDL
|
#ifdef HAVE_LIBDL
|
||||||
#ifdef __GLIBC__
|
#ifdef __GLIBC__
|
||||||
static int plugin_dir_set = 0;
|
static int plugin_dir_set = 0;
|
||||||
|
snd_dlobj_lock();
|
||||||
if (!plugin_dir_set) {
|
if (!plugin_dir_set) {
|
||||||
struct link_map *links;
|
struct link_map *links;
|
||||||
Dl_info info;
|
Dl_info info;
|
||||||
|
|
@ -63,14 +81,15 @@ int snd_dlpath(char *path, size_t path_len, const char *name)
|
||||||
if (links != NULL && dlinfo(links, RTLD_DI_ORIGIN, origin) == 0) {
|
if (links != NULL && dlinfo(links, RTLD_DI_ORIGIN, origin) == 0) {
|
||||||
snprintf(path, path_len, "%s/alsa-lib", origin);
|
snprintf(path, path_len, "%s/alsa-lib", origin);
|
||||||
if (access(path, X_OK) == 0)
|
if (access(path, X_OK) == 0)
|
||||||
origin_dir = origin;
|
snd_libdir_origin = strdup(origin);
|
||||||
}
|
}
|
||||||
plugin_dir_set = 1;
|
plugin_dir_set = 1;
|
||||||
}
|
}
|
||||||
|
snd_dlobj_unlock();
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
if (origin_dir)
|
if (snd_libdir_origin)
|
||||||
snprintf(path, path_len, "%s/alsa-lib/%s", origin_dir, name);
|
snprintf(path, path_len, "%s/alsa-lib/%s", snd_libdir_origin, name);
|
||||||
else
|
else
|
||||||
snprintf(path, path_len, "%s/%s", ALSA_PLUGIN_DIR, name);
|
snprintf(path, path_len, "%s/%s", ALSA_PLUGIN_DIR, name);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -268,23 +287,6 @@ struct dlobj_cache {
|
||||||
struct list_head list;
|
struct list_head list;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef HAVE_LIBPTHREAD
|
|
||||||
static pthread_mutex_t snd_dlobj_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
||||||
|
|
||||||
static inline void snd_dlobj_lock(void)
|
|
||||||
{
|
|
||||||
pthread_mutex_lock(&snd_dlobj_mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void snd_dlobj_unlock(void)
|
|
||||||
{
|
|
||||||
pthread_mutex_unlock(&snd_dlobj_mutex);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
static inline void snd_dlobj_lock(void) {}
|
|
||||||
static inline void snd_dlobj_unlock(void) {}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static LIST_HEAD(pcm_dlobj_list);
|
static LIST_HEAD(pcm_dlobj_list);
|
||||||
|
|
||||||
static struct dlobj_cache *
|
static struct dlobj_cache *
|
||||||
|
|
@ -421,7 +423,7 @@ void snd_dlobj_cache_cleanup(void)
|
||||||
free((void *)c->lib); /* shut up gcc warning */
|
free((void *)c->lib); /* shut up gcc warning */
|
||||||
free(c);
|
free(c);
|
||||||
}
|
}
|
||||||
|
free(snd_libdir_origin);
|
||||||
snd_dlobj_unlock();
|
snd_dlobj_unlock();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue