This commit is contained in:
PolynomialDivision 2017-08-31 11:52:29 +02:00
parent 191db22d60
commit b098085543
3 changed files with 32 additions and 1 deletions

View file

@ -97,11 +97,13 @@ char *gcrypt_decrypt_msg(char *msg, size_t msg_length) {
printf("gcry_cipher_encrypt failed: %s/%s\n", printf("gcry_cipher_encrypt failed: %s/%s\n",
gcry_strsource(gcry_error_handle), gcry_strsource(gcry_error_handle),
gcry_strerror(gcry_error_handle)); gcry_strerror(gcry_error_handle));
printf("Free %s: %p\n","out_buffer", out_buffer);
free(out_buffer); free(out_buffer);
return NULL; return NULL;
} }
char *out = malloc(strlen(out_buffer) + 1); char *out = malloc(strlen(out_buffer) + 1);
strcpy(out, out_buffer); strcpy(out, out_buffer);
printf("Free %s: %p\n","out_buffer", out_buffer);
free(out_buffer); free(out_buffer);
return out; return out;
} }

View file

@ -26,12 +26,16 @@
#include <dlfcn.h> #include <dlfcn.h>
static void* (*real_malloc)(size_t)=NULL; static void* (*real_malloc)(size_t)=NULL;
static void* (*real_free)(void *p)=NULL;
void daemon_shutdown(); void daemon_shutdown();
void signal_handler(int sig); void signal_handler(int sig);
struct sigaction newSigAction; struct sigaction newSigAction;
int free_counter = 0;
pthread_t tid_probe; pthread_t tid_probe;
pthread_t tid_client; pthread_t tid_client;
pthread_t tid_get_client; pthread_t tid_get_client;
@ -54,6 +58,8 @@ void daemon_shutdown()
pthread_mutex_destroy(&probe_array_mutex); pthread_mutex_destroy(&probe_array_mutex);
pthread_mutex_destroy(&client_array_mutex); pthread_mutex_destroy(&client_array_mutex);
pthread_mutex_destroy(&ap_array_mutex); pthread_mutex_destroy(&ap_array_mutex);
printf("Free Counter: %d\n", free_counter);
} }
void signal_handler(int sig) void signal_handler(int sig)
@ -83,6 +89,10 @@ static void mtrace_init(void)
if (NULL == real_malloc) { if (NULL == real_malloc) {
fprintf(stderr, "Error in `dlsym`: %s\n", dlerror()); fprintf(stderr, "Error in `dlsym`: %s\n", dlerror());
} }
real_free = dlsym(RTLD_NEXT, "free");
if (NULL == real_free) {
fprintf(stderr, "Error in `dlsym`: %s\n", dlerror());
}
} }
void *malloc(size_t size) void *malloc(size_t size)
@ -96,10 +106,25 @@ void *malloc(size_t size)
fprintf(stderr, "malloc(%d) = ", size); fprintf(stderr, "malloc(%d) = ", size);
p = real_malloc(size); p = real_malloc(size);
fprintf(stderr, "%p\n", p); fprintf(stderr, "%p\n", p);
free_counter++;
return p; return p;
} }
void free(void *p)
{
mtrace_init();
if(real_free==NULL) {
mtrace_init();
}
p = real_free(p);
fprintf(stderr, "free: ");
fprintf(stderr, "%p\n", p);
free_counter--;
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
free_counter = 0;
const char *ubus_socket = NULL; const char *ubus_socket = NULL;
int ch; int ch;
@ -182,7 +207,7 @@ int main(int argc, char **argv) {
return 1; return 1;
} }
init_socket_runopts(opt_broadcast_ip, opt_broadcast_port, 1); //init_socket_runopts(opt_broadcast_ip, opt_broadcast_port, 1);
pthread_create(&tid_probe, NULL, &remove_array_thread, NULL); pthread_create(&tid_probe, NULL, &remove_array_thread, NULL);
pthread_create(&tid_client, NULL, &remove_client_array_thread, NULL); pthread_create(&tid_client, NULL, &remove_client_array_thread, NULL);

View file

@ -146,6 +146,7 @@ void *receive_msg_enc(void *args) {
char *dec = gcrypt_decrypt_msg(base64_dec_str, base64_dec_length); char *dec = gcrypt_decrypt_msg(base64_dec_str, base64_dec_length);
printf("Free %s: %p\n","base64_dec_str", base64_dec_str);
free(base64_dec_str); free(base64_dec_str);
printf("[WC] Network-Received: %s\n", dec); printf("[WC] Network-Received: %s\n", dec);
@ -175,6 +176,7 @@ void *receive_msg_enc(void *args) {
} }
} }
// free encrypted string // free encrypted string
printf("Free %s: %p\n","dec", dec);
free(dec); free(dec);
} }
} }
@ -225,7 +227,9 @@ int send_string_enc(char *msg) {
pthread_mutex_unlock(&send_mutex); pthread_mutex_unlock(&send_mutex);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
printf("Free %s: %p\n","base64_enc_str", base64_enc_str);
free(base64_enc_str); free(base64_enc_str);
printf("Free %s: %p\n","enc", enc);
free(enc); free(enc);
pthread_mutex_unlock(&send_mutex); pthread_mutex_unlock(&send_mutex);
return 0; return 0;