Index: dlfcn.c =================================================================== RCS file: /usr/cvsroot/asterisk/dlfcn.c,v retrieving revision 1.1 diff -u -p -r1.1 dlfcn.c --- dlfcn.c 26 Oct 2003 19:17:28 -0000 1.1 +++ dlfcn.c 10 Jul 2004 05:42:02 -0000 @@ -199,12 +199,17 @@ static void error(const char *str, ...) char * err_str; va_start(arg, str); tss = pthread_getspecific(dlerror_key); - err_str = tss->errstr; - strncpy(err_str, "dlcompat: ", ERR_STR_LEN); - vsnprintf(err_str + 10, ERR_STR_LEN - 10, str, arg); + if (tss) { + err_str = tss->errstr; + if (err_str) { + strncpy(err_str, "dlcompat: ", ERR_STR_LEN - 1); + err_str[ERR_STR_LEN - 1] = '\0'; + vsnprintf(err_str + 10, ERR_STR_LEN - 10, str, arg); + debug("ERROR: %s\n", err_str); + } + tss->errset = 1; + } va_end(arg); - debug("ERROR: %s\n", err_str); - tss->errset = 1; } static void warning(const char *str) @@ -287,8 +292,14 @@ static const char *searchList() { buf_size = strlen(ldlp) + strlen(dyldlp) + strlen(stdpath) + 4; buf = malloc(buf_size); - snprintf(buf, buf_size, "%s%s%s%s%s%c", dyldlp, (dyldlp[0] ? ":" : ""), ldlp, (ldlp[0] ? ":" : ""), + if (!buf) { + error("%s(%s) Line %d Out of memory.\n", + __FILE__, __FUNCTION__, __LINE__); + } + else { + snprintf(buf, buf_size, "%s%s%s%s%s%c", dyldlp, (dyldlp[0] ? ":" : ""), ldlp, (ldlp[0] ? ":" : ""), stdpath, '\0'); + } } return buf; } @@ -434,7 +445,9 @@ static struct dlstatus *allocStatus() if (!dls) #endif dls = malloc(sizeof(*dls)); - dls->flags = 0; + if (dls) { + dls->flags = 0; + } return dls; } @@ -551,7 +564,9 @@ static inline const char *dyld_error_str if (dylderrstr && strlen(dylderrstr)) { retStr = malloc(strlen(dylderrstr) +1); - strcpy((char*)retStr,dylderrstr); + if (retStr) { + strcpy(retStr, dylderrstr); + } } return retStr; } @@ -652,7 +667,13 @@ static void *dlsymIntern(struct dlstatus if (savedErrorStr) free((char*)savedErrorStr); savedErrorStr = malloc(256); - snprintf((char*)savedErrorStr, 256, "Symbol \"%s\" not in global context",symbol); + if (!savedErrorStr) { + error("%s(%s) Line %d Out of memory.\n", + __FILE__, __FUNCTION__, __LINE__); + } + else { + snprintf((char*)savedErrorStr, 256, "Symbol \"%s\" not in global context",symbol); + } } } } @@ -664,7 +685,13 @@ static void *dlsymIntern(struct dlstatus if (savedErrorStr) free((char*)savedErrorStr); savedErrorStr = malloc(256); - snprintf((char*)savedErrorStr, 256,"Symbol \"%s\" not found",symbol); + if (!savedErrorStr) { + error("%s(%s) Line %d Out of memory.\n", + __FILE__, __FUNCTION__, __LINE__); + } + else { + snprintf((char*)savedErrorStr, 256,"Symbol \"%s\" not found",symbol); + } } if (canSetError) { @@ -866,17 +893,25 @@ static inline void dolock(void) if (!tss) { tss = malloc(sizeof(struct dlthread)); - tss->lockcnt = 0; - tss->errset = 0; - if (pthread_setspecific(dlerror_key, tss)) - { - fprintf(stderr,"dlcompat: pthread_setspecific failed\n"); - exit(1); + if (!tss) { + error("%s(%s) Line %d Out of memory.\n", + __FILE__, __FUNCTION__, __LINE__); + } + else { + tss->lockcnt = 0; + tss->errset = 0; + if (pthread_setspecific(dlerror_key, tss)) + { + fprintf(stderr,"dlcompat: pthread_setspecific failed\n"); + exit(1); + } } } - if (!tss->lockcnt) - err = pthread_mutex_lock(&dlcompat_mutex); - tss->lockcnt = tss->lockcnt +1; + if (tss) { + if (!tss->lockcnt) + err = pthread_mutex_lock(&dlcompat_mutex); + tss->lockcnt = tss->lockcnt +1; + } if (err) exit(err); }