diff options
Diffstat (limited to 'Source/lib')
-rw-r--r-- | Source/lib/Makefile.lib | 8 | ||||
-rw-r--r-- | Source/lib/utils/Makefile.utils | 7 | ||||
-rw-r--r-- | Source/lib/utils/leak_detective.c | 189 |
3 files changed, 111 insertions, 93 deletions
diff --git a/Source/lib/Makefile.lib b/Source/lib/Makefile.lib index 0e8c359bd..80a44ff69 100644 --- a/Source/lib/Makefile.lib +++ b/Source/lib/Makefile.lib @@ -14,6 +14,10 @@ LIB_DIR= $(MAIN_DIR)lib/ +include $(MAIN_DIR)lib/utils/Makefile.utils +include $(MAIN_DIR)lib/crypto/Makefile.transforms +include $(MAIN_DIR)lib/asn1/Makefile.asn1 + LIB_OBJS+= $(BUILD_DIR)types.o $(BUILD_DIR)types.o : $(LIB_DIR)types.c $(LIB_DIR)types.h $(CC) $(CFLAGS) -c -o $@ $< @@ -25,7 +29,3 @@ $(BUILD_DIR)definitions.o : $(LIB_DIR)definitions.c $(LIB_DIR)definitions.h LIB_OBJS+= $(BUILD_DIR)library.o $(BUILD_DIR)library.o : $(LIB_DIR)library.c $(LIB_DIR)library.h $(CC) $(CFLAGS) -c -o $@ $< - -include $(MAIN_DIR)lib/crypto/Makefile.transforms -include $(MAIN_DIR)lib/utils/Makefile.utils -include $(MAIN_DIR)lib/asn1/Makefile.asn1 diff --git a/Source/lib/utils/Makefile.utils b/Source/lib/utils/Makefile.utils index 9b6eac7bf..1c82283d7 100644 --- a/Source/lib/utils/Makefile.utils +++ b/Source/lib/utils/Makefile.utils @@ -14,6 +14,9 @@ UTILS_DIR= $(LIB_DIR)utils/ +LIB_OBJS+= $(BUILD_DIR)leak_detective.o +$(BUILD_DIR)leak_detective.o : $(UTILS_DIR)leak_detective.c $(UTILS_DIR)leak_detective.h + $(CC) $(CFLAGS) -c -o $@ $< LIB_OBJS+= $(BUILD_DIR)linked_list.o $(BUILD_DIR)linked_list.o : $(UTILS_DIR)linked_list.c $(UTILS_DIR)linked_list.h @@ -41,8 +44,4 @@ $(BUILD_DIR)identification.o : $(UTILS_DIR)identification.c $(UTILS_DIR)identifi LIB_OBJS+= $(BUILD_DIR)host.o $(BUILD_DIR)host.o : $(UTILS_DIR)host.c $(UTILS_DIR)host.h - $(CC) $(CFLAGS) -c -o $@ $< - -LIB_OBJS+= $(BUILD_DIR)leak_detective.o -$(BUILD_DIR)leak_detective.o : $(UTILS_DIR)leak_detective.c $(UTILS_DIR)leak_detective.h $(CC) $(CFLAGS) -c -o $@ $<
\ No newline at end of file diff --git a/Source/lib/utils/leak_detective.c b/Source/lib/utils/leak_detective.c index 06d8916ac..a6a5c9a91 100644 --- a/Source/lib/utils/leak_detective.c +++ b/Source/lib/utils/leak_detective.c @@ -253,7 +253,7 @@ void free_hook(void *ptr, const void *caller) { pthread_mutex_unlock(&mutex); /* TODO: since pthread_join cannot be excluded cleanly, we are not whining about bad frees */ - return; + //return; logger->log(logger, ERROR, "freeing of invalid memory (%p)", ptr); stack_frame_count = backtrace(stack_frames, STACK_FRAMES_COUNT); log_stack_frames(stack_frames, stack_frame_count); @@ -323,8 +323,8 @@ void leak_detective_init() */ void leak_detective_cleanup() { - report_leaks(); uninstall_hooks(); + report_leaks(); } @@ -348,6 +348,7 @@ struct excluded_function { {"libpthread.so.0", "_pthread_cleanup_pop", NULL, NULL}, {"libc.so.6", "mktime", NULL, NULL}, {"libc.so.6", "vsyslog", NULL, NULL}, + {"libc.so.6", "strerror", NULL, NULL}, }; #define INET_NTOA 0 #define PTHREAD_CREATE 1 @@ -357,6 +358,7 @@ struct excluded_function { #define PTHREAD_CLEANUP_POP 5 #define MKTIME 6 #define VSYSLOG 7 +#define STRERROR 8 /** @@ -402,120 +404,137 @@ char *inet_ntoa(struct in_addr in) return result; } -int pthread_create(pthread_t *__restrict __threadp, __const pthread_attr_t *__restrict __attr, - void *(*__start_routine) (void *), void *__restrict __arg) -{ - int (*_pthread_create) (pthread_t *__restrict __threadp, - __const pthread_attr_t *__restrict __attr, - void *(*__start_routine) (void *), - void *__restrict __arg) = excluded_functions[PTHREAD_CREATE].lib_function; - int result; - - pthread_mutex_lock(&mutex); - uninstall_hooks(); - - result = _pthread_create(__threadp, __attr, __start_routine, __arg); - - install_hooks(); - pthread_mutex_unlock(&mutex); - return result; -} +// int pthread_create(pthread_t *__restrict __threadp, __const pthread_attr_t *__restrict __attr, +// void *(*__start_routine) (void *), void *__restrict __arg) +// { +// int (*_pthread_create) (pthread_t *__restrict __threadp, +// __const pthread_attr_t *__restrict __attr, +// void *(*__start_routine) (void *), +// void *__restrict __arg) = excluded_functions[PTHREAD_CREATE].lib_function; +// int result; +// +// pthread_mutex_lock(&mutex); +// uninstall_hooks(); +// +// result = _pthread_create(__threadp, __attr, __start_routine, __arg); +// +// install_hooks(); +// pthread_mutex_unlock(&mutex); +// return result; +// } +// +// +// int pthread_cancel(pthread_t __th) +// { +// int (*_pthread_cancel) (pthread_t) = excluded_functions[PTHREAD_CANCEL].lib_function; +// int result; +// +// pthread_mutex_lock(&mutex); +// uninstall_hooks(); +// +// result = _pthread_cancel(__th); +// +// install_hooks(); +// pthread_mutex_unlock(&mutex); +// return result; +// } +// +// /* TODO: join has probs, since it dellocates memory +// * allocated (somewhere) with leak_detective :-(. +// * We should exclude all pthread_ functions to fix it !? */ +// int pthread_join(pthread_t __th, void **__thread_return) +// { +// int (*_pthread_join) (pthread_t, void **) = excluded_functions[PTHREAD_JOIN].lib_function; +// int result; +// +// pthread_mutex_lock(&mutex); +// uninstall_hooks(); +// +// result = _pthread_join(__th, __thread_return); +// +// install_hooks(); +// pthread_mutex_unlock(&mutex); +// return result; +// } +// +// void _pthread_cleanup_push (struct _pthread_cleanup_buffer *__buffer, +// void (*__routine) (void *), +// void *__arg) +// { +// int (*__pthread_cleanup_push) (struct _pthread_cleanup_buffer *__buffer, +// void (*__routine) (void *), +// void *__arg) = +// excluded_functions[PTHREAD_CLEANUP_PUSH].lib_function; +// +// pthread_mutex_lock(&mutex); +// uninstall_hooks(); +// +// __pthread_cleanup_push(__buffer, __routine, __arg); +// +// install_hooks(); +// pthread_mutex_unlock(&mutex); +// return; +// } +// +// void _pthread_cleanup_pop (struct _pthread_cleanup_buffer *__buffer, int __execute) +// { +// int (*__pthread_cleanup_pop) (struct _pthread_cleanup_buffer *__buffer, int __execute) = +// excluded_functions[PTHREAD_CLEANUP_POP].lib_function; +// +// pthread_mutex_lock(&mutex); +// uninstall_hooks(); +// +// __pthread_cleanup_pop(__buffer, __execute); +// +// install_hooks(); +// pthread_mutex_unlock(&mutex); +// return; +// } - -int pthread_cancel(pthread_t __th) +time_t mktime(struct tm *tm) { - int (*_pthread_cancel) (pthread_t) = excluded_functions[PTHREAD_CANCEL].lib_function; - int result; - - pthread_mutex_lock(&mutex); - uninstall_hooks(); - - result = _pthread_cancel(__th); - - install_hooks(); - pthread_mutex_unlock(&mutex); - return result; -} + time_t (*_mktime)(struct tm *tm) = excluded_functions[MKTIME].lib_function; + time_t result; -/* TODO: join has probs, since it dellocates memory - * allocated (somewhere) with leak_detective :-(. - * We should exclude all pthread_ functions to fix it !? -int pthread_join(pthread_t __th, void **__thread_return) -{ - int (*_pthread_join) (pthread_t, void **) = excluded_functions[PTHREAD_JOIN].lib_function; - int result; - pthread_mutex_lock(&mutex); uninstall_hooks(); - - result = _pthread_join(__th, __thread_return); + + result = _mktime(tm); install_hooks(); pthread_mutex_unlock(&mutex); return result; } -void _pthread_cleanup_push (struct _pthread_cleanup_buffer *__buffer, - void (*__routine) (void *), - void *__arg) +void vsyslog (int __pri, __const char *__fmt, __gnuc_va_list __ap) { - int (*__pthread_cleanup_push) (struct _pthread_cleanup_buffer *__buffer, - void (*__routine) (void *), - void *__arg) = - excluded_functions[PTHREAD_CLEANUP_PUSH].lib_function; - + void (*_vsyslog) (int __pri, __const char *__fmt, __gnuc_va_list __ap) = excluded_functions[VSYSLOG].lib_function; + pthread_mutex_lock(&mutex); uninstall_hooks(); - __pthread_cleanup_push(__buffer, __routine, __arg); + _vsyslog(__pri, __fmt, __ap); install_hooks(); pthread_mutex_unlock(&mutex); return; } - -void _pthread_cleanup_pop (struct _pthread_cleanup_buffer *__buffer, int __execute) -{ - int (*__pthread_cleanup_pop) (struct _pthread_cleanup_buffer *__buffer, int __execute) = - excluded_functions[PTHREAD_CLEANUP_POP].lib_function; - - pthread_mutex_lock(&mutex); - uninstall_hooks(); - - __pthread_cleanup_pop(__buffer, __execute); - - install_hooks(); - pthread_mutex_unlock(&mutex); - return; -}*/ -time_t mktime(struct tm *tm) -{ - time_t (*_mktime)(struct tm *tm) = excluded_functions[MKTIME].lib_function; - time_t result; - pthread_mutex_lock(&mutex); - uninstall_hooks(); - - result = _mktime(tm); - - install_hooks(); - pthread_mutex_unlock(&mutex); - return result; -} -void vsyslog (int __pri, __const char *__fmt, __gnuc_va_list __ap) +char *strerror(int errnum) { - void (*_vsyslog) (int __pri, __const char *__fmt, __gnuc_va_list __ap) = excluded_functions[VSYSLOG].lib_function; + char* (*_strerror) (int) = excluded_functions[STRERROR].lib_function; + char *result; pthread_mutex_lock(&mutex); uninstall_hooks(); - _vsyslog(__pri, __fmt, __ap); + result = _strerror(errnum); install_hooks(); pthread_mutex_unlock(&mutex); - return; + return result; } #endif /* LEAK_DETECTION */ |