From 91ba8011c8892989f89822ccebdf88e8c268f9d5 Mon Sep 17 00:00:00 2001 From: stamrakar Date: Sat, 12 Oct 2024 01:36:10 -0600 Subject: [PATCH 01/17] closeAll() added for proper exit handling --- server/aesdsocket.c | 191 +++++++++++++++++++++----------------------- 1 file changed, 90 insertions(+), 101 deletions(-) diff --git a/server/aesdsocket.c b/server/aesdsocket.c index 0227c3a..aefcfdc 100644 --- a/server/aesdsocket.c +++ b/server/aesdsocket.c @@ -36,6 +36,8 @@ #include #include #include +#include +#include #define PORT "9000" // the port users will be connecting to //const char* port = "9000"; @@ -45,25 +47,62 @@ #define BUF_SIZE 1024 -bool caught_sigalarm = false; +typedef struct slist_data_s my_threads; + +struct slist_data_s { + bool thread_complete_success; + SLIST_ENTRY(slist_data_s) threads; +}; + +sig_atomic_t sig = 0; bool daemon_en = false; -int sockfd , new_fd, recvfile_fd; +int sockfd = -1; +int new_fd = -1; +int recvfile_fd = -1; + pid_t pid; const char *recvfile = "/var/tmp/aesdsocketdata"; -void closeAll(); +static void closeAll(int exit_flag); +static void init_sigHandler(void); +static void signal_handler(int signal_number); -static void signal_handler ( int signal_number ) +static void signal_handler (int signal_number) { - if ( signal_number == SIGINT || signal_number == SIGTERM ) + if (signal_number == SIGINT || signal_number == SIGTERM) { syslog(LOG_DEBUG, "Caught signal, exiting"); - caught_sigalarm = true; - closeAll(); + sig = 1; } } +static void init_sigHandler(void) +{ + struct sigaction sig1; + memset(&sig1, 0, sizeof(struct sigaction)); + sig1.sa_handler = signal_handler; + if( sigaction(SIGINT, &sig1, NULL) != 0) + { + syslog(LOG_ERR, "Error %d (%s) registering for SIGINT", errno, strerror(errno)); + perror("sigint: fail"); + closeAll(EXIT_FAILURE); + } + + struct sigaction sig2; + memset(&sig2, 0, sizeof(struct sigaction)); + sig2.sa_handler = signal_handler; + if( sigaction(SIGTERM, &sig2, NULL) != 0) + { + syslog(LOG_ERR, "Error %d (%s) registering for SIGTERM", errno, strerror(errno)); + perror("sigterm: fail"); + closeAll(EXIT_FAILURE); + } + + return; +} + + static int create_daemon() { pid = fork(); @@ -108,17 +147,19 @@ static int create_daemon() } -void closeAll() +void closeAll(int exit_flag) { syslog(LOG_DEBUG, "PERFORMING CLEANUP."); if(sockfd != -1) close(sockfd); if(new_fd != -1) close(new_fd); + if(recvfile_fd != -1) close(recvfile_fd); if(remove(recvfile) != 0) { syslog(LOG_ERR, "File removal not successful"); } - closelog(); syslog(LOG_DEBUG, "CLEANUP COMPLETED."); + closelog(); + exit(exit_flag); } int main(int argc, char *argv[]) @@ -129,48 +170,16 @@ int main(int argc, char *argv[]) syslog(LOG_DEBUG, "__________________________./full-test.sh________________________"); int status; - // int sockfd, new_fd; - // char buf[BUF_SIZE]; - // socklen_t sin_size; - // ssize_t nread; socklen_t peer_addrlen; struct addrinfo hints; struct addrinfo *servinfo; - //ssize_t num_bytes_rx; - /* - servInfo is just a pointer location on the stack. Will point to the results. - Haven't reserved location for the actual addrinfo structure - */ struct sockaddr_in peer_addr; - // struct sockaddr_in sa; char ip4[INET_ADDRSTRLEN]; //space to hold the IPv4 string int yes=1; - // int recvfile_fd; - //Declare the initial buffer - - - // signal(SIGINT, signal_handler); - // signal(SIGTERM, signal_handler); - // Setup SIGINT and SIGTERM - struct sigaction sig1; - memset(&sig1, 0, sizeof(struct sigaction)); - sig1.sa_handler = signal_handler; - if( sigaction(SIGINT, &sig1, NULL) != 0) - { - syslog(LOG_ERR, "Error %d (%s) registering for SIGINT", errno, strerror(errno)); - perror("sigint: fail"); - } - - struct sigaction sig2; - memset(&sig2, 0, sizeof(struct sigaction)); - sig2.sa_handler = signal_handler; - if( sigaction(SIGTERM, &sig2, NULL) != 0) - { - syslog(LOG_ERR, "Error %d (%s) registering for SIGTERM", errno, strerror(errno)); - perror("sigterm: fail"); - } + //Initializes the signal handlers SIGINT and SIGTERM + init_sigHandler(); if ((argc == 2) && (strcmp(argv[1], "-d") == 0)) @@ -187,9 +196,8 @@ int main(int argc, char *argv[]) /*error*/ int err = errno; syslog(LOG_ERR, "%s failed to open. errno -> %d", recvfile, err); - exit(1); + closeAll(EXIT_FAILURE); } - //syslog(LOG_DEBUG, "recvfile_fd is %d", recvfile_fd); memset(&hints, 0, sizeof(hints)); //empty the struct @@ -197,19 +205,13 @@ int main(int argc, char *argv[]) hints.ai_socktype = SOCK_STREAM; // Datagram socket hints.ai_flags = AI_PASSIVE; // For wildcard IP address, fill in my IP for me - //Not sure if these need to be initialized - // hints.ai_protocol = 0; // Any protocol - // hints.ai_canonname = NULL; - // hints.ai_addr = NULL; - // hints.ai_next = NULL; - // &servInfo is the not the pointer to the addrinfo struct, // but rather pointer to the location to store the pointer to that addrinfo if ((status = getaddrinfo(NULL, PORT, &hints, &servinfo)) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status)); - exit(EXIT_FAILURE); + closeAll(EXIT_FAILURE); } syslog(LOG_DEBUG, "getaddrinfo pass"); @@ -218,7 +220,7 @@ int main(int argc, char *argv[]) if ((sockfd = socket(servinfo->ai_family, servinfo->ai_socktype, servinfo->ai_protocol)) == -1) { perror("server: socket"); - exit(EXIT_FAILURE); + closeAll(EXIT_FAILURE); } syslog(LOG_DEBUG, "socket pass"); @@ -226,7 +228,7 @@ int main(int argc, char *argv[]) if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) { perror("server: setsockopt"); - exit(EXIT_FAILURE); + closeAll(EXIT_FAILURE); } syslog(LOG_DEBUG, "setsockopt pass"); @@ -234,26 +236,23 @@ int main(int argc, char *argv[]) if (bind(sockfd, servinfo->ai_addr, servinfo->ai_addrlen) == -1) { perror("server: bind"); - exit(EXIT_FAILURE); + closeAll(EXIT_FAILURE); } + syslog(LOG_DEBUG, "bind pass"); + freeaddrinfo(servinfo); - // when in daemon mode the program should fork after ensuring it can bind to port 9000. if(daemon_en) { if(create_daemon() != 0) { + syslog(LOG_ERR, "serve: daemon"); perror("server: daemon"); - exit(EXIT_FAILURE); + closeAll(EXIT_FAILURE); } - } - - - syslog(LOG_DEBUG, "bind pass"); - if (listen(sockfd, BACKLOG) == -1) { perror("server: listen"); @@ -270,46 +269,48 @@ int main(int argc, char *argv[]) ssize_t bytes_rx = 0; ssize_t addibuffer; ssize_t bytes_read; - //ssize_t total_size; char *send_my_buffer = NULL; char *new_line = NULL; ssize_t nr; bool isPacketValid = false; - while(!caught_sigalarm){ //signal to exit this + while(!sig){ bytes_read = 0; incrementBy = BUF_SIZE; isPacketValid = false; peer_addrlen = sizeof(peer_addr); - //new_fd is the accepted fd if((new_fd = accept(sockfd, (struct sockaddr *)&peer_addr, &peer_addrlen)) == -1 ) { - syslog(LOG_ERR, "server: accept, error here?????"); + syslog(LOG_ERR, "server: accept"); perror("server: accept"); - //closeAll(); - //exit(EXIT_FAILURE); continue; } - else - { - syslog(LOG_DEBUG, "CONNECTED"); - } - //syslog(LOG_DEBUG, "new_fd is %d", new_fd); + + syslog(LOG_DEBUG, "CONNECTED"); + + // int rc; + // rc = pthread_create(threadid, NULL, threadfunc, (void*)new_fd); + // if (rc != 0) + // { + // ERROR_LOG("Failed to pthread_create(), error was %d", rc); + // free(threadp); + // return false; + // } + + + //create thread here ? + inet_ntop(AF_INET, &(peer_addr.sin_addr), ip4, sizeof(ip4)); syslog(LOG_DEBUG, "Accepted connection from %s", ip4); addibuffer = 0; - //total_size = BUF_SIZE; char *my_buffer = (char *) malloc(BUF_SIZE); if (my_buffer == NULL) { syslog(LOG_ERR, "Failed to malloc."); - close(new_fd); - exit(EXIT_FAILURE); + closeAll(EXIT_FAILURE); } - // set buffer values all to zero memset(my_buffer, 0, BUF_SIZE); - do{ bytes_rx = recv(new_fd, my_buffer + addibuffer, BUF_SIZE-1, 0); @@ -318,8 +319,8 @@ int main(int argc, char *argv[]) { free(my_buffer); perror("server: recv"); - syslog(LOG_ERR, "recv: error??"); - exit(EXIT_FAILURE); + syslog(LOG_ERR, "server: recv"); + closeAll(EXIT_FAILURE); } addibuffer += bytes_rx; new_line = strchr(my_buffer, '\n'); //if NULL, keep getting packets @@ -337,14 +338,11 @@ int main(int argc, char *argv[]) if(my_buffer == NULL) { syslog(LOG_ERR, "Failed to realloc."); - close(new_fd); - exit(EXIT_FAILURE); + closeAll(EXIT_FAILURE); } incrementBy += BUF_SIZE; memset(my_buffer+addibuffer, 0 , incrementBy-addibuffer); - //addibuffer = 0; } - //syslog(LOG_DEBUG, "I am here once only. %d", isPacketValid); }while (isPacketValid == false); @@ -363,7 +361,7 @@ int main(int argc, char *argv[]) int err1 = errno; syslog(LOG_ERR, "Failed to write bytes: errno -> %d", err1); syslog(LOG_ERR, "error string is %s", strerror(errno)); - exit(EXIT_FAILURE); + closeAll(EXIT_FAILURE); } syslog(LOG_DEBUG, "Write completed to recvfile_fd"); @@ -374,18 +372,18 @@ int main(int argc, char *argv[]) if(lseek(recvfile_fd, 0, SEEK_SET) == -1) { - syslog(LOG_ERR, "lseek error"); - perror("lseek"); + syslog(LOG_ERR, "server: lseek"); + perror("server: lseek"); + closeAll(EXIT_FAILURE); } syslog(LOG_DEBUG, "lseek pass"); - syslog(LOG_DEBUG, "addibuffer is %ld", addibuffer); + //syslog(LOG_DEBUG, "addibuffer is %ld", addibuffer); send_my_buffer = (char *) malloc(addibuffer); if (send_my_buffer == NULL) { syslog(LOG_ERR, "Failed to malloc sending buffer."); - close(new_fd); - exit(EXIT_FAILURE); + closeAll(EXIT_FAILURE); } @@ -406,29 +404,20 @@ int main(int argc, char *argv[]) syslog(LOG_DEBUG,"HEREEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"); syslog(LOG_ERR,"server: send"); perror("server: send"); - exit(EXIT_FAILURE); + closeAll(EXIT_FAILURE); } else { syslog(LOG_DEBUG, "send pass"); } } - //errno_read = errno; - - // syslog(LOG_DEBUG, "bytes_read after while is %ld", bytes_read); - // syslog(LOG_ERR, "errno is %d", errno_read); - // syslog(LOG_ERR, "Error message: %s", strerror(errno)); - close(new_fd); free(send_my_buffer); - syslog(LOG_DEBUG, "Closed connection from %s", ip4); syslog(LOG_DEBUG, "_________________________________________________________"); } syslog(LOG_DEBUG, "AM I EVER HERE?"); - closeAll(); - - //return 0; + closeAll(EXIT_SUCCESS); } \ No newline at end of file From 8dc4706cf62be7a634ba999a43f8b777d3209345 Mon Sep 17 00:00:00 2001 From: stamrakar Date: Sat, 12 Oct 2024 16:54:00 -0600 Subject: [PATCH 02/17] Threading implemented, need to have a wrapper struct --- server/aesdsocket.c | 301 ++++++++++++++++++++++++++------------------ 1 file changed, 181 insertions(+), 120 deletions(-) diff --git a/server/aesdsocket.c b/server/aesdsocket.c index aefcfdc..8c9561b 100644 --- a/server/aesdsocket.c +++ b/server/aesdsocket.c @@ -46,14 +46,27 @@ #define BACKLOG 10 // pending connections #define BUF_SIZE 1024 - +typedef struct thread_info_s thread_info_t; typedef struct slist_data_s my_threads; -struct slist_data_s { +struct thread_info_s{ + pthread_t threadid; + int afd; //accepted fd psot accept() connection. bool thread_complete_success; - SLIST_ENTRY(slist_data_s) threads; + char ip4[INET_ADDRSTRLEN]; //space to hold the IPv4 string +}; + +struct slist_data_s { + + thread_info_t thread_info; + SLIST_ENTRY(slist_data_s) nextThread; }; +SLIST_HEAD(slisthead, slist_data_s) head; +SLIST_INIT(&head); + + + sig_atomic_t sig = 0; bool daemon_en = false; @@ -66,6 +79,7 @@ const char *recvfile = "/var/tmp/aesdsocketdata"; static void closeAll(int exit_flag); static void init_sigHandler(void); static void signal_handler(int signal_number); +void *threadfunc(void *arg); static void signal_handler (int signal_number) { @@ -162,6 +176,134 @@ void closeAll(int exit_flag) exit(exit_flag); } + +void *threadfunc(void *args) +{ + my_threads *thread_func_args = (my_threads *) args; + bool isPacketValid = false; + ssize_t bytes_rx; + ssize_t bytes_read; + ssize_t supplementBuf = 0; + ssize_t supplementSize = BUF_SIZE; + ssize_t nr; + char *new_line = NULL; + char *my_buffer = (char *) malloc(BUF_SIZE); + char *send_my_buffer = NULL; + + if(my_buffer == NULL) + { + syslog(LOG_ERR, "Failed to malloc."); + closeAll(EXIT_FAILURE); + } + + memset(my_buffer, 0, BUF_SIZE); + do{ + + bytes_rx = recv(new_fd, my_buffer+supplementBuf, BUF_SIZE-1, 0); + syslog(LOG_DEBUG, "I have received %ld bytes", bytes_rx); + if (bytes_rx < 0) + { + free(my_buffer); + perror("server: recv"); + syslog(LOG_ERR, "server: recv"); + closeAll(EXIT_FAILURE); + } + supplementBuf += bytes_rx; + new_line = strchr(my_buffer, '\n'); //if NULL, keep getting packets + if (new_line != NULL) + { + syslog(LOG_DEBUG, "YAY, slash n found"); + isPacketValid = true; + supplementBuf = new_line - my_buffer + 1; + syslog(LOG_DEBUG, "supplementBuf size within slash found %ld", supplementBuf); + } + + else + { + my_buffer = realloc(my_buffer, supplementSize+BUF_SIZE); + if(my_buffer == NULL) + { + syslog(LOG_ERR, "Failed to realloc."); + closeAll(EXIT_FAILURE); + } + supplementSize += BUF_SIZE; + memset(my_buffer+supplementBuf, 0 , supplementSize-supplementBuf); + } + + }while (isPacketValid == false); + + + //new line character has been found + if(isPacketValid == true) + { + //my_buffer[addibuffer]= '\0'; + //ssize_t write_size = new_line - my_buffer + 1; + syslog(LOG_DEBUG, "PACKET SUCCESSFULLY VALIDATED"); + nr = write(recvfile_fd, my_buffer, supplementBuf); + syslog(LOG_DEBUG, "nr is %ld",nr); + if (nr != supplementBuf) + { + /*error*/ + int err1 = errno; + syslog(LOG_ERR, "Failed to write bytes: errno -> %d", err1); + syslog(LOG_ERR, "error string is %s", strerror(errno)); + closeAll(EXIT_FAILURE); + } + + syslog(LOG_DEBUG, "Write completed to recvfile_fd"); + } + + + free(my_buffer); + + if(lseek(recvfile_fd, 0, SEEK_SET) == -1) + { + syslog(LOG_ERR, "server: lseek"); + perror("server: lseek"); + closeAll(EXIT_FAILURE); + } + + syslog(LOG_DEBUG, "lseek pass"); + send_my_buffer = (char *) malloc(supplementBuf); + if (send_my_buffer == NULL) + { + syslog(LOG_ERR, "Failed to malloc sending buffer."); + closeAll(EXIT_FAILURE); + } + + while ((bytes_read = read(recvfile_fd, send_my_buffer, supplementBuf)) > 0) { + syslog(LOG_DEBUG, "bytes_read is %ld", bytes_read); + //syslog(LOG_DEBUG, "bytes_read inside while is %ld", bytes_read); + // for( int i = 0; i < bytes_read; i++) + // { + // syslog(LOG_DEBUG, "%c", send_my_buffer[i]); + // } + + //syslog(LOG_DEBUG, "strlen of send_my_buffer is %ld", strlen(send_my_buffer)); + //syslog(LOG_DEBUG, "new_fd heree is %d", new_fd); + if (send(new_fd, send_my_buffer, bytes_read, 0) != bytes_read) + { + syslog(LOG_DEBUG,"HEREEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"); + syslog(LOG_ERR,"server: send"); + perror("server: send"); + closeAll(EXIT_FAILURE); + } + else + { + syslog(LOG_DEBUG, "send pass"); + } + } + + close(new_fd); + free(send_my_buffer); + free(new_line); + syslog(LOG_DEBUG, "Closed connection from %s", thread_func_args->ip4); + syslog(LOG_DEBUG, "_________________________________________________________"); + + thread_func_args->thread_complete_success = true; + return args; +} + int main(int argc, char *argv[]) { // Setting up syslog logging using LOG_USER facility @@ -265,9 +407,9 @@ int main(int argc, char *argv[]) - ssize_t incrementBy; + ssize_t supplementSize; ssize_t bytes_rx = 0; - ssize_t addibuffer; + ssize_t supplementBuf; ssize_t bytes_read; char *send_my_buffer = NULL; char *new_line = NULL; @@ -276,7 +418,7 @@ int main(int argc, char *argv[]) while(!sig){ bytes_read = 0; - incrementBy = BUF_SIZE; + supplementSize = BUF_SIZE; isPacketValid = false; peer_addrlen = sizeof(peer_addr); if((new_fd = accept(sockfd, (struct sockaddr *)&peer_addr, &peer_addrlen)) == -1 ) @@ -287,137 +429,56 @@ int main(int argc, char *argv[]) } syslog(LOG_DEBUG, "CONNECTED"); - - // int rc; - // rc = pthread_create(threadid, NULL, threadfunc, (void*)new_fd); - // if (rc != 0) - // { - // ERROR_LOG("Failed to pthread_create(), error was %d", rc); - // free(threadp); - // return false; - // } - - - //create thread here ? inet_ntop(AF_INET, &(peer_addr.sin_addr), ip4, sizeof(ip4)); syslog(LOG_DEBUG, "Accepted connection from %s", ip4); - addibuffer = 0; - char *my_buffer = (char *) malloc(BUF_SIZE); - if (my_buffer == NULL) + my_threads *thread_data = (my_threads *)malloc(sizeof(my_threads)); + if (thread_data == NULL) { - syslog(LOG_ERR, "Failed to malloc."); - closeAll(EXIT_FAILURE); - } - memset(my_buffer, 0, BUF_SIZE); - do{ - - bytes_rx = recv(new_fd, my_buffer + addibuffer, BUF_SIZE-1, 0); - syslog(LOG_DEBUG, "i have received %ld bytes", bytes_rx); - if (bytes_rx < 0) - { - free(my_buffer); - perror("server: recv"); - syslog(LOG_ERR, "server: recv"); - closeAll(EXIT_FAILURE); - } - addibuffer += bytes_rx; - new_line = strchr(my_buffer, '\n'); //if NULL, keep getting packets - if (new_line != NULL) - { - syslog(LOG_DEBUG, "YAY, slash n found"); - isPacketValid = true; - addibuffer = new_line - my_buffer + 1; - syslog(LOG_DEBUG, "addibuffer size within slash found %ld", addibuffer); - } - - else - { - my_buffer = realloc(my_buffer, incrementBy+BUF_SIZE); - if(my_buffer == NULL) - { - syslog(LOG_ERR, "Failed to realloc."); - closeAll(EXIT_FAILURE); - } - incrementBy += BUF_SIZE; - memset(my_buffer+addibuffer, 0 , incrementBy-addibuffer); - } - - }while (isPacketValid == false); - - //new line character has been found, now i want to send? - //append happens here, writing - if(isPacketValid == true) - { - //my_buffer[addibuffer]= '\0'; - //ssize_t write_size = new_line - my_buffer + 1; - syslog(LOG_DEBUG, "PACKET SUCCESSFULLY VALIDATED"); - nr = write(recvfile_fd, my_buffer, addibuffer); - syslog(LOG_DEBUG, "nr is %ld",nr); - if (nr != addibuffer) - { - /*error*/ - int err1 = errno; - syslog(LOG_ERR, "Failed to write bytes: errno -> %d", err1); - syslog(LOG_ERR, "error string is %s", strerror(errno)); - closeAll(EXIT_FAILURE); - } - - syslog(LOG_DEBUG, "Write completed to recvfile_fd"); + syslog(LOG_ERR, "server: thread allocation"); + perror("server: thread allocation"); + continue; + //should I be exiting everything here or just keep trying } + thread_data->afd = new_fd; + thread_data->thread_complete_success = false; + strcpy(thread_data->ip4, ip4); - free(my_buffer); - - if(lseek(recvfile_fd, 0, SEEK_SET) == -1) - { - syslog(LOG_ERR, "server: lseek"); - perror("server: lseek"); - closeAll(EXIT_FAILURE); - } + int rc; - syslog(LOG_DEBUG, "lseek pass"); - //syslog(LOG_DEBUG, "addibuffer is %ld", addibuffer); - send_my_buffer = (char *) malloc(addibuffer); - if (send_my_buffer == NULL) + if((rc = pthread_create(&thread_data->threadid, NULL, threadfunc, (void*)thread_data)) != 0) { - syslog(LOG_ERR, "Failed to malloc sending buffer."); - closeAll(EXIT_FAILURE); + syslog("Failed to pthread_create(), error was %d", rc); + perror("Failed to pthread_create()"); + free(thread_data); + close(new_fd); + continue; } - - //int errno_read; - //syslog(LOG_DEBUG, "I am here. Just before the while. addibuffer is %ld, %d", addibuffer, recvfile_fd); - while ((bytes_read = read(recvfile_fd, send_my_buffer, addibuffer)) > 0) { - syslog(LOG_DEBUG, "bytes_read is %ld", bytes_read); - //syslog(LOG_DEBUG, "bytes_read inside while is %ld", bytes_read); - // for( int i = 0; i < bytes_read; i++) - // { - // syslog(LOG_DEBUG, "%c", send_my_buffer[i]); - // } - - //syslog(LOG_DEBUG, "strlen of send_my_buffer is %ld", strlen(send_my_buffer)); - //syslog(LOG_DEBUG, "new_fd heree is %d", new_fd); - if (send(new_fd, send_my_buffer, bytes_read, 0) != bytes_read) + SLIST_INSERT_HEAD(&head, thread_data, nextThread); + int join_rc; + my_threads *datap = NULL; + SLIST_FOREACH(datap, &head, nextThread) { + if(datap->thread_complete_success) { - syslog(LOG_DEBUG,"HEREEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"); - syslog(LOG_ERR,"server: send"); - perror("server: send"); - closeAll(EXIT_FAILURE); - } - else - { - syslog(LOG_DEBUG, "send pass"); + join_rc = pthread_join(datap->threadid, NULL); + if(join_rc != 0) + { + syslog(LOG_ERR, "Failed to pthread_join(), error was %d", join_rc); + perror("Failed to pthread_join()"); + continue; + } + SLIST_REMOVE(&head, datap, my_threads, nextThread); + free(datap); } + } - close(new_fd); - free(send_my_buffer); - syslog(LOG_DEBUG, "Closed connection from %s", ip4); - syslog(LOG_DEBUG, "_________________________________________________________"); } - syslog(LOG_DEBUG, "AM I EVER HERE?"); + syslog(LOG_DEBUG, "Do I reach here?"); closeAll(EXIT_SUCCESS); + return 0; } \ No newline at end of file From d40d5b313f4414825acc90fd0b94bd16793c7bcb Mon Sep 17 00:00:00 2001 From: stamrakar Date: Sat, 12 Oct 2024 18:28:21 -0600 Subject: [PATCH 03/17] threading not quite working --- server/Makefile | 2 +- server/aesdsocket.c | 77 ++++++++++++++++++++++++++++----------------- 2 files changed, 49 insertions(+), 30 deletions(-) diff --git a/server/Makefile b/server/Makefile index d116e52..65aaf51 100644 --- a/server/Makefile +++ b/server/Makefile @@ -32,7 +32,7 @@ clean: -rm -f aesdsocket aesdsocket: ${OBJS} - $(CROSS_COMPILE)$(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) + $(CROSS_COMPILE)$(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) -pthread depend: diff --git a/server/aesdsocket.c b/server/aesdsocket.c index 8c9561b..baa1400 100644 --- a/server/aesdsocket.c +++ b/server/aesdsocket.c @@ -48,6 +48,8 @@ typedef struct thread_info_s thread_info_t; typedef struct slist_data_s my_threads; +pthread_mutex_t writeSocket; + struct thread_info_s{ pthread_t threadid; @@ -63,7 +65,7 @@ struct slist_data_s { }; SLIST_HEAD(slisthead, slist_data_s) head; -SLIST_INIT(&head); + @@ -186,6 +188,7 @@ void *threadfunc(void *args) ssize_t supplementBuf = 0; ssize_t supplementSize = BUF_SIZE; ssize_t nr; + int rc; char *new_line = NULL; char *my_buffer = (char *) malloc(BUF_SIZE); char *send_my_buffer = NULL; @@ -236,10 +239,25 @@ void *threadfunc(void *args) //new line character has been found if(isPacketValid == true) { - //my_buffer[addibuffer]= '\0'; - //ssize_t write_size = new_line - my_buffer + 1; syslog(LOG_DEBUG, "PACKET SUCCESSFULLY VALIDATED"); + + rc = pthread_mutex_lock(&writeSocket); + if (rc != 0) + { + syslog(LOG_ERR, "pthread_mutex_lock failed, error was %d", rc); + perror("pthread mutex_lock failed"); + } + + nr = write(recvfile_fd, my_buffer, supplementBuf); + + rc = pthread_mutex_unlock(&writeSocket); + if (rc != 0) + { + syslog(LOG_ERR, "pthread_mutex_unlock failed, error was %d", rc); + perror("pthread mutex_unlock failed"); + } + syslog(LOG_DEBUG, "nr is %ld",nr); if (nr != supplementBuf) { @@ -255,6 +273,7 @@ void *threadfunc(void *args) free(my_buffer); + if(lseek(recvfile_fd, 0, SEEK_SET) == -1) { @@ -290,17 +309,19 @@ void *threadfunc(void *args) } else { - syslog(LOG_DEBUG, "send pass"); + syslog(LOG_DEBUG, "send passed"); } } + + syslog(LOG_DEBUG, "This here"); + syslog(LOG_DEBUG, "Closed connection from %s", thread_func_args->thread_info.ip4); + syslog(LOG_DEBUG, "_________________________________________________________"); + thread_func_args->thread_info.thread_complete_success = true; close(new_fd); free(send_my_buffer); free(new_line); - syslog(LOG_DEBUG, "Closed connection from %s", thread_func_args->ip4); - syslog(LOG_DEBUG, "_________________________________________________________"); - - thread_func_args->thread_complete_success = true; + syslog(LOG_DEBUG, "FINISHE"); return args; } @@ -318,7 +339,8 @@ int main(int argc, char *argv[]) struct sockaddr_in peer_addr; char ip4[INET_ADDRSTRLEN]; //space to hold the IPv4 string int yes=1; - + SLIST_INIT(&head); + pthread_mutex_init(&writeSocket, NULL); //Initializes the signal handlers SIGINT and SIGTERM init_sigHandler(); @@ -407,19 +429,8 @@ int main(int argc, char *argv[]) - ssize_t supplementSize; - ssize_t bytes_rx = 0; - ssize_t supplementBuf; - ssize_t bytes_read; - char *send_my_buffer = NULL; - char *new_line = NULL; - ssize_t nr; - bool isPacketValid = false; - while(!sig){ - bytes_read = 0; - supplementSize = BUF_SIZE; - isPacketValid = false; + peer_addrlen = sizeof(peer_addr); if((new_fd = accept(sockfd, (struct sockaddr *)&peer_addr, &peer_addrlen)) == -1 ) { @@ -441,36 +452,44 @@ int main(int argc, char *argv[]) continue; //should I be exiting everything here or just keep trying } + + - thread_data->afd = new_fd; - thread_data->thread_complete_success = false; - strcpy(thread_data->ip4, ip4); + thread_data->thread_info.afd = new_fd; + thread_data->thread_info.thread_complete_success = false; + strcpy(thread_data->thread_info.ip4, ip4); int rc; - if((rc = pthread_create(&thread_data->threadid, NULL, threadfunc, (void*)thread_data)) != 0) + if((rc = pthread_create(&thread_data->thread_info.threadid, NULL, threadfunc, &(thread_data->thread_info))) != 0) { - syslog("Failed to pthread_create(), error was %d", rc); + syslog(LOG_ERR, "Failed to pthread_create(), error was %d", rc); perror("Failed to pthread_create()"); free(thread_data); close(new_fd); continue; } + else + { + syslog(LOG_DEBUG, "pthread_created successfully"); + } + SLIST_INSERT_HEAD(&head, thread_data, nextThread); int join_rc; my_threads *datap = NULL; SLIST_FOREACH(datap, &head, nextThread) { - if(datap->thread_complete_success) + if(datap->thread_info.thread_complete_success) { - join_rc = pthread_join(datap->threadid, NULL); + join_rc = pthread_join(datap->thread_info.threadid, NULL); if(join_rc != 0) { syslog(LOG_ERR, "Failed to pthread_join(), error was %d", join_rc); perror("Failed to pthread_join()"); continue; } - SLIST_REMOVE(&head, datap, my_threads, nextThread); + syslog(LOG_DEBUG, "Joined"); + SLIST_REMOVE(&head, datap, slist_data_s, nextThread); free(datap); } From 9b93bd642ab279de0e7174c4d7820bf9322fa308 Mon Sep 17 00:00:00 2001 From: stamrakar Date: Sun, 13 Oct 2024 13:04:04 -0600 Subject: [PATCH 04/17] race conditions exist --- server/aesdsocket.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/server/aesdsocket.c b/server/aesdsocket.c index baa1400..545204d 100644 --- a/server/aesdsocket.c +++ b/server/aesdsocket.c @@ -182,6 +182,7 @@ void closeAll(int exit_flag) void *threadfunc(void *args) { my_threads *thread_func_args = (my_threads *) args; + syslog(LOG_DEBUG, "I have entered this thread with threadID = %lu", thread_func_args->thread_info.threadid); bool isPacketValid = false; ssize_t bytes_rx; ssize_t bytes_read; @@ -309,20 +310,18 @@ void *threadfunc(void *args) } else { + free(send_my_buffer); syslog(LOG_DEBUG, "send passed"); } } - syslog(LOG_DEBUG, "This here"); + syslog(LOG_DEBUG, "Closed connection from %s", thread_func_args->thread_info.ip4); syslog(LOG_DEBUG, "_________________________________________________________"); thread_func_args->thread_info.thread_complete_success = true; close(new_fd); - free(send_my_buffer); - free(new_line); - syslog(LOG_DEBUG, "FINISHE"); - return args; + pthread_exit(NULL); } int main(int argc, char *argv[]) @@ -473,11 +472,12 @@ int main(int argc, char *argv[]) else { syslog(LOG_DEBUG, "pthread_created successfully"); + syslog(LOG_DEBUG, "The threadID is %lu.", thread_data->thread_info.threadid); } SLIST_INSERT_HEAD(&head, thread_data, nextThread); int join_rc; - my_threads *datap = NULL; + my_threads *datap, *temp; SLIST_FOREACH(datap, &head, nextThread) { if(datap->thread_info.thread_complete_success) { @@ -489,12 +489,18 @@ int main(int argc, char *argv[]) continue; } syslog(LOG_DEBUG, "Joined"); + + temp = SLIST_NEXT(datap, nextThread); SLIST_REMOVE(&head, datap, slist_data_s, nextThread); free(datap); + datap = temp; + } + else + { + syslog(LOG_DEBUG, "I did not join on threadID = %lu", thread_data->thread_info.threadid); } } - } syslog(LOG_DEBUG, "Do I reach here?"); From 9f9b1b9575f7214d015da9e3e57a0679726444a4 Mon Sep 17 00:00:00 2001 From: stamrakar Date: Sun, 13 Oct 2024 17:43:29 -0600 Subject: [PATCH 05/17] using SLIST_FOREACH_SAFE instead --- server/aesdsocket.c | 86 +++-- server/queue.h | 787 ++++++++++++++++++++++++++++++++++++++++ server/valgrind-out.txt | 282 ++++++++------ 3 files changed, 1005 insertions(+), 150 deletions(-) create mode 100644 server/queue.h diff --git a/server/aesdsocket.c b/server/aesdsocket.c index 545204d..9c6322b 100644 --- a/server/aesdsocket.c +++ b/server/aesdsocket.c @@ -37,7 +37,8 @@ #include #include #include -#include +//#include +#include "queue.h" #define PORT "9000" // the port users will be connecting to //const char* port = "9000"; @@ -48,7 +49,7 @@ typedef struct thread_info_s thread_info_t; typedef struct slist_data_s my_threads; -pthread_mutex_t writeSocket; +pthread_mutex_t writeSocket = PTHREAD_MUTEX_INITIALIZER; struct thread_info_s{ @@ -173,6 +174,7 @@ void closeAll(int exit_flag) { syslog(LOG_ERR, "File removal not successful"); } + pthread_mutex_destroy(&writeSocket); syslog(LOG_DEBUG, "CLEANUP COMPLETED."); closelog(); exit(exit_flag); @@ -201,6 +203,7 @@ void *threadfunc(void *args) } memset(my_buffer, 0, BUF_SIZE); + do{ bytes_rx = recv(new_fd, my_buffer+supplementBuf, BUF_SIZE-1, 0); @@ -237,19 +240,20 @@ void *threadfunc(void *args) }while (isPacketValid == false); + //new line character has been found if(isPacketValid == true) { syslog(LOG_DEBUG, "PACKET SUCCESSFULLY VALIDATED"); + + rc = pthread_mutex_lock(&writeSocket); if (rc != 0) { syslog(LOG_ERR, "pthread_mutex_lock failed, error was %d", rc); perror("pthread mutex_lock failed"); } - - nr = write(recvfile_fd, my_buffer, supplementBuf); rc = pthread_mutex_unlock(&writeSocket); @@ -270,57 +274,73 @@ void *threadfunc(void *args) } syslog(LOG_DEBUG, "Write completed to recvfile_fd"); + } free(my_buffer); + my_buffer = NULL; + + + send_my_buffer = (char *) malloc(supplementBuf); + if (send_my_buffer == NULL) + { + syslog(LOG_ERR, "Failed to malloc sending buffer."); + closeAll(EXIT_FAILURE); + } + + rc = pthread_mutex_lock(&writeSocket); + if (rc != 0) + { + syslog(LOG_ERR, "pthread_mutex_lock failed, error was %d", rc); + perror("pthread mutex_lock failed"); + } + if(lseek(recvfile_fd, 0, SEEK_SET) == -1) { syslog(LOG_ERR, "server: lseek"); perror("server: lseek"); closeAll(EXIT_FAILURE); } - syslog(LOG_DEBUG, "lseek pass"); - send_my_buffer = (char *) malloc(supplementBuf); - if (send_my_buffer == NULL) - { - syslog(LOG_ERR, "Failed to malloc sending buffer."); - closeAll(EXIT_FAILURE); - } + while ((bytes_read = read(recvfile_fd, send_my_buffer, supplementBuf)) > 0) { syslog(LOG_DEBUG, "bytes_read is %ld", bytes_read); - //syslog(LOG_DEBUG, "bytes_read inside while is %ld", bytes_read); - // for( int i = 0; i < bytes_read; i++) - // { - // syslog(LOG_DEBUG, "%c", send_my_buffer[i]); - // } - - //syslog(LOG_DEBUG, "strlen of send_my_buffer is %ld", strlen(send_my_buffer)); - //syslog(LOG_DEBUG, "new_fd heree is %d", new_fd); if (send(new_fd, send_my_buffer, bytes_read, 0) != bytes_read) { syslog(LOG_DEBUG,"HEREEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"); syslog(LOG_ERR,"server: send"); + rc = pthread_mutex_unlock(&writeSocket); + if (rc != 0) + { + syslog(LOG_ERR, "pthread_mutex_unlock failed, error was %d", rc); + perror("pthread mutex_unlock failed"); + } perror("server: send"); closeAll(EXIT_FAILURE); } else { - free(send_my_buffer); syslog(LOG_DEBUG, "send passed"); + free(send_my_buffer); + send_my_buffer = NULL; } } + rc = pthread_mutex_unlock(&writeSocket); + if (rc != 0) + { + syslog(LOG_ERR, "pthread_mutex_unlock failed, error was %d", rc); + perror("pthread mutex_unlock failed"); + } - - syslog(LOG_DEBUG, "Closed connection from %s", thread_func_args->thread_info.ip4); syslog(LOG_DEBUG, "_________________________________________________________"); thread_func_args->thread_info.thread_complete_success = true; close(new_fd); + syslog(LOG_DEBUG, "About to exit thread ID = %lu", thread_func_args->thread_info.threadid); pthread_exit(NULL); } @@ -339,7 +359,7 @@ int main(int argc, char *argv[]) char ip4[INET_ADDRSTRLEN]; //space to hold the IPv4 string int yes=1; SLIST_INIT(&head); - pthread_mutex_init(&writeSocket, NULL); + //pthread_mutex_init(&writeSocket, NULL); //Initializes the signal handlers SIGINT and SIGTERM init_sigHandler(); @@ -438,7 +458,7 @@ int main(int argc, char *argv[]) continue; } - syslog(LOG_DEBUG, "CONNECTED"); + syslog(LOG_DEBUG, "CONNECTED, new_fd is %d", new_fd); inet_ntop(AF_INET, &(peer_addr.sin_addr), ip4, sizeof(ip4)); syslog(LOG_DEBUG, "Accepted connection from %s", ip4); @@ -460,7 +480,7 @@ int main(int argc, char *argv[]) int rc; - if((rc = pthread_create(&thread_data->thread_info.threadid, NULL, threadfunc, &(thread_data->thread_info))) != 0) + if((rc = pthread_create(&thread_data->thread_info.threadid, NULL, threadfunc, (void*) &(thread_data->thread_info))) != 0) { syslog(LOG_ERR, "Failed to pthread_create(), error was %d", rc); perror("Failed to pthread_create()"); @@ -477,8 +497,11 @@ int main(int argc, char *argv[]) SLIST_INSERT_HEAD(&head, thread_data, nextThread); int join_rc; - my_threads *datap, *temp; - SLIST_FOREACH(datap, &head, nextThread) { + my_threads *datap = NULL; + my_threads *temp = NULL; + + SLIST_FOREACH_SAFE(datap, &head, nextThread, temp) + { if(datap->thread_info.thread_complete_success) { join_rc = pthread_join(datap->thread_info.threadid, NULL); @@ -488,18 +511,15 @@ int main(int argc, char *argv[]) perror("Failed to pthread_join()"); continue; } - syslog(LOG_DEBUG, "Joined"); - - temp = SLIST_NEXT(datap, nextThread); + syslog(LOG_DEBUG, "Joined thread %lu", datap->thread_info.threadid); SLIST_REMOVE(&head, datap, slist_data_s, nextThread); free(datap); - datap = temp; + datap = NULL; } else { - syslog(LOG_DEBUG, "I did not join on threadID = %lu", thread_data->thread_info.threadid); + syslog(LOG_DEBUG, "I did not join on threadID = %lu", datap->thread_info.threadid); } - } } diff --git a/server/queue.h b/server/queue.h new file mode 100644 index 0000000..6d6b195 --- /dev/null +++ b/server/queue.h @@ -0,0 +1,787 @@ +/*- + * Copyright (c) 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)queue.h 8.5 (Berkeley) 8/20/94 + * $FreeBSD$ + */ + +#ifndef _SYS_QUEUE_H_ +#define _SYS_QUEUE_H_ + +#include + +/* + * This file defines four types of data structures: singly-linked lists, + * singly-linked tail queues, lists and tail queues. + * + * A singly-linked list is headed by a single forward pointer. The elements + * are singly linked for minimum space and pointer manipulation overhead at + * the expense of O(n) removal for arbitrary elements. New elements can be + * added to the list after an existing element or at the head of the list. + * Elements being removed from the head of the list should use the explicit + * macro for this purpose for optimum efficiency. A singly-linked list may + * only be traversed in the forward direction. Singly-linked lists are ideal + * for applications with large datasets and few or no removals or for + * implementing a LIFO queue. + * + * A singly-linked tail queue is headed by a pair of pointers, one to the + * head of the list and the other to the tail of the list. The elements are + * singly linked for minimum space and pointer manipulation overhead at the + * expense of O(n) removal for arbitrary elements. New elements can be added + * to the list after an existing element, at the head of the list, or at the + * end of the list. Elements being removed from the head of the tail queue + * should use the explicit macro for this purpose for optimum efficiency. + * A singly-linked tail queue may only be traversed in the forward direction. + * Singly-linked tail queues are ideal for applications with large datasets + * and few or no removals or for implementing a FIFO queue. + * + * A list is headed by a single forward pointer (or an array of forward + * pointers for a hash table header). The elements are doubly linked + * so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before + * or after an existing element or at the head of the list. A list + * may be traversed in either direction. + * + * A tail queue is headed by a pair of pointers, one to the head of the + * list and the other to the tail of the list. The elements are doubly + * linked so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before or + * after an existing element, at the head of the list, or at the end of + * the list. A tail queue may be traversed in either direction. + * + * For details on the use of these macros, see the queue(3) manual page. + * + * Below is a summary of implemented functions where: + * + means the macro is available + * - means the macro is not available + * s means the macro is available but is slow (runs in O(n) time) + * + * SLIST LIST STAILQ TAILQ + * _HEAD + + + + + * _CLASS_HEAD + + + + + * _HEAD_INITIALIZER + + + + + * _ENTRY + + + + + * _CLASS_ENTRY + + + + + * _INIT + + + + + * _EMPTY + + + + + * _FIRST + + + + + * _NEXT + + + + + * _PREV - + - + + * _LAST - - + + + * _FOREACH + + + + + * _FOREACH_FROM + + + + + * _FOREACH_SAFE + + + + + * _FOREACH_FROM_SAFE + + + + + * _FOREACH_REVERSE - - - + + * _FOREACH_REVERSE_FROM - - - + + * _FOREACH_REVERSE_SAFE - - - + + * _FOREACH_REVERSE_FROM_SAFE - - - + + * _INSERT_HEAD + + + + + * _INSERT_BEFORE - + - + + * _INSERT_AFTER + + + + + * _INSERT_TAIL - - + + + * _CONCAT s s + + + * _REMOVE_AFTER + - + - + * _REMOVE_HEAD + - + - + * _REMOVE s + s + + * _SWAP + + + + + * + */ +#ifdef QUEUE_MACRO_DEBUG +/* Store the last 2 places the queue element or head was altered */ +struct qm_trace { + unsigned long lastline; + unsigned long prevline; + const char *lastfile; + const char *prevfile; +}; + +#define TRACEBUF struct qm_trace trace; +#define TRACEBUF_INITIALIZER { __LINE__, 0, __FILE__, NULL } , +#define TRASHIT(x) do {(x) = (void *)-1;} while (0) +#define QMD_SAVELINK(name, link) void **name = (void *)&(link) + +#define QMD_TRACE_HEAD(head) do { \ + (head)->trace.prevline = (head)->trace.lastline; \ + (head)->trace.prevfile = (head)->trace.lastfile; \ + (head)->trace.lastline = __LINE__; \ + (head)->trace.lastfile = __FILE__; \ +} while (0) + +#define QMD_TRACE_ELEM(elem) do { \ + (elem)->trace.prevline = (elem)->trace.lastline; \ + (elem)->trace.prevfile = (elem)->trace.lastfile; \ + (elem)->trace.lastline = __LINE__; \ + (elem)->trace.lastfile = __FILE__; \ +} while (0) + +#else +#define QMD_TRACE_ELEM(elem) +#define QMD_TRACE_HEAD(head) +#define QMD_SAVELINK(name, link) +#define TRACEBUF +#define TRACEBUF_INITIALIZER +#define TRASHIT(x) +#endif /* QUEUE_MACRO_DEBUG */ + +#ifdef __cplusplus +/* + * In C++ there can be structure lists and class lists: + */ +#define QUEUE_TYPEOF(type) type +#else +#define QUEUE_TYPEOF(type) struct type +#endif + +/* + * Singly-linked List declarations. + */ +#define SLIST_HEAD(name, type) \ +struct name { \ + struct type *slh_first; /* first element */ \ +} + +#define SLIST_CLASS_HEAD(name, type) \ +struct name { \ + class type *slh_first; /* first element */ \ +} + +#define SLIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define SLIST_ENTRY(type) \ +struct { \ + struct type *sle_next; /* next element */ \ +} + +#define SLIST_CLASS_ENTRY(type) \ +struct { \ + class type *sle_next; /* next element */ \ +} + +/* + * Singly-linked List functions. + */ +#define SLIST_CONCAT(head1, head2, type, field) do { \ + QUEUE_TYPEOF(type) *curelm = SLIST_FIRST(head1); \ + if (curelm == NULL) { \ + if ((SLIST_FIRST(head1) = SLIST_FIRST(head2)) != NULL) \ + SLIST_INIT(head2); \ + } else if (SLIST_FIRST(head2) != NULL) { \ + while (SLIST_NEXT(curelm, field) != NULL) \ + curelm = SLIST_NEXT(curelm, field); \ + SLIST_NEXT(curelm, field) = SLIST_FIRST(head2); \ + SLIST_INIT(head2); \ + } \ +} while (0) + +#define SLIST_EMPTY(head) ((head)->slh_first == NULL) + +#define SLIST_FIRST(head) ((head)->slh_first) + +#define SLIST_FOREACH(var, head, field) \ + for ((var) = SLIST_FIRST((head)); \ + (var); \ + (var) = SLIST_NEXT((var), field)) + +#define SLIST_FOREACH_FROM(var, head, field) \ + for ((var) = ((var) ? (var) : SLIST_FIRST((head))); \ + (var); \ + (var) = SLIST_NEXT((var), field)) + +#define SLIST_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = SLIST_FIRST((head)); \ + (var) && ((tvar) = SLIST_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define SLIST_FOREACH_FROM_SAFE(var, head, field, tvar) \ + for ((var) = ((var) ? (var) : SLIST_FIRST((head))); \ + (var) && ((tvar) = SLIST_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define SLIST_FOREACH_PREVPTR(var, varp, head, field) \ + for ((varp) = &SLIST_FIRST((head)); \ + ((var) = *(varp)) != NULL; \ + (varp) = &SLIST_NEXT((var), field)) + +#define SLIST_INIT(head) do { \ + SLIST_FIRST((head)) = NULL; \ +} while (0) + +#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \ + SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field); \ + SLIST_NEXT((slistelm), field) = (elm); \ +} while (0) + +#define SLIST_INSERT_HEAD(head, elm, field) do { \ + SLIST_NEXT((elm), field) = SLIST_FIRST((head)); \ + SLIST_FIRST((head)) = (elm); \ +} while (0) + +#define SLIST_NEXT(elm, field) ((elm)->field.sle_next) + +#define SLIST_REMOVE(head, elm, type, field) do { \ + QMD_SAVELINK(oldnext, (elm)->field.sle_next); \ + if (SLIST_FIRST((head)) == (elm)) { \ + SLIST_REMOVE_HEAD((head), field); \ + } \ + else { \ + QUEUE_TYPEOF(type) *curelm = SLIST_FIRST(head); \ + while (SLIST_NEXT(curelm, field) != (elm)) \ + curelm = SLIST_NEXT(curelm, field); \ + SLIST_REMOVE_AFTER(curelm, field); \ + } \ + TRASHIT(*oldnext); \ +} while (0) + +#define SLIST_REMOVE_AFTER(elm, field) do { \ + SLIST_NEXT(elm, field) = \ + SLIST_NEXT(SLIST_NEXT(elm, field), field); \ +} while (0) + +#define SLIST_REMOVE_HEAD(head, field) do { \ + SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \ +} while (0) + +#define SLIST_SWAP(head1, head2, type) do { \ + QUEUE_TYPEOF(type) *swap_first = SLIST_FIRST(head1); \ + SLIST_FIRST(head1) = SLIST_FIRST(head2); \ + SLIST_FIRST(head2) = swap_first; \ +} while (0) + +/* + * Singly-linked Tail queue declarations. + */ +#define STAILQ_HEAD(name, type) \ +struct name { \ + struct type *stqh_first;/* first element */ \ + struct type **stqh_last;/* addr of last next element */ \ +} + +#define STAILQ_CLASS_HEAD(name, type) \ +struct name { \ + class type *stqh_first; /* first element */ \ + class type **stqh_last; /* addr of last next element */ \ +} + +#define STAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).stqh_first } + +#define STAILQ_ENTRY(type) \ +struct { \ + struct type *stqe_next; /* next element */ \ +} + +#define STAILQ_CLASS_ENTRY(type) \ +struct { \ + class type *stqe_next; /* next element */ \ +} + +/* + * Singly-linked Tail queue functions. + */ +#define STAILQ_CONCAT(head1, head2) do { \ + if (!STAILQ_EMPTY((head2))) { \ + *(head1)->stqh_last = (head2)->stqh_first; \ + (head1)->stqh_last = (head2)->stqh_last; \ + STAILQ_INIT((head2)); \ + } \ +} while (0) + +#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL) + +#define STAILQ_FIRST(head) ((head)->stqh_first) + +#define STAILQ_FOREACH(var, head, field) \ + for((var) = STAILQ_FIRST((head)); \ + (var); \ + (var) = STAILQ_NEXT((var), field)) + +#define STAILQ_FOREACH_FROM(var, head, field) \ + for ((var) = ((var) ? (var) : STAILQ_FIRST((head))); \ + (var); \ + (var) = STAILQ_NEXT((var), field)) + +#define STAILQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = STAILQ_FIRST((head)); \ + (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define STAILQ_FOREACH_FROM_SAFE(var, head, field, tvar) \ + for ((var) = ((var) ? (var) : STAILQ_FIRST((head))); \ + (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define STAILQ_INIT(head) do { \ + STAILQ_FIRST((head)) = NULL; \ + (head)->stqh_last = &STAILQ_FIRST((head)); \ +} while (0) + +#define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \ + if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ + STAILQ_NEXT((tqelm), field) = (elm); \ +} while (0) + +#define STAILQ_INSERT_HEAD(head, elm, field) do { \ + if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ + STAILQ_FIRST((head)) = (elm); \ +} while (0) + +#define STAILQ_INSERT_TAIL(head, elm, field) do { \ + STAILQ_NEXT((elm), field) = NULL; \ + *(head)->stqh_last = (elm); \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ +} while (0) + +#define STAILQ_LAST(head, type, field) \ + (STAILQ_EMPTY((head)) ? NULL : \ + __containerof((head)->stqh_last, \ + QUEUE_TYPEOF(type), field.stqe_next)) + +#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next) + +#define STAILQ_REMOVE(head, elm, type, field) do { \ + QMD_SAVELINK(oldnext, (elm)->field.stqe_next); \ + if (STAILQ_FIRST((head)) == (elm)) { \ + STAILQ_REMOVE_HEAD((head), field); \ + } \ + else { \ + QUEUE_TYPEOF(type) *curelm = STAILQ_FIRST(head); \ + while (STAILQ_NEXT(curelm, field) != (elm)) \ + curelm = STAILQ_NEXT(curelm, field); \ + STAILQ_REMOVE_AFTER(head, curelm, field); \ + } \ + TRASHIT(*oldnext); \ +} while (0) + +#define STAILQ_REMOVE_AFTER(head, elm, field) do { \ + if ((STAILQ_NEXT(elm, field) = \ + STAILQ_NEXT(STAILQ_NEXT(elm, field), field)) == NULL) \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ +} while (0) + +#define STAILQ_REMOVE_HEAD(head, field) do { \ + if ((STAILQ_FIRST((head)) = \ + STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \ + (head)->stqh_last = &STAILQ_FIRST((head)); \ +} while (0) + +#define STAILQ_SWAP(head1, head2, type) do { \ + QUEUE_TYPEOF(type) *swap_first = STAILQ_FIRST(head1); \ + QUEUE_TYPEOF(type) **swap_last = (head1)->stqh_last; \ + STAILQ_FIRST(head1) = STAILQ_FIRST(head2); \ + (head1)->stqh_last = (head2)->stqh_last; \ + STAILQ_FIRST(head2) = swap_first; \ + (head2)->stqh_last = swap_last; \ + if (STAILQ_EMPTY(head1)) \ + (head1)->stqh_last = &STAILQ_FIRST(head1); \ + if (STAILQ_EMPTY(head2)) \ + (head2)->stqh_last = &STAILQ_FIRST(head2); \ +} while (0) + + +/* + * List declarations. + */ +#define LIST_HEAD(name, type) \ +struct name { \ + struct type *lh_first; /* first element */ \ +} + +#define LIST_CLASS_HEAD(name, type) \ +struct name { \ + class type *lh_first; /* first element */ \ +} + +#define LIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define LIST_ENTRY(type) \ +struct { \ + struct type *le_next; /* next element */ \ + struct type **le_prev; /* address of previous next element */ \ +} + +#define LIST_CLASS_ENTRY(type) \ +struct { \ + class type *le_next; /* next element */ \ + class type **le_prev; /* address of previous next element */ \ +} + +/* + * List functions. + */ + +#if (defined(_KERNEL) && defined(INVARIANTS)) +#define QMD_LIST_CHECK_HEAD(head, field) do { \ + if (LIST_FIRST((head)) != NULL && \ + LIST_FIRST((head))->field.le_prev != \ + &LIST_FIRST((head))) \ + panic("Bad list head %p first->prev != head", (head)); \ +} while (0) + +#define QMD_LIST_CHECK_NEXT(elm, field) do { \ + if (LIST_NEXT((elm), field) != NULL && \ + LIST_NEXT((elm), field)->field.le_prev != \ + &((elm)->field.le_next)) \ + panic("Bad link elm %p next->prev != elm", (elm)); \ +} while (0) + +#define QMD_LIST_CHECK_PREV(elm, field) do { \ + if (*(elm)->field.le_prev != (elm)) \ + panic("Bad link elm %p prev->next != elm", (elm)); \ +} while (0) +#else +#define QMD_LIST_CHECK_HEAD(head, field) +#define QMD_LIST_CHECK_NEXT(elm, field) +#define QMD_LIST_CHECK_PREV(elm, field) +#endif /* (_KERNEL && INVARIANTS) */ + +#define LIST_CONCAT(head1, head2, type, field) do { \ + QUEUE_TYPEOF(type) *curelm = LIST_FIRST(head1); \ + if (curelm == NULL) { \ + if ((LIST_FIRST(head1) = LIST_FIRST(head2)) != NULL) { \ + LIST_FIRST(head2)->field.le_prev = \ + &LIST_FIRST((head1)); \ + LIST_INIT(head2); \ + } \ + } else if (LIST_FIRST(head2) != NULL) { \ + while (LIST_NEXT(curelm, field) != NULL) \ + curelm = LIST_NEXT(curelm, field); \ + LIST_NEXT(curelm, field) = LIST_FIRST(head2); \ + LIST_FIRST(head2)->field.le_prev = &LIST_NEXT(curelm, field); \ + LIST_INIT(head2); \ + } \ +} while (0) + +#define LIST_EMPTY(head) ((head)->lh_first == NULL) + +#define LIST_FIRST(head) ((head)->lh_first) + +#define LIST_FOREACH(var, head, field) \ + for ((var) = LIST_FIRST((head)); \ + (var); \ + (var) = LIST_NEXT((var), field)) + +#define LIST_FOREACH_FROM(var, head, field) \ + for ((var) = ((var) ? (var) : LIST_FIRST((head))); \ + (var); \ + (var) = LIST_NEXT((var), field)) + +#define LIST_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = LIST_FIRST((head)); \ + (var) && ((tvar) = LIST_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define LIST_FOREACH_FROM_SAFE(var, head, field, tvar) \ + for ((var) = ((var) ? (var) : LIST_FIRST((head))); \ + (var) && ((tvar) = LIST_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define LIST_INIT(head) do { \ + LIST_FIRST((head)) = NULL; \ +} while (0) + +#define LIST_INSERT_AFTER(listelm, elm, field) do { \ + QMD_LIST_CHECK_NEXT(listelm, field); \ + if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\ + LIST_NEXT((listelm), field)->field.le_prev = \ + &LIST_NEXT((elm), field); \ + LIST_NEXT((listelm), field) = (elm); \ + (elm)->field.le_prev = &LIST_NEXT((listelm), field); \ +} while (0) + +#define LIST_INSERT_BEFORE(listelm, elm, field) do { \ + QMD_LIST_CHECK_PREV(listelm, field); \ + (elm)->field.le_prev = (listelm)->field.le_prev; \ + LIST_NEXT((elm), field) = (listelm); \ + *(listelm)->field.le_prev = (elm); \ + (listelm)->field.le_prev = &LIST_NEXT((elm), field); \ +} while (0) + +#define LIST_INSERT_HEAD(head, elm, field) do { \ + QMD_LIST_CHECK_HEAD((head), field); \ + if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \ + LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\ + LIST_FIRST((head)) = (elm); \ + (elm)->field.le_prev = &LIST_FIRST((head)); \ +} while (0) + +#define LIST_NEXT(elm, field) ((elm)->field.le_next) + +#define LIST_PREV(elm, head, type, field) \ + ((elm)->field.le_prev == &LIST_FIRST((head)) ? NULL : \ + __containerof((elm)->field.le_prev, \ + QUEUE_TYPEOF(type), field.le_next)) + +#define LIST_REMOVE(elm, field) do { \ + QMD_SAVELINK(oldnext, (elm)->field.le_next); \ + QMD_SAVELINK(oldprev, (elm)->field.le_prev); \ + QMD_LIST_CHECK_NEXT(elm, field); \ + QMD_LIST_CHECK_PREV(elm, field); \ + if (LIST_NEXT((elm), field) != NULL) \ + LIST_NEXT((elm), field)->field.le_prev = \ + (elm)->field.le_prev; \ + *(elm)->field.le_prev = LIST_NEXT((elm), field); \ + TRASHIT(*oldnext); \ + TRASHIT(*oldprev); \ +} while (0) + +#define LIST_SWAP(head1, head2, type, field) do { \ + QUEUE_TYPEOF(type) *swap_tmp = LIST_FIRST(head1); \ + LIST_FIRST((head1)) = LIST_FIRST((head2)); \ + LIST_FIRST((head2)) = swap_tmp; \ + if ((swap_tmp = LIST_FIRST((head1))) != NULL) \ + swap_tmp->field.le_prev = &LIST_FIRST((head1)); \ + if ((swap_tmp = LIST_FIRST((head2))) != NULL) \ + swap_tmp->field.le_prev = &LIST_FIRST((head2)); \ +} while (0) + +/* + * Tail queue declarations. + */ +#define TAILQ_HEAD(name, type) \ +struct name { \ + struct type *tqh_first; /* first element */ \ + struct type **tqh_last; /* addr of last next element */ \ + TRACEBUF \ +} + +#define TAILQ_CLASS_HEAD(name, type) \ +struct name { \ + class type *tqh_first; /* first element */ \ + class type **tqh_last; /* addr of last next element */ \ + TRACEBUF \ +} + +#define TAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).tqh_first, TRACEBUF_INITIALIZER } + +#define TAILQ_ENTRY(type) \ +struct { \ + struct type *tqe_next; /* next element */ \ + struct type **tqe_prev; /* address of previous next element */ \ + TRACEBUF \ +} + +#define TAILQ_CLASS_ENTRY(type) \ +struct { \ + class type *tqe_next; /* next element */ \ + class type **tqe_prev; /* address of previous next element */ \ + TRACEBUF \ +} + +/* + * Tail queue functions. + */ +#if (defined(_KERNEL) && defined(INVARIANTS)) +#define QMD_TAILQ_CHECK_HEAD(head, field) do { \ + if (!TAILQ_EMPTY(head) && \ + TAILQ_FIRST((head))->field.tqe_prev != \ + &TAILQ_FIRST((head))) \ + panic("Bad tailq head %p first->prev != head", (head)); \ +} while (0) + +#define QMD_TAILQ_CHECK_TAIL(head, field) do { \ + if (*(head)->tqh_last != NULL) \ + panic("Bad tailq NEXT(%p->tqh_last) != NULL", (head)); \ +} while (0) + +#define QMD_TAILQ_CHECK_NEXT(elm, field) do { \ + if (TAILQ_NEXT((elm), field) != NULL && \ + TAILQ_NEXT((elm), field)->field.tqe_prev != \ + &((elm)->field.tqe_next)) \ + panic("Bad link elm %p next->prev != elm", (elm)); \ +} while (0) + +#define QMD_TAILQ_CHECK_PREV(elm, field) do { \ + if (*(elm)->field.tqe_prev != (elm)) \ + panic("Bad link elm %p prev->next != elm", (elm)); \ +} while (0) +#else +#define QMD_TAILQ_CHECK_HEAD(head, field) +#define QMD_TAILQ_CHECK_TAIL(head, headname) +#define QMD_TAILQ_CHECK_NEXT(elm, field) +#define QMD_TAILQ_CHECK_PREV(elm, field) +#endif /* (_KERNEL && INVARIANTS) */ + +#define TAILQ_CONCAT(head1, head2, field) do { \ + if (!TAILQ_EMPTY(head2)) { \ + *(head1)->tqh_last = (head2)->tqh_first; \ + (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \ + (head1)->tqh_last = (head2)->tqh_last; \ + TAILQ_INIT((head2)); \ + QMD_TRACE_HEAD(head1); \ + QMD_TRACE_HEAD(head2); \ + } \ +} while (0) + +#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL) + +#define TAILQ_FIRST(head) ((head)->tqh_first) + +#define TAILQ_FOREACH(var, head, field) \ + for ((var) = TAILQ_FIRST((head)); \ + (var); \ + (var) = TAILQ_NEXT((var), field)) + +#define TAILQ_FOREACH_FROM(var, head, field) \ + for ((var) = ((var) ? (var) : TAILQ_FIRST((head))); \ + (var); \ + (var) = TAILQ_NEXT((var), field)) + +#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = TAILQ_FIRST((head)); \ + (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define TAILQ_FOREACH_FROM_SAFE(var, head, field, tvar) \ + for ((var) = ((var) ? (var) : TAILQ_FIRST((head))); \ + (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ + for ((var) = TAILQ_LAST((head), headname); \ + (var); \ + (var) = TAILQ_PREV((var), headname, field)) + +#define TAILQ_FOREACH_REVERSE_FROM(var, head, headname, field) \ + for ((var) = ((var) ? (var) : TAILQ_LAST((head), headname)); \ + (var); \ + (var) = TAILQ_PREV((var), headname, field)) + +#define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \ + for ((var) = TAILQ_LAST((head), headname); \ + (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \ + (var) = (tvar)) + +#define TAILQ_FOREACH_REVERSE_FROM_SAFE(var, head, headname, field, tvar) \ + for ((var) = ((var) ? (var) : TAILQ_LAST((head), headname)); \ + (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \ + (var) = (tvar)) + +#define TAILQ_INIT(head) do { \ + TAILQ_FIRST((head)) = NULL; \ + (head)->tqh_last = &TAILQ_FIRST((head)); \ + QMD_TRACE_HEAD(head); \ +} while (0) + +#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ + QMD_TAILQ_CHECK_NEXT(listelm, field); \ + if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\ + TAILQ_NEXT((elm), field)->field.tqe_prev = \ + &TAILQ_NEXT((elm), field); \ + else { \ + (head)->tqh_last = &TAILQ_NEXT((elm), field); \ + QMD_TRACE_HEAD(head); \ + } \ + TAILQ_NEXT((listelm), field) = (elm); \ + (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \ + QMD_TRACE_ELEM(&(elm)->field); \ + QMD_TRACE_ELEM(&(listelm)->field); \ +} while (0) + +#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ + QMD_TAILQ_CHECK_PREV(listelm, field); \ + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ + TAILQ_NEXT((elm), field) = (listelm); \ + *(listelm)->field.tqe_prev = (elm); \ + (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \ + QMD_TRACE_ELEM(&(elm)->field); \ + QMD_TRACE_ELEM(&(listelm)->field); \ +} while (0) + +#define TAILQ_INSERT_HEAD(head, elm, field) do { \ + QMD_TAILQ_CHECK_HEAD(head, field); \ + if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \ + TAILQ_FIRST((head))->field.tqe_prev = \ + &TAILQ_NEXT((elm), field); \ + else \ + (head)->tqh_last = &TAILQ_NEXT((elm), field); \ + TAILQ_FIRST((head)) = (elm); \ + (elm)->field.tqe_prev = &TAILQ_FIRST((head)); \ + QMD_TRACE_HEAD(head); \ + QMD_TRACE_ELEM(&(elm)->field); \ +} while (0) + +#define TAILQ_INSERT_TAIL(head, elm, field) do { \ + QMD_TAILQ_CHECK_TAIL(head, field); \ + TAILQ_NEXT((elm), field) = NULL; \ + (elm)->field.tqe_prev = (head)->tqh_last; \ + *(head)->tqh_last = (elm); \ + (head)->tqh_last = &TAILQ_NEXT((elm), field); \ + QMD_TRACE_HEAD(head); \ + QMD_TRACE_ELEM(&(elm)->field); \ +} while (0) + +#define TAILQ_LAST(head, headname) \ + (*(((struct headname *)((head)->tqh_last))->tqh_last)) + +#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) + +#define TAILQ_PREV(elm, headname, field) \ + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) + +#define TAILQ_REMOVE(head, elm, field) do { \ + QMD_SAVELINK(oldnext, (elm)->field.tqe_next); \ + QMD_SAVELINK(oldprev, (elm)->field.tqe_prev); \ + QMD_TAILQ_CHECK_NEXT(elm, field); \ + QMD_TAILQ_CHECK_PREV(elm, field); \ + if ((TAILQ_NEXT((elm), field)) != NULL) \ + TAILQ_NEXT((elm), field)->field.tqe_prev = \ + (elm)->field.tqe_prev; \ + else { \ + (head)->tqh_last = (elm)->field.tqe_prev; \ + QMD_TRACE_HEAD(head); \ + } \ + *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \ + TRASHIT(*oldnext); \ + TRASHIT(*oldprev); \ + QMD_TRACE_ELEM(&(elm)->field); \ +} while (0) + +#define TAILQ_SWAP(head1, head2, type, field) do { \ + QUEUE_TYPEOF(type) *swap_first = (head1)->tqh_first; \ + QUEUE_TYPEOF(type) **swap_last = (head1)->tqh_last; \ + (head1)->tqh_first = (head2)->tqh_first; \ + (head1)->tqh_last = (head2)->tqh_last; \ + (head2)->tqh_first = swap_first; \ + (head2)->tqh_last = swap_last; \ + if ((swap_first = (head1)->tqh_first) != NULL) \ + swap_first->field.tqe_prev = &(head1)->tqh_first; \ + else \ + (head1)->tqh_last = &(head1)->tqh_first; \ + if ((swap_first = (head2)->tqh_first) != NULL) \ + swap_first->field.tqe_prev = &(head2)->tqh_first; \ + else \ + (head2)->tqh_last = &(head2)->tqh_first; \ +} while (0) + +#endif /* !_SYS_QUEUE_H_ */ \ No newline at end of file diff --git a/server/valgrind-out.txt b/server/valgrind-out.txt index b77119c..6639502 100644 --- a/server/valgrind-out.txt +++ b/server/valgrind-out.txt @@ -1,117 +1,165 @@ -==6567== Memcheck, a memory error detector -==6567== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. -==6567== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info -==6567== Command: ./aesdsocket -==6567== Parent PID: 6565 -==6567== ---6567-- ---6567-- Valgrind options: ---6567-- --error-exitcode=1 ---6567-- --leak-check=full ---6567-- --show-leak-kinds=all ---6567-- --track-origins=yes ---6567-- --errors-for-leak-kinds=definite ---6567-- --verbose ---6567-- --log-file=valgrind-out.txt ---6567-- Contents of /proc/version: ---6567-- Linux version 5.15.0-122-generic (buildd@lcy02-amd64-106) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #132~20.04.1-Ubuntu SMP Fri Aug 30 15:50:07 UTC 2024 ---6567-- ---6567-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3 ---6567-- Page sizes: currently 4096, max supported 4096 ---6567-- Valgrind library directory: /usr/lib/x86_64-linux-gnu/valgrind ---6567-- Reading syms from /home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocket ---6567-- Reading syms from /usr/lib/x86_64-linux-gnu/ld-2.31.so ---6567-- Considering /usr/lib/debug/.build-id/db/0420f708b806cf03260aadb916c330049580b7.debug .. ---6567-- .. build-id is valid ---6567-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-linux ---6567-- object doesn't have a symbol table ---6567-- object doesn't have a dynamic symbol table ---6567-- Scheduler: using generic scheduler lock implementation. ---6567-- Reading suppressions file: /usr/lib/x86_64-linux-gnu/valgrind/default.supp -==6567== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-6567-by-stamrakar-on-??? -==6567== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-6567-by-stamrakar-on-??? -==6567== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-6567-by-stamrakar-on-??? -==6567== -==6567== TO CONTROL THIS PROCESS USING vgdb (which you probably -==6567== don't want to do, unless you know exactly what you're doing, -==6567== or are doing some strange experiment): -==6567== /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=6567 ...command... -==6567== -==6567== TO DEBUG THIS PROCESS USING GDB: start GDB like this -==6567== /path/to/gdb ./aesdsocket -==6567== and then give GDB the following command -==6567== target remote | /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=6567 -==6567== --pid is optional if only one valgrind process is running -==6567== ---6567-- REDIR: 0x4022e20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9ce2 (???) ---6567-- REDIR: 0x4022bf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c9cfc (???) ---6567-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_core-amd64-linux.so ---6567-- object doesn't have a symbol table ---6567-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so ---6567-- object doesn't have a symbol table -==6567== WARNING: new redirection conflicts with existing -- ignoring it ---6567-- old: 0x04022e20 (strlen ) R-> (0000.0) 0x580c9ce2 ??? ---6567-- new: 0x04022e20 (strlen ) R-> (2007.0) 0x0483f060 strlen ---6567-- REDIR: 0x401f600 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ffd0 (strcmp) ---6567-- REDIR: 0x4023380 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4843a20 (mempcpy) ---6567-- Reading syms from /usr/lib/x86_64-linux-gnu/libc-2.31.so ---6567-- Considering /usr/lib/debug/.build-id/07/02430aef5fa3dda43986563e9ffcc47efbd75e.debug .. ---6567-- .. build-id is valid ---6567-- REDIR: 0x48fd480 (libc.so.6:memmove) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x48fc780 (libc.so.6:strncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x48fd7b0 (libc.so.6:strcasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x48fc0a0 (libc.so.6:strcat) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x48fc7e0 (libc.so.6:rindex) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x48fec50 (libc.so.6:rawmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x4919ce0 (libc.so.6:wmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x4919820 (libc.so.6:wcscmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x48fd5e0 (libc.so.6:mempcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x48fd410 (libc.so.6:bcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x48fc710 (libc.so.6:strncmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x48fc150 (libc.so.6:strcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x48fd540 (libc.so.6:memset) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x49197e0 (libc.so.6:wcschr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x48fc670 (libc.so.6:strnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x48fc230 (libc.so.6:strcspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x48fd800 (libc.so.6:strncasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x48fc1d0 (libc.so.6:strcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x48fd950 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x491af50 (libc.so.6:wcsnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x4919860 (libc.so.6:wcscpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x48fc820 (libc.so.6:strpbrk) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x48fc100 (libc.so.6:index) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x48fc630 (libc.so.6:strlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x4905bb0 (libc.so.6:memrchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x48fd850 (libc.so.6:strcasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x48fd3d0 (libc.so.6:memchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x4919930 (libc.so.6:wcslen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x48fcae0 (libc.so.6:strspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x48fd750 (libc.so.6:stpncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x48fd6f0 (libc.so.6:stpcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x48fec90 (libc.so.6:strchrnul) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x48fd8a0 (libc.so.6:strncasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6567-- REDIR: 0x490e8c0 (libc.so.6:__strrchr_sse2) redirected to 0x483ea70 (__strrchr_sse2) ---6567-- REDIR: 0x48f70e0 (libc.so.6:malloc) redirected to 0x483b780 (malloc) ---6567-- REDIR: 0x48f8b10 (libc.so.6:calloc) redirected to 0x483dce0 (calloc) ---6567-- REDIR: 0x490e6b0 (libc.so.6:__strchrnul_sse2) redirected to 0x4843540 (strchrnul) ---6567-- REDIR: 0x490ebc0 (libc.so.6:__strlen_sse2) redirected to 0x483efa0 (__strlen_sse2) ---6567-- REDIR: 0x48f76d0 (libc.so.6:free) redirected to 0x483c9d0 (free) ---6567-- REDIR: 0x4918ad0 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4840100 (memcpy@GLIBC_2.2.5) ---6567-- REDIR: 0x48fcfa0 (libc.so.6:__GI_strstr) redirected to 0x4843ca0 (__strstr_sse2) ---6567-- REDIR: 0x49ea790 (libc.so.6:__memcmp_sse4_1) redirected to 0x4842150 (__memcmp_sse4_1) ---6567-- REDIR: 0x49073b0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x483fed0 (strcmp) ---6567-- REDIR: 0x4918f00 (libc.so.6:__memset_sse2_unaligned) redirected to 0x48428e0 (memset) ---6567-- REDIR: 0x4918ab0 (libc.so.6:__mempcpy_sse2_unaligned) redirected to 0x4843660 (mempcpy) ---6567-- REDIR: 0x48f7e80 (libc.so.6:realloc) redirected to 0x483df30 (realloc) ---6567-- REDIR: 0x4908ec0 (libc.so.6:__memchr_sse2) redirected to 0x4840050 (memchr) ---6567-- REDIR: 0x490e480 (libc.so.6:__strchr_sse2) redirected to 0x483eb90 (__strchr_sse2) ---6567-- REDIR: 0x4913b00 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x483f090 (strcpy) ---6567-- REDIR: 0x4915140 (libc.so.6:__stpcpy_sse2_unaligned) redirected to 0x4842570 (__stpcpy_sse2_unaligned) -==6567== -==6567== HEAP SUMMARY: -==6567== in use at exit: 0 bytes in 0 blocks -==6567== total heap usage: 398 allocs, 398 frees, 1,285,928 bytes allocated -==6567== -==6567== All heap blocks were freed -- no leaks are possible -==6567== -==6567== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) +==12774== Memcheck, a memory error detector +==12774== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. +==12774== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info +==12774== Command: ./aesdsocket +==12774== Parent PID: 12770 +==12774== +--12774-- +--12774-- Valgrind options: +--12774-- --error-exitcode=1 +--12774-- --leak-check=full +--12774-- --show-leak-kinds=all +--12774-- --track-origins=yes +--12774-- --errors-for-leak-kinds=definite +--12774-- --verbose +--12774-- --log-file=valgrind-out.txt +--12774-- Contents of /proc/version: +--12774-- Linux version 5.15.0-122-generic (buildd@lcy02-amd64-106) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #132~20.04.1-Ubuntu SMP Fri Aug 30 15:50:07 UTC 2024 +--12774-- +--12774-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3 +--12774-- Page sizes: currently 4096, max supported 4096 +--12774-- Valgrind library directory: /usr/lib/x86_64-linux-gnu/valgrind +--12774-- Reading syms from /home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocket +--12774-- Reading syms from /usr/lib/x86_64-linux-gnu/ld-2.31.so +--12774-- Considering /usr/lib/debug/.build-id/db/0420f708b806cf03260aadb916c330049580b7.debug .. +--12774-- .. build-id is valid +--12774-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-linux +--12774-- object doesn't have a symbol table +--12774-- object doesn't have a dynamic symbol table +--12774-- Scheduler: using generic scheduler lock implementation. +--12774-- Reading suppressions file: /usr/lib/x86_64-linux-gnu/valgrind/default.supp +==12774== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-12774-by-stamrakar-on-??? +==12774== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-12774-by-stamrakar-on-??? +==12774== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-12774-by-stamrakar-on-??? +==12774== +==12774== TO CONTROL THIS PROCESS USING vgdb (which you probably +==12774== don't want to do, unless you know exactly what you're doing, +==12774== or are doing some strange experiment): +==12774== /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=12774 ...command... +==12774== +==12774== TO DEBUG THIS PROCESS USING GDB: start GDB like this +==12774== /path/to/gdb ./aesdsocket +==12774== and then give GDB the following command +==12774== target remote | /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=12774 +==12774== --pid is optional if only one valgrind process is running +==12774== +--12774-- REDIR: 0x4022e20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9ce2 (???) +--12774-- REDIR: 0x4022bf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c9cfc (???) +--12774-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_core-amd64-linux.so +--12774-- object doesn't have a symbol table +--12774-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so +--12774-- object doesn't have a symbol table +==12774== WARNING: new redirection conflicts with existing -- ignoring it +--12774-- old: 0x04022e20 (strlen ) R-> (0000.0) 0x580c9ce2 ??? +--12774-- new: 0x04022e20 (strlen ) R-> (2007.0) 0x0483f060 strlen +--12774-- REDIR: 0x401f600 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ffd0 (strcmp) +--12774-- REDIR: 0x4023380 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4843a20 (mempcpy) +--12774-- Reading syms from /usr/lib/x86_64-linux-gnu/libpthread-2.31.so +--12774-- Considering /usr/lib/debug/.build-id/9a/65bb469e45a1c6fbcffae5b82a2fd7a69eb479.debug .. +--12774-- .. build-id is valid +--12774-- Reading syms from /usr/lib/x86_64-linux-gnu/libc-2.31.so +--12774-- Considering /usr/lib/debug/.build-id/07/02430aef5fa3dda43986563e9ffcc47efbd75e.debug .. +--12774-- .. build-id is valid +--12774-- REDIR: 0x4920480 (libc.so.6:memmove) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x491f780 (libc.so.6:strncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x49207b0 (libc.so.6:strcasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x491f0a0 (libc.so.6:strcat) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x491f7e0 (libc.so.6:rindex) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x4921c50 (libc.so.6:rawmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x493cce0 (libc.so.6:wmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x493c820 (libc.so.6:wcscmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x49205e0 (libc.so.6:mempcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x4920410 (libc.so.6:bcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x491f710 (libc.so.6:strncmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x491f150 (libc.so.6:strcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x4920540 (libc.so.6:memset) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x493c7e0 (libc.so.6:wcschr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x491f670 (libc.so.6:strnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x491f230 (libc.so.6:strcspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x4920800 (libc.so.6:strncasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x491f1d0 (libc.so.6:strcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x4920950 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x493df50 (libc.so.6:wcsnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x493c860 (libc.so.6:wcscpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x491f820 (libc.so.6:strpbrk) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x491f100 (libc.so.6:index) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x491f630 (libc.so.6:strlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x4928bb0 (libc.so.6:memrchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x4920850 (libc.so.6:strcasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x49203d0 (libc.so.6:memchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x493c930 (libc.so.6:wcslen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x491fae0 (libc.so.6:strspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x4920750 (libc.so.6:stpncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x49206f0 (libc.so.6:stpcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x4921c90 (libc.so.6:strchrnul) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x49208a0 (libc.so.6:strncasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--12774-- REDIR: 0x49318c0 (libc.so.6:__strrchr_sse2) redirected to 0x483ea70 (__strrchr_sse2) +--12774-- REDIR: 0x491a0e0 (libc.so.6:malloc) redirected to 0x483b780 (malloc) +--12774-- REDIR: 0x491bb10 (libc.so.6:calloc) redirected to 0x483dce0 (calloc) +--12774-- REDIR: 0x49316b0 (libc.so.6:__strchrnul_sse2) redirected to 0x4843540 (strchrnul) +--12774-- REDIR: 0x4931bc0 (libc.so.6:__strlen_sse2) redirected to 0x483efa0 (__strlen_sse2) +--12774-- REDIR: 0x491a6d0 (libc.so.6:free) redirected to 0x483c9d0 (free) +--12774-- REDIR: 0x493bad0 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4840100 (memcpy@GLIBC_2.2.5) +--12774-- REDIR: 0x491ffa0 (libc.so.6:__GI_strstr) redirected to 0x4843ca0 (__strstr_sse2) +--12774-- REDIR: 0x4a0d790 (libc.so.6:__memcmp_sse4_1) redirected to 0x4842150 (__memcmp_sse4_1) +--12774-- REDIR: 0x492a3b0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x483fed0 (strcmp) +--12774-- REDIR: 0x493bab0 (libc.so.6:__mempcpy_sse2_unaligned) redirected to 0x4843660 (mempcpy) +--12774-- REDIR: 0x491ae80 (libc.so.6:realloc) redirected to 0x483df30 (realloc) +--12774-- REDIR: 0x493bf00 (libc.so.6:__memset_sse2_unaligned) redirected to 0x48428e0 (memset) +--12774-- REDIR: 0x492bec0 (libc.so.6:__memchr_sse2) redirected to 0x4840050 (memchr) +--12774-- REDIR: 0x4931480 (libc.so.6:__strchr_sse2) redirected to 0x483eb90 (__strchr_sse2) +--12774-- REDIR: 0x4936b00 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x483f090 (strcpy) +==12774== Thread 2: +==12774== Syscall param read(buf) points to unaddressable byte(s) +==12774== at 0x48703CC: __libc_read (read.c:26) +==12774== by 0x48703CC: read (read.c:24) +==12774== by 0x10AF73: threadfunc (aesdsocket.c:310) +==12774== by 0x4865608: start_thread (pthread_create.c:477) +==12774== by 0x499F352: clone (clone.S:95) +==12774== Address 0x0 is not stack'd, malloc'd or (recently) free'd +==12774== +--12774-- Reading syms from /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 +--12774-- object doesn't have a symbol table +--12774-- REDIR: 0x4938140 (libc.so.6:__stpcpy_sse2_unaligned) redirected to 0x4842570 (__stpcpy_sse2_unaligned) +--12774-- Discarding syms at 0x56795e0-0x568a055 in /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 (have_dinfo 1) +==12774== +==12774== HEAP SUMMARY: +==12774== in use at exit: 312 bytes in 2 blocks +==12774== total heap usage: 169 allocs, 167 frees, 429,138 bytes allocated +==12774== +==12774== Searching for pointers to 2 not-freed blocks +==12774== Checked 8,477,232 bytes +==12774== +==12774== Thread 1: +==12774== 40 bytes in 1 blocks are still reachable in loss record 1 of 2 +==12774== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==12774== by 0x10B457: main (aesdsocket.c:466) +==12774== +==12774== 272 bytes in 1 blocks are possibly lost in loss record 2 of 2 +==12774== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==12774== by 0x40149DA: allocate_dtv (dl-tls.c:286) +==12774== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) +==12774== by 0x4866322: allocate_stack (allocatestack.c:622) +==12774== by 0x4866322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) +==12774== by 0x10B4D4: main (aesdsocket.c:483) +==12774== +==12774== LEAK SUMMARY: +==12774== definitely lost: 0 bytes in 0 blocks +==12774== indirectly lost: 0 bytes in 0 blocks +==12774== possibly lost: 272 bytes in 1 blocks +==12774== still reachable: 40 bytes in 1 blocks +==12774== suppressed: 0 bytes in 0 blocks +==12774== +==12774== ERROR SUMMARY: 2 errors from 1 contexts (suppressed: 0 from 0) +==12774== +==12774== 2 errors in context 1 of 1: +==12774== Thread 2: +==12774== Syscall param read(buf) points to unaddressable byte(s) +==12774== at 0x48703CC: __libc_read (read.c:26) +==12774== by 0x48703CC: read (read.c:24) +==12774== by 0x10AF73: threadfunc (aesdsocket.c:310) +==12774== by 0x4865608: start_thread (pthread_create.c:477) +==12774== by 0x499F352: clone (clone.S:95) +==12774== Address 0x0 is not stack'd, malloc'd or (recently) free'd +==12774== +==12774== ERROR SUMMARY: 2 errors from 1 contexts (suppressed: 0 from 0) From cd27db482a84e8fd7cb7444ccc428632964ecddf Mon Sep 17 00:00:00 2001 From: stamrakar Date: Sun, 13 Oct 2024 22:39:28 -0600 Subject: [PATCH 06/17] not all tests passing --- server/aesdsocket.c | 68 +++++--- server/valgrind-out.txt | 338 ++++++++++++++++++++-------------------- 2 files changed, 220 insertions(+), 186 deletions(-) diff --git a/server/aesdsocket.c b/server/aesdsocket.c index 9c6322b..c78f61b 100644 --- a/server/aesdsocket.c +++ b/server/aesdsocket.c @@ -50,6 +50,7 @@ typedef struct thread_info_s thread_info_t; typedef struct slist_data_s my_threads; pthread_mutex_t writeSocket = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t size_val = PTHREAD_MUTEX_INITIALIZER; struct thread_info_s{ @@ -76,9 +77,11 @@ bool daemon_en = false; int sockfd = -1; int new_fd = -1; int recvfile_fd = -1; +static ssize_t total_size = 0; pid_t pid; const char *recvfile = "/var/tmp/aesdsocketdata"; +//const char *recvfile = "/home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocketdata"; static void closeAll(int exit_flag); static void init_sigHandler(void); static void signal_handler(int signal_number); @@ -170,10 +173,10 @@ void closeAll(int exit_flag) if(sockfd != -1) close(sockfd); if(new_fd != -1) close(new_fd); if(recvfile_fd != -1) close(recvfile_fd); - if(remove(recvfile) != 0) - { - syslog(LOG_ERR, "File removal not successful"); - } + //if(remove(recvfile) != 0) + //{ + // syslog(LOG_ERR, "File removal not successful"); + //} pthread_mutex_destroy(&writeSocket); syslog(LOG_DEBUG, "CLEANUP COMPLETED."); closelog(); @@ -186,12 +189,12 @@ void *threadfunc(void *args) my_threads *thread_func_args = (my_threads *) args; syslog(LOG_DEBUG, "I have entered this thread with threadID = %lu", thread_func_args->thread_info.threadid); bool isPacketValid = false; - ssize_t bytes_rx; - ssize_t bytes_read; + ssize_t bytes_rx = 0; + ssize_t bytes_read = 0; ssize_t supplementBuf = 0; ssize_t supplementSize = BUF_SIZE; - ssize_t nr; - int rc; + ssize_t nr = 0; + int rc = 0; char *new_line = NULL; char *my_buffer = (char *) malloc(BUF_SIZE); char *send_my_buffer = NULL; @@ -205,8 +208,11 @@ void *threadfunc(void *args) memset(my_buffer, 0, BUF_SIZE); do{ - bytes_rx = recv(new_fd, my_buffer+supplementBuf, BUF_SIZE-1, 0); + for (int i = 0; i < bytes_rx; i++) + { + syslog(LOG_DEBUG, "receiving: %c", my_buffer[i]); + } syslog(LOG_DEBUG, "I have received %ld bytes", bytes_rx); if (bytes_rx < 0) { @@ -216,13 +222,18 @@ void *threadfunc(void *args) closeAll(EXIT_FAILURE); } supplementBuf += bytes_rx; + syslog(LOG_DEBUG, "supplementBuf is %ld in thread ID : %lu", supplementBuf, thread_func_args->thread_info.threadid); new_line = strchr(my_buffer, '\n'); //if NULL, keep getting packets if (new_line != NULL) { - syslog(LOG_DEBUG, "YAY, slash n found"); + syslog(LOG_DEBUG, "yay, newline character found!"); + // for (int i = 0; i < supplementBuf; i++) + // { + // syslog(LOG_DEBUG, "%c", my_buffer[i]); + // } isPacketValid = true; supplementBuf = new_line - my_buffer + 1; - syslog(LOG_DEBUG, "supplementBuf size within slash found %ld", supplementBuf); + syslog(LOG_DEBUG, "supplementBuf size with newline found is %ld with thread ID : %lu", supplementBuf, thread_func_args->thread_info.threadid); } else @@ -237,7 +248,7 @@ void *threadfunc(void *args) memset(my_buffer+supplementBuf, 0 , supplementSize-supplementBuf); } - }while (isPacketValid == false); + }while (isPacketValid == false); @@ -246,8 +257,6 @@ void *threadfunc(void *args) { syslog(LOG_DEBUG, "PACKET SUCCESSFULLY VALIDATED"); - - rc = pthread_mutex_lock(&writeSocket); if (rc != 0) { @@ -263,7 +272,7 @@ void *threadfunc(void *args) perror("pthread mutex_unlock failed"); } - syslog(LOG_DEBUG, "nr is %ld",nr); + syslog(LOG_DEBUG, "bytes written to recvfile is %ld",nr); if (nr != supplementBuf) { /*error*/ @@ -277,12 +286,27 @@ void *threadfunc(void *args) } + rc = pthread_mutex_lock(&size_val); + if (rc != 0) + { + syslog(LOG_ERR, "pthread_mutex_lock failed on total size, error was %d", rc); + perror("pthread mutex_lock failed"); + } + + total_size += supplementBuf; + + rc = pthread_mutex_unlock(&size_val); + if (rc != 0) + { + syslog(LOG_ERR, "pthread_mutex_unlock failed on total size, error was %d", rc); + perror("pthread mutex_lock failed"); + } free(my_buffer); my_buffer = NULL; - send_my_buffer = (char *) malloc(supplementBuf); + send_my_buffer = (char *) malloc(BUF_SIZE); if (send_my_buffer == NULL) { syslog(LOG_ERR, "Failed to malloc sending buffer."); @@ -307,8 +331,12 @@ void *threadfunc(void *args) syslog(LOG_DEBUG, "lseek pass"); - while ((bytes_read = read(recvfile_fd, send_my_buffer, supplementBuf)) > 0) { + while ((bytes_read = read(recvfile_fd, send_my_buffer, total_size)) > 0) { syslog(LOG_DEBUG, "bytes_read is %ld", bytes_read); + for(int i = 0; i < bytes_read; i++) + { + syslog(LOG_DEBUG, "send: %c",send_my_buffer[i]); + } if (send(new_fd, send_my_buffer, bytes_read, 0) != bytes_read) { syslog(LOG_DEBUG,"HEREEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"); @@ -458,10 +486,10 @@ int main(int argc, char *argv[]) continue; } - syslog(LOG_DEBUG, "CONNECTED, new_fd is %d", new_fd); + syslog(LOG_DEBUG, "Connected + Accepted, new_fd is %d", new_fd); inet_ntop(AF_INET, &(peer_addr.sin_addr), ip4, sizeof(ip4)); - syslog(LOG_DEBUG, "Accepted connection from %s", ip4); + //syslog(LOG_DEBUG, "Accepted connection from %s", ip4); my_threads *thread_data = (my_threads *)malloc(sizeof(my_threads)); if (thread_data == NULL) @@ -472,8 +500,6 @@ int main(int argc, char *argv[]) //should I be exiting everything here or just keep trying } - - thread_data->thread_info.afd = new_fd; thread_data->thread_info.thread_complete_success = false; strcpy(thread_data->thread_info.ip4, ip4); diff --git a/server/valgrind-out.txt b/server/valgrind-out.txt index 6639502..a341758 100644 --- a/server/valgrind-out.txt +++ b/server/valgrind-out.txt @@ -1,165 +1,173 @@ -==12774== Memcheck, a memory error detector -==12774== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. -==12774== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info -==12774== Command: ./aesdsocket -==12774== Parent PID: 12770 -==12774== ---12774-- ---12774-- Valgrind options: ---12774-- --error-exitcode=1 ---12774-- --leak-check=full ---12774-- --show-leak-kinds=all ---12774-- --track-origins=yes ---12774-- --errors-for-leak-kinds=definite ---12774-- --verbose ---12774-- --log-file=valgrind-out.txt ---12774-- Contents of /proc/version: ---12774-- Linux version 5.15.0-122-generic (buildd@lcy02-amd64-106) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #132~20.04.1-Ubuntu SMP Fri Aug 30 15:50:07 UTC 2024 ---12774-- ---12774-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3 ---12774-- Page sizes: currently 4096, max supported 4096 ---12774-- Valgrind library directory: /usr/lib/x86_64-linux-gnu/valgrind ---12774-- Reading syms from /home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocket ---12774-- Reading syms from /usr/lib/x86_64-linux-gnu/ld-2.31.so ---12774-- Considering /usr/lib/debug/.build-id/db/0420f708b806cf03260aadb916c330049580b7.debug .. ---12774-- .. build-id is valid ---12774-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-linux ---12774-- object doesn't have a symbol table ---12774-- object doesn't have a dynamic symbol table ---12774-- Scheduler: using generic scheduler lock implementation. ---12774-- Reading suppressions file: /usr/lib/x86_64-linux-gnu/valgrind/default.supp -==12774== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-12774-by-stamrakar-on-??? -==12774== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-12774-by-stamrakar-on-??? -==12774== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-12774-by-stamrakar-on-??? -==12774== -==12774== TO CONTROL THIS PROCESS USING vgdb (which you probably -==12774== don't want to do, unless you know exactly what you're doing, -==12774== or are doing some strange experiment): -==12774== /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=12774 ...command... -==12774== -==12774== TO DEBUG THIS PROCESS USING GDB: start GDB like this -==12774== /path/to/gdb ./aesdsocket -==12774== and then give GDB the following command -==12774== target remote | /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=12774 -==12774== --pid is optional if only one valgrind process is running -==12774== ---12774-- REDIR: 0x4022e20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9ce2 (???) ---12774-- REDIR: 0x4022bf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c9cfc (???) ---12774-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_core-amd64-linux.so ---12774-- object doesn't have a symbol table ---12774-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so ---12774-- object doesn't have a symbol table -==12774== WARNING: new redirection conflicts with existing -- ignoring it ---12774-- old: 0x04022e20 (strlen ) R-> (0000.0) 0x580c9ce2 ??? ---12774-- new: 0x04022e20 (strlen ) R-> (2007.0) 0x0483f060 strlen ---12774-- REDIR: 0x401f600 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ffd0 (strcmp) ---12774-- REDIR: 0x4023380 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4843a20 (mempcpy) ---12774-- Reading syms from /usr/lib/x86_64-linux-gnu/libpthread-2.31.so ---12774-- Considering /usr/lib/debug/.build-id/9a/65bb469e45a1c6fbcffae5b82a2fd7a69eb479.debug .. ---12774-- .. build-id is valid ---12774-- Reading syms from /usr/lib/x86_64-linux-gnu/libc-2.31.so ---12774-- Considering /usr/lib/debug/.build-id/07/02430aef5fa3dda43986563e9ffcc47efbd75e.debug .. ---12774-- .. build-id is valid ---12774-- REDIR: 0x4920480 (libc.so.6:memmove) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x491f780 (libc.so.6:strncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x49207b0 (libc.so.6:strcasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x491f0a0 (libc.so.6:strcat) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x491f7e0 (libc.so.6:rindex) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x4921c50 (libc.so.6:rawmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x493cce0 (libc.so.6:wmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x493c820 (libc.so.6:wcscmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x49205e0 (libc.so.6:mempcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x4920410 (libc.so.6:bcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x491f710 (libc.so.6:strncmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x491f150 (libc.so.6:strcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x4920540 (libc.so.6:memset) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x493c7e0 (libc.so.6:wcschr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x491f670 (libc.so.6:strnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x491f230 (libc.so.6:strcspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x4920800 (libc.so.6:strncasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x491f1d0 (libc.so.6:strcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x4920950 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x493df50 (libc.so.6:wcsnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x493c860 (libc.so.6:wcscpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x491f820 (libc.so.6:strpbrk) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x491f100 (libc.so.6:index) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x491f630 (libc.so.6:strlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x4928bb0 (libc.so.6:memrchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x4920850 (libc.so.6:strcasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x49203d0 (libc.so.6:memchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x493c930 (libc.so.6:wcslen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x491fae0 (libc.so.6:strspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x4920750 (libc.so.6:stpncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x49206f0 (libc.so.6:stpcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x4921c90 (libc.so.6:strchrnul) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x49208a0 (libc.so.6:strncasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---12774-- REDIR: 0x49318c0 (libc.so.6:__strrchr_sse2) redirected to 0x483ea70 (__strrchr_sse2) ---12774-- REDIR: 0x491a0e0 (libc.so.6:malloc) redirected to 0x483b780 (malloc) ---12774-- REDIR: 0x491bb10 (libc.so.6:calloc) redirected to 0x483dce0 (calloc) ---12774-- REDIR: 0x49316b0 (libc.so.6:__strchrnul_sse2) redirected to 0x4843540 (strchrnul) ---12774-- REDIR: 0x4931bc0 (libc.so.6:__strlen_sse2) redirected to 0x483efa0 (__strlen_sse2) ---12774-- REDIR: 0x491a6d0 (libc.so.6:free) redirected to 0x483c9d0 (free) ---12774-- REDIR: 0x493bad0 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4840100 (memcpy@GLIBC_2.2.5) ---12774-- REDIR: 0x491ffa0 (libc.so.6:__GI_strstr) redirected to 0x4843ca0 (__strstr_sse2) ---12774-- REDIR: 0x4a0d790 (libc.so.6:__memcmp_sse4_1) redirected to 0x4842150 (__memcmp_sse4_1) ---12774-- REDIR: 0x492a3b0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x483fed0 (strcmp) ---12774-- REDIR: 0x493bab0 (libc.so.6:__mempcpy_sse2_unaligned) redirected to 0x4843660 (mempcpy) ---12774-- REDIR: 0x491ae80 (libc.so.6:realloc) redirected to 0x483df30 (realloc) ---12774-- REDIR: 0x493bf00 (libc.so.6:__memset_sse2_unaligned) redirected to 0x48428e0 (memset) ---12774-- REDIR: 0x492bec0 (libc.so.6:__memchr_sse2) redirected to 0x4840050 (memchr) ---12774-- REDIR: 0x4931480 (libc.so.6:__strchr_sse2) redirected to 0x483eb90 (__strchr_sse2) ---12774-- REDIR: 0x4936b00 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x483f090 (strcpy) -==12774== Thread 2: -==12774== Syscall param read(buf) points to unaddressable byte(s) -==12774== at 0x48703CC: __libc_read (read.c:26) -==12774== by 0x48703CC: read (read.c:24) -==12774== by 0x10AF73: threadfunc (aesdsocket.c:310) -==12774== by 0x4865608: start_thread (pthread_create.c:477) -==12774== by 0x499F352: clone (clone.S:95) -==12774== Address 0x0 is not stack'd, malloc'd or (recently) free'd -==12774== ---12774-- Reading syms from /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 ---12774-- object doesn't have a symbol table ---12774-- REDIR: 0x4938140 (libc.so.6:__stpcpy_sse2_unaligned) redirected to 0x4842570 (__stpcpy_sse2_unaligned) ---12774-- Discarding syms at 0x56795e0-0x568a055 in /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 (have_dinfo 1) -==12774== -==12774== HEAP SUMMARY: -==12774== in use at exit: 312 bytes in 2 blocks -==12774== total heap usage: 169 allocs, 167 frees, 429,138 bytes allocated -==12774== -==12774== Searching for pointers to 2 not-freed blocks -==12774== Checked 8,477,232 bytes -==12774== -==12774== Thread 1: -==12774== 40 bytes in 1 blocks are still reachable in loss record 1 of 2 -==12774== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==12774== by 0x10B457: main (aesdsocket.c:466) -==12774== -==12774== 272 bytes in 1 blocks are possibly lost in loss record 2 of 2 -==12774== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==12774== by 0x40149DA: allocate_dtv (dl-tls.c:286) -==12774== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) -==12774== by 0x4866322: allocate_stack (allocatestack.c:622) -==12774== by 0x4866322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) -==12774== by 0x10B4D4: main (aesdsocket.c:483) -==12774== -==12774== LEAK SUMMARY: -==12774== definitely lost: 0 bytes in 0 blocks -==12774== indirectly lost: 0 bytes in 0 blocks -==12774== possibly lost: 272 bytes in 1 blocks -==12774== still reachable: 40 bytes in 1 blocks -==12774== suppressed: 0 bytes in 0 blocks -==12774== -==12774== ERROR SUMMARY: 2 errors from 1 contexts (suppressed: 0 from 0) -==12774== -==12774== 2 errors in context 1 of 1: -==12774== Thread 2: -==12774== Syscall param read(buf) points to unaddressable byte(s) -==12774== at 0x48703CC: __libc_read (read.c:26) -==12774== by 0x48703CC: read (read.c:24) -==12774== by 0x10AF73: threadfunc (aesdsocket.c:310) -==12774== by 0x4865608: start_thread (pthread_create.c:477) -==12774== by 0x499F352: clone (clone.S:95) -==12774== Address 0x0 is not stack'd, malloc'd or (recently) free'd -==12774== -==12774== ERROR SUMMARY: 2 errors from 1 contexts (suppressed: 0 from 0) +==6960== Memcheck, a memory error detector +==6960== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. +==6960== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info +==6960== Command: ./aesdsocket +==6960== Parent PID: 6956 +==6960== +--6960-- +--6960-- Valgrind options: +--6960-- --error-exitcode=1 +--6960-- --leak-check=full +--6960-- --show-leak-kinds=all +--6960-- --track-origins=yes +--6960-- --errors-for-leak-kinds=definite +--6960-- --verbose +--6960-- --log-file=valgrind-out.txt +--6960-- Contents of /proc/version: +--6960-- Linux version 5.15.0-122-generic (buildd@lcy02-amd64-106) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #132~20.04.1-Ubuntu SMP Fri Aug 30 15:50:07 UTC 2024 +--6960-- +--6960-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3 +--6960-- Page sizes: currently 4096, max supported 4096 +--6960-- Valgrind library directory: /usr/lib/x86_64-linux-gnu/valgrind +--6960-- Reading syms from /home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocket +--6960-- Reading syms from /usr/lib/x86_64-linux-gnu/ld-2.31.so +--6960-- Considering /usr/lib/debug/.build-id/db/0420f708b806cf03260aadb916c330049580b7.debug .. +--6960-- .. build-id is valid +--6960-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-linux +--6960-- object doesn't have a symbol table +--6960-- object doesn't have a dynamic symbol table +--6960-- Scheduler: using generic scheduler lock implementation. +--6960-- Reading suppressions file: /usr/lib/x86_64-linux-gnu/valgrind/default.supp +==6960== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-6960-by-stamrakar-on-??? +==6960== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-6960-by-stamrakar-on-??? +==6960== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-6960-by-stamrakar-on-??? +==6960== +==6960== TO CONTROL THIS PROCESS USING vgdb (which you probably +==6960== don't want to do, unless you know exactly what you're doing, +==6960== or are doing some strange experiment): +==6960== /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=6960 ...command... +==6960== +==6960== TO DEBUG THIS PROCESS USING GDB: start GDB like this +==6960== /path/to/gdb ./aesdsocket +==6960== and then give GDB the following command +==6960== target remote | /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=6960 +==6960== --pid is optional if only one valgrind process is running +==6960== +--6960-- REDIR: 0x4022e20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9ce2 (???) +--6960-- REDIR: 0x4022bf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c9cfc (???) +--6960-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_core-amd64-linux.so +--6960-- object doesn't have a symbol table +--6960-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so +--6960-- object doesn't have a symbol table +==6960== WARNING: new redirection conflicts with existing -- ignoring it +--6960-- old: 0x04022e20 (strlen ) R-> (0000.0) 0x580c9ce2 ??? +--6960-- new: 0x04022e20 (strlen ) R-> (2007.0) 0x0483f060 strlen +--6960-- REDIR: 0x401f600 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ffd0 (strcmp) +--6960-- REDIR: 0x4023380 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4843a20 (mempcpy) +--6960-- Reading syms from /usr/lib/x86_64-linux-gnu/libpthread-2.31.so +--6960-- Considering /usr/lib/debug/.build-id/9a/65bb469e45a1c6fbcffae5b82a2fd7a69eb479.debug .. +--6960-- .. build-id is valid +--6960-- Reading syms from /usr/lib/x86_64-linux-gnu/libc-2.31.so +--6960-- Considering /usr/lib/debug/.build-id/07/02430aef5fa3dda43986563e9ffcc47efbd75e.debug .. +--6960-- .. build-id is valid +--6960-- REDIR: 0x4920480 (libc.so.6:memmove) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x491f780 (libc.so.6:strncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x49207b0 (libc.so.6:strcasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x491f0a0 (libc.so.6:strcat) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x491f7e0 (libc.so.6:rindex) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x4921c50 (libc.so.6:rawmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x493cce0 (libc.so.6:wmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x493c820 (libc.so.6:wcscmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x49205e0 (libc.so.6:mempcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x4920410 (libc.so.6:bcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x491f710 (libc.so.6:strncmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x491f150 (libc.so.6:strcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x4920540 (libc.so.6:memset) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x493c7e0 (libc.so.6:wcschr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x491f670 (libc.so.6:strnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x491f230 (libc.so.6:strcspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x4920800 (libc.so.6:strncasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x491f1d0 (libc.so.6:strcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x4920950 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x493df50 (libc.so.6:wcsnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x493c860 (libc.so.6:wcscpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x491f820 (libc.so.6:strpbrk) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x491f100 (libc.so.6:index) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x491f630 (libc.so.6:strlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x4928bb0 (libc.so.6:memrchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x4920850 (libc.so.6:strcasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x49203d0 (libc.so.6:memchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x493c930 (libc.so.6:wcslen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x491fae0 (libc.so.6:strspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x4920750 (libc.so.6:stpncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x49206f0 (libc.so.6:stpcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x4921c90 (libc.so.6:strchrnul) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x49208a0 (libc.so.6:strncasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--6960-- REDIR: 0x49318c0 (libc.so.6:__strrchr_sse2) redirected to 0x483ea70 (__strrchr_sse2) +--6960-- REDIR: 0x491a0e0 (libc.so.6:malloc) redirected to 0x483b780 (malloc) +--6960-- REDIR: 0x491bb10 (libc.so.6:calloc) redirected to 0x483dce0 (calloc) +--6960-- REDIR: 0x49316b0 (libc.so.6:__strchrnul_sse2) redirected to 0x4843540 (strchrnul) +--6960-- REDIR: 0x4931bc0 (libc.so.6:__strlen_sse2) redirected to 0x483efa0 (__strlen_sse2) +--6960-- REDIR: 0x491a6d0 (libc.so.6:free) redirected to 0x483c9d0 (free) +--6960-- REDIR: 0x493bad0 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4840100 (memcpy@GLIBC_2.2.5) +--6960-- REDIR: 0x491ffa0 (libc.so.6:__GI_strstr) redirected to 0x4843ca0 (__strstr_sse2) +--6960-- REDIR: 0x4a0d790 (libc.so.6:__memcmp_sse4_1) redirected to 0x4842150 (__memcmp_sse4_1) +--6960-- REDIR: 0x492a3b0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x483fed0 (strcmp) +--6960-- REDIR: 0x493bab0 (libc.so.6:__mempcpy_sse2_unaligned) redirected to 0x4843660 (mempcpy) +--6960-- REDIR: 0x491ae80 (libc.so.6:realloc) redirected to 0x483df30 (realloc) +--6960-- REDIR: 0x493bf00 (libc.so.6:__memset_sse2_unaligned) redirected to 0x48428e0 (memset) +--6960-- REDIR: 0x492bec0 (libc.so.6:__memchr_sse2) redirected to 0x4840050 (memchr) +--6960-- REDIR: 0x4931480 (libc.so.6:__strchr_sse2) redirected to 0x483eb90 (__strchr_sse2) +--6960-- REDIR: 0x4936b00 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x483f090 (strcpy) +==6960== Thread 2: +==6960== Syscall param read(buf) points to unaddressable byte(s) +==6960== at 0x48703CC: __libc_read (read.c:26) +==6960== by 0x48703CC: read (read.c:24) +==6960== by 0x10AFFB: threadfunc (aesdsocket.c:317) +==6960== by 0x4865608: start_thread (pthread_create.c:477) +==6960== by 0x499F352: clone (clone.S:95) +==6960== Address 0x4add722 is 0 bytes after a block of size 18 alloc'd +==6960== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==6960== by 0x10ADED: threadfunc (aesdsocket.c:292) +==6960== by 0x4865608: start_thread (pthread_create.c:477) +==6960== by 0x499F352: clone (clone.S:95) +==6960== +--6960-- Reading syms from /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 +--6960-- object doesn't have a symbol table +--6960-- REDIR: 0x4938140 (libc.so.6:__stpcpy_sse2_unaligned) redirected to 0x4842570 (__stpcpy_sse2_unaligned) +--6960-- Discarding syms at 0x56795e0-0x568a055 in /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 (have_dinfo 1) +==6960== +==6960== HEAP SUMMARY: +==6960== in use at exit: 312 bytes in 2 blocks +==6960== total heap usage: 322 allocs, 320 frees, 875,637 bytes allocated +==6960== +==6960== Searching for pointers to 2 not-freed blocks +==6960== Checked 8,477,232 bytes +==6960== +==6960== Thread 1: +==6960== 40 bytes in 1 blocks are still reachable in loss record 1 of 2 +==6960== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==6960== by 0x10B4C2: main (aesdsocket.c:477) +==6960== +==6960== 272 bytes in 1 blocks are possibly lost in loss record 2 of 2 +==6960== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==6960== by 0x40149DA: allocate_dtv (dl-tls.c:286) +==6960== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) +==6960== by 0x4866322: allocate_stack (allocatestack.c:622) +==6960== by 0x4866322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) +==6960== by 0x10B53F: main (aesdsocket.c:492) +==6960== +==6960== LEAK SUMMARY: +==6960== definitely lost: 0 bytes in 0 blocks +==6960== indirectly lost: 0 bytes in 0 blocks +==6960== possibly lost: 272 bytes in 1 blocks +==6960== still reachable: 40 bytes in 1 blocks +==6960== suppressed: 0 bytes in 0 blocks +==6960== +==6960== ERROR SUMMARY: 3 errors from 1 contexts (suppressed: 0 from 0) +==6960== +==6960== 3 errors in context 1 of 1: +==6960== Thread 2: +==6960== Syscall param read(buf) points to unaddressable byte(s) +==6960== at 0x48703CC: __libc_read (read.c:26) +==6960== by 0x48703CC: read (read.c:24) +==6960== by 0x10AFFB: threadfunc (aesdsocket.c:317) +==6960== by 0x4865608: start_thread (pthread_create.c:477) +==6960== by 0x499F352: clone (clone.S:95) +==6960== Address 0x4add722 is 0 bytes after a block of size 18 alloc'd +==6960== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==6960== by 0x10ADED: threadfunc (aesdsocket.c:292) +==6960== by 0x4865608: start_thread (pthread_create.c:477) +==6960== by 0x499F352: clone (clone.S:95) +==6960== +==6960== ERROR SUMMARY: 3 errors from 1 contexts (suppressed: 0 from 0) From 016918cfc3e90cbf815a2e01f190dc418c1f16db Mon Sep 17 00:00:00 2001 From: stamrakar Date: Mon, 14 Oct 2024 02:34:08 -0600 Subject: [PATCH 07/17] A6 Part 1 Step 1 working, timestamp next --- server/aesdsocket.c | 139 +++++++++------ server/valgrind-out.txt | 365 +++++++++++++++++++++------------------- 2 files changed, 283 insertions(+), 221 deletions(-) diff --git a/server/aesdsocket.c b/server/aesdsocket.c index c78f61b..68f58ca 100644 --- a/server/aesdsocket.c +++ b/server/aesdsocket.c @@ -51,6 +51,7 @@ typedef struct thread_info_s thread_info_t; typedef struct slist_data_s my_threads; pthread_mutex_t writeSocket = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t size_val = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t ll_lock = PTHREAD_MUTEX_INITIALIZER; struct thread_info_s{ @@ -173,10 +174,10 @@ void closeAll(int exit_flag) if(sockfd != -1) close(sockfd); if(new_fd != -1) close(new_fd); if(recvfile_fd != -1) close(recvfile_fd); - //if(remove(recvfile) != 0) - //{ - // syslog(LOG_ERR, "File removal not successful"); - //} + if(remove(recvfile) != 0) + { + syslog(LOG_ERR, "File removal not successful"); + } pthread_mutex_destroy(&writeSocket); syslog(LOG_DEBUG, "CLEANUP COMPLETED."); closelog(); @@ -187,7 +188,7 @@ void closeAll(int exit_flag) void *threadfunc(void *args) { my_threads *thread_func_args = (my_threads *) args; - syslog(LOG_DEBUG, "I have entered this thread with threadID = %lu", thread_func_args->thread_info.threadid); + syslog(LOG_DEBUG, "Entered Thread: ID = %lu, AFD = %d", thread_func_args->thread_info.threadid, thread_func_args->thread_info.afd); bool isPacketValid = false; ssize_t bytes_rx = 0; ssize_t bytes_read = 0; @@ -206,34 +207,29 @@ void *threadfunc(void *args) } memset(my_buffer, 0, BUF_SIZE); - + int errnum; do{ - bytes_rx = recv(new_fd, my_buffer+supplementBuf, BUF_SIZE-1, 0); - for (int i = 0; i < bytes_rx; i++) - { - syslog(LOG_DEBUG, "receiving: %c", my_buffer[i]); - } + bytes_rx = recv(thread_func_args->thread_info.afd, my_buffer+supplementBuf, BUF_SIZE-1, 0); + syslog(LOG_DEBUG, "Receiving: %s", my_buffer); + // syslog(LOG_DEBUG, "new_fd is %d", thread_func_args->thread_info.afd); syslog(LOG_DEBUG, "I have received %ld bytes", bytes_rx); if (bytes_rx < 0) { + errnum = errno; free(my_buffer); - perror("server: recv"); - syslog(LOG_ERR, "server: recv"); + syslog(LOG_ERR, "server: recv, errno is %d", errnum); + syslog(LOG_ERR, "Error Msg: %s", strerror(errno)); closeAll(EXIT_FAILURE); } supplementBuf += bytes_rx; - syslog(LOG_DEBUG, "supplementBuf is %ld in thread ID : %lu", supplementBuf, thread_func_args->thread_info.threadid); + //syslog(LOG_DEBUG, "supplementBuf is %ld in thread ID : %lu, AFD: %d", supplementBuf, thread_func_args->thread_info.threadid, thread_func_args->thread_info.afd); new_line = strchr(my_buffer, '\n'); //if NULL, keep getting packets if (new_line != NULL) { - syslog(LOG_DEBUG, "yay, newline character found!"); - // for (int i = 0; i < supplementBuf; i++) - // { - // syslog(LOG_DEBUG, "%c", my_buffer[i]); - // } + //syslog(LOG_DEBUG, "yay, newline character found!"); isPacketValid = true; supplementBuf = new_line - my_buffer + 1; - syslog(LOG_DEBUG, "supplementBuf size with newline found is %ld with thread ID : %lu", supplementBuf, thread_func_args->thread_info.threadid); + //syslog(LOG_DEBUG, "supplementBuf size with newline found is %ld with thread ID : %lu", supplementBuf, thread_func_args->thread_info.threadid); } else @@ -263,6 +259,7 @@ void *threadfunc(void *args) syslog(LOG_ERR, "pthread_mutex_lock failed, error was %d", rc); perror("pthread mutex_lock failed"); } + nr = write(recvfile_fd, my_buffer, supplementBuf); rc = pthread_mutex_unlock(&writeSocket); @@ -314,7 +311,6 @@ void *threadfunc(void *args) } - rc = pthread_mutex_lock(&writeSocket); if (rc != 0) { @@ -328,25 +324,34 @@ void *threadfunc(void *args) perror("server: lseek"); closeAll(EXIT_FAILURE); } - syslog(LOG_DEBUG, "lseek pass"); + rc = pthread_mutex_unlock(&writeSocket); + if (rc != 0) + { + syslog(LOG_ERR, "pthread_mutex_unlock failed, error was %d", rc); + perror("pthread mutex_unlock failed"); + } + + + //syslog(LOG_DEBUG, "lseek pass"); + + int errnum9 = 0; while ((bytes_read = read(recvfile_fd, send_my_buffer, total_size)) > 0) { syslog(LOG_DEBUG, "bytes_read is %ld", bytes_read); - for(int i = 0; i < bytes_read; i++) - { - syslog(LOG_DEBUG, "send: %c",send_my_buffer[i]); - } - if (send(new_fd, send_my_buffer, bytes_read, 0) != bytes_read) + syslog(LOG_DEBUG, "Sending: %s",send_my_buffer); + if (send(thread_func_args->thread_info.afd, send_my_buffer, bytes_read, 0) != bytes_read) { + errnum9 = errno; syslog(LOG_DEBUG,"HEREEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"); - syslog(LOG_ERR,"server: send"); - rc = pthread_mutex_unlock(&writeSocket); - if (rc != 0) - { - syslog(LOG_ERR, "pthread_mutex_unlock failed, error was %d", rc); - perror("pthread mutex_unlock failed"); - } + syslog(LOG_ERR, "server: send, errno is %d", errnum9); + syslog(LOG_ERR, "error string is %s", strerror(errno)); + // rc = pthread_mutex_unlock(&writeSocket); + // if (rc != 0) + // { + // syslog(LOG_ERR, "pthread_mutex_unlock failed, error was %d", rc); + // perror("pthread mutex_unlock failed"); + // } perror("server: send"); closeAll(EXIT_FAILURE); } @@ -358,18 +363,20 @@ void *threadfunc(void *args) } } - rc = pthread_mutex_unlock(&writeSocket); - if (rc != 0) - { - syslog(LOG_ERR, "pthread_mutex_unlock failed, error was %d", rc); - perror("pthread mutex_unlock failed"); - } - syslog(LOG_DEBUG, "_________________________________________________________"); thread_func_args->thread_info.thread_complete_success = true; - close(new_fd); + // if (close(new_fd) == -1) + // { + // syslog(LOG_ERR, "new_fd failed to close"); + // } + // else + // { + // syslog(LOG_DEBUG, "new_fd: %d successfully closed.", thread_func_args->thread_info.afd); + // } + syslog(LOG_DEBUG, "About to exit thread ID = %lu", thread_func_args->thread_info.threadid); - pthread_exit(NULL); + syslog(LOG_DEBUG, "_________________________________________________________"); + return 0; } int main(int argc, char *argv[]) @@ -486,7 +493,7 @@ int main(int argc, char *argv[]) continue; } - syslog(LOG_DEBUG, "Connected + Accepted, new_fd is %d", new_fd); + //syslog(LOG_DEBUG, "Connected + Accepted, new_fd is %d", new_fd); inet_ntop(AF_INET, &(peer_addr.sin_addr), ip4, sizeof(ip4)); //syslog(LOG_DEBUG, "Accepted connection from %s", ip4); @@ -500,7 +507,15 @@ int main(int argc, char *argv[]) //should I be exiting everything here or just keep trying } - thread_data->thread_info.afd = new_fd; + thread_data->thread_info.afd = dup(new_fd); + if(thread_data->thread_info.afd == -1) + { + syslog(LOG_ERR, "Failed to duplicate file descriptor"); + free(thread_data); + close(new_fd); + continue; + } + close(new_fd); thread_data->thread_info.thread_complete_success = false; strcpy(thread_data->thread_info.ip4, ip4); @@ -517,15 +532,36 @@ int main(int argc, char *argv[]) else { - syslog(LOG_DEBUG, "pthread_created successfully"); - syslog(LOG_DEBUG, "The threadID is %lu.", thread_data->thread_info.threadid); + syslog(LOG_DEBUG, "pthread_created successfully. The threadID is %lu. AFD: %d", thread_data->thread_info.threadid, thread_data->thread_info.afd); } + + rc = pthread_mutex_lock(&ll_lock); + if (rc != 0) + { + syslog(LOG_ERR, "pthread_mutex_lock failed on ll_lock, error was %d", rc); + perror("pthread mutex_lock failed"); + } SLIST_INSERT_HEAD(&head, thread_data, nextThread); + rc = pthread_mutex_unlock(&ll_lock); + if (rc != 0) + { + syslog(LOG_ERR, "pthread_mutex_unlock failed on ll_lock, error was %d", rc); + perror("pthread mutex_lock failed"); + } + int join_rc; my_threads *datap = NULL; my_threads *temp = NULL; + + rc = pthread_mutex_lock(&ll_lock); + if (rc != 0) + { + syslog(LOG_ERR, "pthread_mutex_lock failed on ll_lock, error was %d", rc); + perror("pthread mutex_lock failed"); + } + SLIST_FOREACH_SAFE(datap, &head, nextThread, temp) { if(datap->thread_info.thread_complete_success) @@ -544,9 +580,16 @@ int main(int argc, char *argv[]) } else { - syslog(LOG_DEBUG, "I did not join on threadID = %lu", datap->thread_info.threadid); + //syslog(LOG_DEBUG, "I did not join on threadID = %lu", datap->thread_info.threadid); } } + + rc = pthread_mutex_unlock(&ll_lock); + if (rc != 0) + { + syslog(LOG_ERR, "pthread_mutex_unlock failed on ll_lock, error was %d", rc); + perror("pthread mutex_lock failed"); + } } syslog(LOG_DEBUG, "Do I reach here?"); diff --git a/server/valgrind-out.txt b/server/valgrind-out.txt index a341758..0fc4e1e 100644 --- a/server/valgrind-out.txt +++ b/server/valgrind-out.txt @@ -1,173 +1,192 @@ -==6960== Memcheck, a memory error detector -==6960== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. -==6960== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info -==6960== Command: ./aesdsocket -==6960== Parent PID: 6956 -==6960== ---6960-- ---6960-- Valgrind options: ---6960-- --error-exitcode=1 ---6960-- --leak-check=full ---6960-- --show-leak-kinds=all ---6960-- --track-origins=yes ---6960-- --errors-for-leak-kinds=definite ---6960-- --verbose ---6960-- --log-file=valgrind-out.txt ---6960-- Contents of /proc/version: ---6960-- Linux version 5.15.0-122-generic (buildd@lcy02-amd64-106) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #132~20.04.1-Ubuntu SMP Fri Aug 30 15:50:07 UTC 2024 ---6960-- ---6960-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3 ---6960-- Page sizes: currently 4096, max supported 4096 ---6960-- Valgrind library directory: /usr/lib/x86_64-linux-gnu/valgrind ---6960-- Reading syms from /home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocket ---6960-- Reading syms from /usr/lib/x86_64-linux-gnu/ld-2.31.so ---6960-- Considering /usr/lib/debug/.build-id/db/0420f708b806cf03260aadb916c330049580b7.debug .. ---6960-- .. build-id is valid ---6960-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-linux ---6960-- object doesn't have a symbol table ---6960-- object doesn't have a dynamic symbol table ---6960-- Scheduler: using generic scheduler lock implementation. ---6960-- Reading suppressions file: /usr/lib/x86_64-linux-gnu/valgrind/default.supp -==6960== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-6960-by-stamrakar-on-??? -==6960== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-6960-by-stamrakar-on-??? -==6960== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-6960-by-stamrakar-on-??? -==6960== -==6960== TO CONTROL THIS PROCESS USING vgdb (which you probably -==6960== don't want to do, unless you know exactly what you're doing, -==6960== or are doing some strange experiment): -==6960== /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=6960 ...command... -==6960== -==6960== TO DEBUG THIS PROCESS USING GDB: start GDB like this -==6960== /path/to/gdb ./aesdsocket -==6960== and then give GDB the following command -==6960== target remote | /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=6960 -==6960== --pid is optional if only one valgrind process is running -==6960== ---6960-- REDIR: 0x4022e20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9ce2 (???) ---6960-- REDIR: 0x4022bf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c9cfc (???) ---6960-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_core-amd64-linux.so ---6960-- object doesn't have a symbol table ---6960-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so ---6960-- object doesn't have a symbol table -==6960== WARNING: new redirection conflicts with existing -- ignoring it ---6960-- old: 0x04022e20 (strlen ) R-> (0000.0) 0x580c9ce2 ??? ---6960-- new: 0x04022e20 (strlen ) R-> (2007.0) 0x0483f060 strlen ---6960-- REDIR: 0x401f600 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ffd0 (strcmp) ---6960-- REDIR: 0x4023380 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4843a20 (mempcpy) ---6960-- Reading syms from /usr/lib/x86_64-linux-gnu/libpthread-2.31.so ---6960-- Considering /usr/lib/debug/.build-id/9a/65bb469e45a1c6fbcffae5b82a2fd7a69eb479.debug .. ---6960-- .. build-id is valid ---6960-- Reading syms from /usr/lib/x86_64-linux-gnu/libc-2.31.so ---6960-- Considering /usr/lib/debug/.build-id/07/02430aef5fa3dda43986563e9ffcc47efbd75e.debug .. ---6960-- .. build-id is valid ---6960-- REDIR: 0x4920480 (libc.so.6:memmove) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x491f780 (libc.so.6:strncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x49207b0 (libc.so.6:strcasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x491f0a0 (libc.so.6:strcat) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x491f7e0 (libc.so.6:rindex) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x4921c50 (libc.so.6:rawmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x493cce0 (libc.so.6:wmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x493c820 (libc.so.6:wcscmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x49205e0 (libc.so.6:mempcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x4920410 (libc.so.6:bcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x491f710 (libc.so.6:strncmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x491f150 (libc.so.6:strcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x4920540 (libc.so.6:memset) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x493c7e0 (libc.so.6:wcschr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x491f670 (libc.so.6:strnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x491f230 (libc.so.6:strcspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x4920800 (libc.so.6:strncasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x491f1d0 (libc.so.6:strcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x4920950 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x493df50 (libc.so.6:wcsnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x493c860 (libc.so.6:wcscpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x491f820 (libc.so.6:strpbrk) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x491f100 (libc.so.6:index) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x491f630 (libc.so.6:strlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x4928bb0 (libc.so.6:memrchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x4920850 (libc.so.6:strcasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x49203d0 (libc.so.6:memchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x493c930 (libc.so.6:wcslen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x491fae0 (libc.so.6:strspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x4920750 (libc.so.6:stpncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x49206f0 (libc.so.6:stpcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x4921c90 (libc.so.6:strchrnul) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x49208a0 (libc.so.6:strncasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---6960-- REDIR: 0x49318c0 (libc.so.6:__strrchr_sse2) redirected to 0x483ea70 (__strrchr_sse2) ---6960-- REDIR: 0x491a0e0 (libc.so.6:malloc) redirected to 0x483b780 (malloc) ---6960-- REDIR: 0x491bb10 (libc.so.6:calloc) redirected to 0x483dce0 (calloc) ---6960-- REDIR: 0x49316b0 (libc.so.6:__strchrnul_sse2) redirected to 0x4843540 (strchrnul) ---6960-- REDIR: 0x4931bc0 (libc.so.6:__strlen_sse2) redirected to 0x483efa0 (__strlen_sse2) ---6960-- REDIR: 0x491a6d0 (libc.so.6:free) redirected to 0x483c9d0 (free) ---6960-- REDIR: 0x493bad0 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4840100 (memcpy@GLIBC_2.2.5) ---6960-- REDIR: 0x491ffa0 (libc.so.6:__GI_strstr) redirected to 0x4843ca0 (__strstr_sse2) ---6960-- REDIR: 0x4a0d790 (libc.so.6:__memcmp_sse4_1) redirected to 0x4842150 (__memcmp_sse4_1) ---6960-- REDIR: 0x492a3b0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x483fed0 (strcmp) ---6960-- REDIR: 0x493bab0 (libc.so.6:__mempcpy_sse2_unaligned) redirected to 0x4843660 (mempcpy) ---6960-- REDIR: 0x491ae80 (libc.so.6:realloc) redirected to 0x483df30 (realloc) ---6960-- REDIR: 0x493bf00 (libc.so.6:__memset_sse2_unaligned) redirected to 0x48428e0 (memset) ---6960-- REDIR: 0x492bec0 (libc.so.6:__memchr_sse2) redirected to 0x4840050 (memchr) ---6960-- REDIR: 0x4931480 (libc.so.6:__strchr_sse2) redirected to 0x483eb90 (__strchr_sse2) ---6960-- REDIR: 0x4936b00 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x483f090 (strcpy) -==6960== Thread 2: -==6960== Syscall param read(buf) points to unaddressable byte(s) -==6960== at 0x48703CC: __libc_read (read.c:26) -==6960== by 0x48703CC: read (read.c:24) -==6960== by 0x10AFFB: threadfunc (aesdsocket.c:317) -==6960== by 0x4865608: start_thread (pthread_create.c:477) -==6960== by 0x499F352: clone (clone.S:95) -==6960== Address 0x4add722 is 0 bytes after a block of size 18 alloc'd -==6960== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==6960== by 0x10ADED: threadfunc (aesdsocket.c:292) -==6960== by 0x4865608: start_thread (pthread_create.c:477) -==6960== by 0x499F352: clone (clone.S:95) -==6960== ---6960-- Reading syms from /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 ---6960-- object doesn't have a symbol table ---6960-- REDIR: 0x4938140 (libc.so.6:__stpcpy_sse2_unaligned) redirected to 0x4842570 (__stpcpy_sse2_unaligned) ---6960-- Discarding syms at 0x56795e0-0x568a055 in /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 (have_dinfo 1) -==6960== -==6960== HEAP SUMMARY: -==6960== in use at exit: 312 bytes in 2 blocks -==6960== total heap usage: 322 allocs, 320 frees, 875,637 bytes allocated -==6960== -==6960== Searching for pointers to 2 not-freed blocks -==6960== Checked 8,477,232 bytes -==6960== -==6960== Thread 1: -==6960== 40 bytes in 1 blocks are still reachable in loss record 1 of 2 -==6960== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==6960== by 0x10B4C2: main (aesdsocket.c:477) -==6960== -==6960== 272 bytes in 1 blocks are possibly lost in loss record 2 of 2 -==6960== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==6960== by 0x40149DA: allocate_dtv (dl-tls.c:286) -==6960== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) -==6960== by 0x4866322: allocate_stack (allocatestack.c:622) -==6960== by 0x4866322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) -==6960== by 0x10B53F: main (aesdsocket.c:492) -==6960== -==6960== LEAK SUMMARY: -==6960== definitely lost: 0 bytes in 0 blocks -==6960== indirectly lost: 0 bytes in 0 blocks -==6960== possibly lost: 272 bytes in 1 blocks -==6960== still reachable: 40 bytes in 1 blocks -==6960== suppressed: 0 bytes in 0 blocks -==6960== -==6960== ERROR SUMMARY: 3 errors from 1 contexts (suppressed: 0 from 0) -==6960== -==6960== 3 errors in context 1 of 1: -==6960== Thread 2: -==6960== Syscall param read(buf) points to unaddressable byte(s) -==6960== at 0x48703CC: __libc_read (read.c:26) -==6960== by 0x48703CC: read (read.c:24) -==6960== by 0x10AFFB: threadfunc (aesdsocket.c:317) -==6960== by 0x4865608: start_thread (pthread_create.c:477) -==6960== by 0x499F352: clone (clone.S:95) -==6960== Address 0x4add722 is 0 bytes after a block of size 18 alloc'd -==6960== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==6960== by 0x10ADED: threadfunc (aesdsocket.c:292) -==6960== by 0x4865608: start_thread (pthread_create.c:477) -==6960== by 0x499F352: clone (clone.S:95) -==6960== -==6960== ERROR SUMMARY: 3 errors from 1 contexts (suppressed: 0 from 0) +==18884== Memcheck, a memory error detector +==18884== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. +==18884== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info +==18884== Command: ./aesdsocket +==18884== Parent PID: 18882 +==18884== +--18884-- +--18884-- Valgrind options: +--18884-- --error-exitcode=1 +--18884-- --leak-check=full +--18884-- --show-leak-kinds=all +--18884-- --track-origins=yes +--18884-- --errors-for-leak-kinds=definite +--18884-- --verbose +--18884-- --log-file=valgrind-out.txt +--18884-- Contents of /proc/version: +--18884-- Linux version 5.15.0-122-generic (buildd@lcy02-amd64-106) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #132~20.04.1-Ubuntu SMP Fri Aug 30 15:50:07 UTC 2024 +--18884-- +--18884-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3 +--18884-- Page sizes: currently 4096, max supported 4096 +--18884-- Valgrind library directory: /usr/lib/x86_64-linux-gnu/valgrind +--18884-- Reading syms from /home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocket +--18884-- Reading syms from /usr/lib/x86_64-linux-gnu/ld-2.31.so +--18884-- Considering /usr/lib/debug/.build-id/db/0420f708b806cf03260aadb916c330049580b7.debug .. +--18884-- .. build-id is valid +--18884-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-linux +--18884-- object doesn't have a symbol table +--18884-- object doesn't have a dynamic symbol table +--18884-- Scheduler: using generic scheduler lock implementation. +--18884-- Reading suppressions file: /usr/lib/x86_64-linux-gnu/valgrind/default.supp +==18884== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-18884-by-stamrakar-on-??? +==18884== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-18884-by-stamrakar-on-??? +==18884== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-18884-by-stamrakar-on-??? +==18884== +==18884== TO CONTROL THIS PROCESS USING vgdb (which you probably +==18884== don't want to do, unless you know exactly what you're doing, +==18884== or are doing some strange experiment): +==18884== /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=18884 ...command... +==18884== +==18884== TO DEBUG THIS PROCESS USING GDB: start GDB like this +==18884== /path/to/gdb ./aesdsocket +==18884== and then give GDB the following command +==18884== target remote | /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=18884 +==18884== --pid is optional if only one valgrind process is running +==18884== +--18884-- REDIR: 0x4022e20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9ce2 (???) +--18884-- REDIR: 0x4022bf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c9cfc (???) +--18884-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_core-amd64-linux.so +--18884-- object doesn't have a symbol table +--18884-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so +--18884-- object doesn't have a symbol table +==18884== WARNING: new redirection conflicts with existing -- ignoring it +--18884-- old: 0x04022e20 (strlen ) R-> (0000.0) 0x580c9ce2 ??? +--18884-- new: 0x04022e20 (strlen ) R-> (2007.0) 0x0483f060 strlen +--18884-- REDIR: 0x401f600 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ffd0 (strcmp) +--18884-- REDIR: 0x4023380 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4843a20 (mempcpy) +--18884-- Reading syms from /usr/lib/x86_64-linux-gnu/libpthread-2.31.so +--18884-- Considering /usr/lib/debug/.build-id/9a/65bb469e45a1c6fbcffae5b82a2fd7a69eb479.debug .. +--18884-- .. build-id is valid +--18884-- Reading syms from /usr/lib/x86_64-linux-gnu/libc-2.31.so +--18884-- Considering /usr/lib/debug/.build-id/07/02430aef5fa3dda43986563e9ffcc47efbd75e.debug .. +--18884-- .. build-id is valid +--18884-- REDIR: 0x4920480 (libc.so.6:memmove) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x491f780 (libc.so.6:strncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x49207b0 (libc.so.6:strcasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x491f0a0 (libc.so.6:strcat) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x491f7e0 (libc.so.6:rindex) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x4921c50 (libc.so.6:rawmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x493cce0 (libc.so.6:wmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x493c820 (libc.so.6:wcscmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x49205e0 (libc.so.6:mempcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x4920410 (libc.so.6:bcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x491f710 (libc.so.6:strncmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x491f150 (libc.so.6:strcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x4920540 (libc.so.6:memset) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x493c7e0 (libc.so.6:wcschr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x491f670 (libc.so.6:strnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x491f230 (libc.so.6:strcspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x4920800 (libc.so.6:strncasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x491f1d0 (libc.so.6:strcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x4920950 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x493df50 (libc.so.6:wcsnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x493c860 (libc.so.6:wcscpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x491f820 (libc.so.6:strpbrk) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x491f100 (libc.so.6:index) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x491f630 (libc.so.6:strlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x4928bb0 (libc.so.6:memrchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x4920850 (libc.so.6:strcasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x49203d0 (libc.so.6:memchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x493c930 (libc.so.6:wcslen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x491fae0 (libc.so.6:strspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x4920750 (libc.so.6:stpncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x49206f0 (libc.so.6:stpcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x4921c90 (libc.so.6:strchrnul) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x49208a0 (libc.so.6:strncasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--18884-- REDIR: 0x49318c0 (libc.so.6:__strrchr_sse2) redirected to 0x483ea70 (__strrchr_sse2) +--18884-- REDIR: 0x491a0e0 (libc.so.6:malloc) redirected to 0x483b780 (malloc) +--18884-- REDIR: 0x491bb10 (libc.so.6:calloc) redirected to 0x483dce0 (calloc) +--18884-- REDIR: 0x49316b0 (libc.so.6:__strchrnul_sse2) redirected to 0x4843540 (strchrnul) +--18884-- REDIR: 0x4931bc0 (libc.so.6:__strlen_sse2) redirected to 0x483efa0 (__strlen_sse2) +--18884-- REDIR: 0x491a6d0 (libc.so.6:free) redirected to 0x483c9d0 (free) +--18884-- REDIR: 0x493bad0 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4840100 (memcpy@GLIBC_2.2.5) +--18884-- REDIR: 0x491ffa0 (libc.so.6:__GI_strstr) redirected to 0x4843ca0 (__strstr_sse2) +--18884-- REDIR: 0x4a0d790 (libc.so.6:__memcmp_sse4_1) redirected to 0x4842150 (__memcmp_sse4_1) +--18884-- REDIR: 0x492a3b0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x483fed0 (strcmp) +--18884-- REDIR: 0x493bf00 (libc.so.6:__memset_sse2_unaligned) redirected to 0x48428e0 (memset) +--18884-- REDIR: 0x493bab0 (libc.so.6:__mempcpy_sse2_unaligned) redirected to 0x4843660 (mempcpy) +--18884-- REDIR: 0x491ae80 (libc.so.6:realloc) redirected to 0x483df30 (realloc) +--18884-- REDIR: 0x492bec0 (libc.so.6:__memchr_sse2) redirected to 0x4840050 (memchr) +--18884-- REDIR: 0x4931480 (libc.so.6:__strchr_sse2) redirected to 0x483eb90 (__strchr_sse2) +--18884-- REDIR: 0x4936b00 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x483f090 (strcpy) +==18884== Thread 2: +==18884== Conditional jump or move depends on uninitialised value(s) +==18884== at 0x483EFB8: __strlen_sse2 (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==18884== by 0x48F8D14: __vfprintf_internal (vfprintf-internal.c:1688) +==18884== by 0x4997FF2: __vsyslog_internal (syslog.c:233) +==18884== by 0x49984A9: syslog (syslog.c:117) +==18884== by 0x10AF7F: threadfunc (aesdsocket.c:342) +==18884== by 0x4865608: start_thread (pthread_create.c:477) +==18884== by 0x499F352: clone (clone.S:95) +==18884== Uninitialised value was created by a heap allocation +==18884== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==18884== by 0x10AE4D: threadfunc (aesdsocket.c:306) +==18884== by 0x4865608: start_thread (pthread_create.c:477) +==18884== by 0x499F352: clone (clone.S:95) +==18884== +==18884== Syscall param read(buf) points to unaddressable byte(s) +==18884== at 0x48703CC: __libc_read (read.c:26) +==18884== by 0x48703CC: read (read.c:24) +==18884== by 0x10B062: threadfunc (aesdsocket.c:340) +==18884== by 0x4865608: start_thread (pthread_create.c:477) +==18884== by 0x499F352: clone (clone.S:95) +==18884== Address 0x0 is not stack'd, malloc'd or (recently) free'd +==18884== +--18884-- REDIR: 0x4938140 (libc.so.6:__stpcpy_sse2_unaligned) redirected to 0x4842570 (__stpcpy_sse2_unaligned) +==18884== +==18884== HEAP SUMMARY: +==18884== in use at exit: 312 bytes in 2 blocks +==18884== total heap usage: 766 allocs, 764 frees, 2,091,702 bytes allocated +==18884== +==18884== Searching for pointers to 2 not-freed blocks +==18884== Checked 8,477,232 bytes +==18884== +==18884== Thread 1: +==18884== 40 bytes in 1 blocks are still reachable in loss record 1 of 2 +==18884== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==18884== by 0x10B4BF: main (aesdsocket.c:501) +==18884== +==18884== 272 bytes in 1 blocks are possibly lost in loss record 2 of 2 +==18884== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==18884== by 0x40149DA: allocate_dtv (dl-tls.c:286) +==18884== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) +==18884== by 0x4866322: allocate_stack (allocatestack.c:622) +==18884== by 0x4866322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) +==18884== by 0x10B590: main (aesdsocket.c:524) +==18884== +==18884== LEAK SUMMARY: +==18884== definitely lost: 0 bytes in 0 blocks +==18884== indirectly lost: 0 bytes in 0 blocks +==18884== possibly lost: 272 bytes in 1 blocks +==18884== still reachable: 40 bytes in 1 blocks +==18884== suppressed: 0 bytes in 0 blocks +==18884== +==18884== ERROR SUMMARY: 34 errors from 2 contexts (suppressed: 0 from 0) +==18884== +==18884== 17 errors in context 1 of 2: +==18884== Thread 2: +==18884== Syscall param read(buf) points to unaddressable byte(s) +==18884== at 0x48703CC: __libc_read (read.c:26) +==18884== by 0x48703CC: read (read.c:24) +==18884== by 0x10B062: threadfunc (aesdsocket.c:340) +==18884== by 0x4865608: start_thread (pthread_create.c:477) +==18884== by 0x499F352: clone (clone.S:95) +==18884== Address 0x0 is not stack'd, malloc'd or (recently) free'd +==18884== +==18884== +==18884== 17 errors in context 2 of 2: +==18884== Conditional jump or move depends on uninitialised value(s) +==18884== at 0x483EFB8: __strlen_sse2 (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==18884== by 0x48F8D14: __vfprintf_internal (vfprintf-internal.c:1688) +==18884== by 0x4997FF2: __vsyslog_internal (syslog.c:233) +==18884== by 0x49984A9: syslog (syslog.c:117) +==18884== by 0x10AF7F: threadfunc (aesdsocket.c:342) +==18884== by 0x4865608: start_thread (pthread_create.c:477) +==18884== by 0x499F352: clone (clone.S:95) +==18884== Uninitialised value was created by a heap allocation +==18884== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==18884== by 0x10AE4D: threadfunc (aesdsocket.c:306) +==18884== by 0x4865608: start_thread (pthread_create.c:477) +==18884== by 0x499F352: clone (clone.S:95) +==18884== +==18884== ERROR SUMMARY: 34 errors from 2 contexts (suppressed: 0 from 0) From 50595cb08c7d1d4bdb5ad1d1da3cd21d82b98fa0 Mon Sep 17 00:00:00 2001 From: stamrakar Date: Mon, 14 Oct 2024 13:04:25 -0600 Subject: [PATCH 08/17] timer not working properly, firing soon --- server/Makefile | 2 +- server/aesdsocket.c | 128 ++++++++++--- server/aesdsocketdata | 17 ++ server/valgrind-out.txt | 407 +++++++++++++++++++++------------------- 4 files changed, 338 insertions(+), 216 deletions(-) create mode 100644 server/aesdsocketdata diff --git a/server/Makefile b/server/Makefile index 65aaf51..c4d91ae 100644 --- a/server/Makefile +++ b/server/Makefile @@ -32,7 +32,7 @@ clean: -rm -f aesdsocket aesdsocket: ${OBJS} - $(CROSS_COMPILE)$(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) -pthread + $(CROSS_COMPILE)$(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) -pthread -lrt depend: diff --git a/server/aesdsocket.c b/server/aesdsocket.c index 68f58ca..e321fdc 100644 --- a/server/aesdsocket.c +++ b/server/aesdsocket.c @@ -9,7 +9,7 @@ * ****************************************************************************/ /** * @file aesdsocket.c - * @brief Assignment 5 Part 1. Socket based program + * @brief Assignment 5,6 Part 1. Socket based program * @author Sonal Tamrakar * @date 10-07-2024 * @credit Beej's Guide to Network Programming @@ -37,6 +37,9 @@ #include #include #include +#include +#include +#include //#include #include "queue.h" @@ -44,11 +47,13 @@ //const char* port = "9000"; //optional -#define BACKLOG 10 // pending connections +#define BACKLOG (10) // pending connections #define BUF_SIZE 1024 +#define TSTAMP_INTERVAL (10) typedef struct thread_info_s thread_info_t; typedef struct slist_data_s my_threads; +static timer_t timerid; pthread_mutex_t writeSocket = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t size_val = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t ll_lock = PTHREAD_MUTEX_INITIALIZER; @@ -81,11 +86,13 @@ int recvfile_fd = -1; static ssize_t total_size = 0; pid_t pid; -const char *recvfile = "/var/tmp/aesdsocketdata"; -//const char *recvfile = "/home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocketdata"; +//const char *recvfile = "/var/tmp/aesdsocketdata"; +const char *recvfile = "/home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocketdata"; static void closeAll(int exit_flag); +static void initTimer(void); static void init_sigHandler(void); static void signal_handler(int signal_number); +static void timer_handler(int signal_number); void *threadfunc(void *arg); static void signal_handler (int signal_number) @@ -97,6 +104,47 @@ static void signal_handler (int signal_number) } } +static void timer_handler(int signal_number) +{ + int rc; + ssize_t nr; + ssize_t strf_ret; + time_t now; + struct tm *ttime; + char curr_tstamp[50]; + time(&now); + ttime = localtime(&now); + + + strf_ret = strftime(curr_tstamp, sizeof(curr_tstamp), "timestamp:%Y %b %d %H:%M:%S\n", ttime); + + if (!strf_ret) + { + syslog(LOG_ERR, "strftime error, receiving 0 bytes"); + } + + rc = pthread_mutex_lock(&writeSocket); + if (rc != 0) + { + syslog(LOG_ERR, "pthread_mutex_lock failed, error was %d", rc); + perror("pthread mutex_lock failed"); + } + + nr = write(recvfile_fd, curr_tstamp, strf_ret); + + rc = pthread_mutex_unlock(&writeSocket); + if (rc != 0) + { + syslog(LOG_ERR, "pthread_mutex_unlock failed, error was %d", rc); + perror("pthread mutex_unlock failed"); + } + + if(nr != strf_ret) + { + syslog(LOG_DEBUG, "Inconsistent bytes written"); + } + +} static void init_sigHandler(void) { @@ -167,17 +215,62 @@ static int create_daemon() return 0; } +static void initTimer(void) +{ + struct sigaction sigt; + struct sigevent sev; + struct itimerspec mytime; + + memset(&sigt, 0, sizeof(struct sigaction)); + sigt.sa_handler = timer_handler; + if( sigaction(SIGALRM, &sigt, NULL) != 0) + { + syslog(LOG_ERR, "Error %d (%s) registering for SIGALRM", errno, strerror(errno)); + perror("sigalrm: fail"); + closeAll(EXIT_FAILURE); + } + + sev.sigev_notify = SIGEV_SIGNAL; + //sev.sigev_notify_function = &timer_handler; + sev.sigev_signo = SIGALRM; + if (timer_create(CLOCK_MONOTONIC, &sev, &timerid) == -1) + { + perror("initTimer: timer_create"); + syslog(LOG_ERR, "Error creating timer: %s", strerror(errno)); + return; + } + + mytime.it_value.tv_sec = TSTAMP_INTERVAL; + mytime.it_value.tv_nsec = 0; + mytime.it_interval.tv_sec = TSTAMP_INTERVAL; + mytime.it_interval.tv_nsec = 0; + + + + if(timer_settime(timerid, 0, &mytime, NULL) == -1) + { + perror("initTimer: timer_settime"); + syslog(LOG_ERR, "Timer couldn't be started: %s", strerror(errno)); + } + + + + return; +} void closeAll(int exit_flag) { + //int rc; syslog(LOG_DEBUG, "PERFORMING CLEANUP."); if(sockfd != -1) close(sockfd); if(new_fd != -1) close(new_fd); if(recvfile_fd != -1) close(recvfile_fd); - if(remove(recvfile) != 0) - { - syslog(LOG_ERR, "File removal not successful"); - } + // if(remove(recvfile) != 0) + // { + // syslog(LOG_ERR, "File removal not successful"); + // } + + timer_delete(timerid); pthread_mutex_destroy(&writeSocket); syslog(LOG_DEBUG, "CLEANUP COMPLETED."); closelog(); @@ -346,12 +439,6 @@ void *threadfunc(void *args) syslog(LOG_DEBUG,"HEREEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"); syslog(LOG_ERR, "server: send, errno is %d", errnum9); syslog(LOG_ERR, "error string is %s", strerror(errno)); - // rc = pthread_mutex_unlock(&writeSocket); - // if (rc != 0) - // { - // syslog(LOG_ERR, "pthread_mutex_unlock failed, error was %d", rc); - // perror("pthread mutex_unlock failed"); - // } perror("server: send"); closeAll(EXIT_FAILURE); } @@ -365,15 +452,6 @@ void *threadfunc(void *args) thread_func_args->thread_info.thread_complete_success = true; - // if (close(new_fd) == -1) - // { - // syslog(LOG_ERR, "new_fd failed to close"); - // } - // else - // { - // syslog(LOG_DEBUG, "new_fd: %d successfully closed.", thread_func_args->thread_info.afd); - // } - syslog(LOG_DEBUG, "About to exit thread ID = %lu", thread_func_args->thread_info.threadid); syslog(LOG_DEBUG, "_________________________________________________________"); return 0; @@ -479,6 +557,10 @@ int main(int argc, char *argv[]) syslog(LOG_DEBUG, "listen pass"); + initTimer(); + + syslog(LOG_DEBUG, "Timer has been set"); + syslog(LOG_DEBUG, "server: waiting for connections.........\n"); diff --git a/server/aesdsocketdata b/server/aesdsocketdata new file mode 100644 index 0000000..d2c26f9 --- /dev/null +++ b/server/aesdsocketdata @@ -0,0 +1,17 @@ +timestamp:wait-for-startup +abcdefg +hijklmnop +1234567890 +9876543210 +One best book is equal to a hundred good friends, but one good friend is equal to a library +If you want to shine like a sun, first burn like a sun +Never stop fighting until you arrive at your destined place - that is, the unique you +Never stop fighting until you arrive at your destined place - that is, the unique you +One best book is equal to a hundred good friends, but one good friend is equal to a library +If you want to shine like a sun, first burn like a sun +Never stop fighting until you arrive at your destined place - that is, the unique you +One best book is equal to a hundred good friends, but one good friend is equal to a library +If you want to shine like a sun, first burn like a sun +validate_multithreaded +test_socket_timer +test_socket_timer diff --git a/server/valgrind-out.txt b/server/valgrind-out.txt index 0fc4e1e..144ffaf 100644 --- a/server/valgrind-out.txt +++ b/server/valgrind-out.txt @@ -1,192 +1,215 @@ -==18884== Memcheck, a memory error detector -==18884== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. -==18884== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info -==18884== Command: ./aesdsocket -==18884== Parent PID: 18882 -==18884== ---18884-- ---18884-- Valgrind options: ---18884-- --error-exitcode=1 ---18884-- --leak-check=full ---18884-- --show-leak-kinds=all ---18884-- --track-origins=yes ---18884-- --errors-for-leak-kinds=definite ---18884-- --verbose ---18884-- --log-file=valgrind-out.txt ---18884-- Contents of /proc/version: ---18884-- Linux version 5.15.0-122-generic (buildd@lcy02-amd64-106) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #132~20.04.1-Ubuntu SMP Fri Aug 30 15:50:07 UTC 2024 ---18884-- ---18884-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3 ---18884-- Page sizes: currently 4096, max supported 4096 ---18884-- Valgrind library directory: /usr/lib/x86_64-linux-gnu/valgrind ---18884-- Reading syms from /home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocket ---18884-- Reading syms from /usr/lib/x86_64-linux-gnu/ld-2.31.so ---18884-- Considering /usr/lib/debug/.build-id/db/0420f708b806cf03260aadb916c330049580b7.debug .. ---18884-- .. build-id is valid ---18884-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-linux ---18884-- object doesn't have a symbol table ---18884-- object doesn't have a dynamic symbol table ---18884-- Scheduler: using generic scheduler lock implementation. ---18884-- Reading suppressions file: /usr/lib/x86_64-linux-gnu/valgrind/default.supp -==18884== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-18884-by-stamrakar-on-??? -==18884== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-18884-by-stamrakar-on-??? -==18884== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-18884-by-stamrakar-on-??? -==18884== -==18884== TO CONTROL THIS PROCESS USING vgdb (which you probably -==18884== don't want to do, unless you know exactly what you're doing, -==18884== or are doing some strange experiment): -==18884== /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=18884 ...command... -==18884== -==18884== TO DEBUG THIS PROCESS USING GDB: start GDB like this -==18884== /path/to/gdb ./aesdsocket -==18884== and then give GDB the following command -==18884== target remote | /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=18884 -==18884== --pid is optional if only one valgrind process is running -==18884== ---18884-- REDIR: 0x4022e20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9ce2 (???) ---18884-- REDIR: 0x4022bf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c9cfc (???) ---18884-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_core-amd64-linux.so ---18884-- object doesn't have a symbol table ---18884-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so ---18884-- object doesn't have a symbol table -==18884== WARNING: new redirection conflicts with existing -- ignoring it ---18884-- old: 0x04022e20 (strlen ) R-> (0000.0) 0x580c9ce2 ??? ---18884-- new: 0x04022e20 (strlen ) R-> (2007.0) 0x0483f060 strlen ---18884-- REDIR: 0x401f600 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ffd0 (strcmp) ---18884-- REDIR: 0x4023380 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4843a20 (mempcpy) ---18884-- Reading syms from /usr/lib/x86_64-linux-gnu/libpthread-2.31.so ---18884-- Considering /usr/lib/debug/.build-id/9a/65bb469e45a1c6fbcffae5b82a2fd7a69eb479.debug .. ---18884-- .. build-id is valid ---18884-- Reading syms from /usr/lib/x86_64-linux-gnu/libc-2.31.so ---18884-- Considering /usr/lib/debug/.build-id/07/02430aef5fa3dda43986563e9ffcc47efbd75e.debug .. ---18884-- .. build-id is valid ---18884-- REDIR: 0x4920480 (libc.so.6:memmove) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x491f780 (libc.so.6:strncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x49207b0 (libc.so.6:strcasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x491f0a0 (libc.so.6:strcat) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x491f7e0 (libc.so.6:rindex) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x4921c50 (libc.so.6:rawmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x493cce0 (libc.so.6:wmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x493c820 (libc.so.6:wcscmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x49205e0 (libc.so.6:mempcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x4920410 (libc.so.6:bcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x491f710 (libc.so.6:strncmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x491f150 (libc.so.6:strcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x4920540 (libc.so.6:memset) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x493c7e0 (libc.so.6:wcschr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x491f670 (libc.so.6:strnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x491f230 (libc.so.6:strcspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x4920800 (libc.so.6:strncasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x491f1d0 (libc.so.6:strcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x4920950 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x493df50 (libc.so.6:wcsnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x493c860 (libc.so.6:wcscpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x491f820 (libc.so.6:strpbrk) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x491f100 (libc.so.6:index) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x491f630 (libc.so.6:strlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x4928bb0 (libc.so.6:memrchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x4920850 (libc.so.6:strcasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x49203d0 (libc.so.6:memchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x493c930 (libc.so.6:wcslen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x491fae0 (libc.so.6:strspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x4920750 (libc.so.6:stpncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x49206f0 (libc.so.6:stpcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x4921c90 (libc.so.6:strchrnul) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x49208a0 (libc.so.6:strncasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---18884-- REDIR: 0x49318c0 (libc.so.6:__strrchr_sse2) redirected to 0x483ea70 (__strrchr_sse2) ---18884-- REDIR: 0x491a0e0 (libc.so.6:malloc) redirected to 0x483b780 (malloc) ---18884-- REDIR: 0x491bb10 (libc.so.6:calloc) redirected to 0x483dce0 (calloc) ---18884-- REDIR: 0x49316b0 (libc.so.6:__strchrnul_sse2) redirected to 0x4843540 (strchrnul) ---18884-- REDIR: 0x4931bc0 (libc.so.6:__strlen_sse2) redirected to 0x483efa0 (__strlen_sse2) ---18884-- REDIR: 0x491a6d0 (libc.so.6:free) redirected to 0x483c9d0 (free) ---18884-- REDIR: 0x493bad0 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4840100 (memcpy@GLIBC_2.2.5) ---18884-- REDIR: 0x491ffa0 (libc.so.6:__GI_strstr) redirected to 0x4843ca0 (__strstr_sse2) ---18884-- REDIR: 0x4a0d790 (libc.so.6:__memcmp_sse4_1) redirected to 0x4842150 (__memcmp_sse4_1) ---18884-- REDIR: 0x492a3b0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x483fed0 (strcmp) ---18884-- REDIR: 0x493bf00 (libc.so.6:__memset_sse2_unaligned) redirected to 0x48428e0 (memset) ---18884-- REDIR: 0x493bab0 (libc.so.6:__mempcpy_sse2_unaligned) redirected to 0x4843660 (mempcpy) ---18884-- REDIR: 0x491ae80 (libc.so.6:realloc) redirected to 0x483df30 (realloc) ---18884-- REDIR: 0x492bec0 (libc.so.6:__memchr_sse2) redirected to 0x4840050 (memchr) ---18884-- REDIR: 0x4931480 (libc.so.6:__strchr_sse2) redirected to 0x483eb90 (__strchr_sse2) ---18884-- REDIR: 0x4936b00 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x483f090 (strcpy) -==18884== Thread 2: -==18884== Conditional jump or move depends on uninitialised value(s) -==18884== at 0x483EFB8: __strlen_sse2 (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==18884== by 0x48F8D14: __vfprintf_internal (vfprintf-internal.c:1688) -==18884== by 0x4997FF2: __vsyslog_internal (syslog.c:233) -==18884== by 0x49984A9: syslog (syslog.c:117) -==18884== by 0x10AF7F: threadfunc (aesdsocket.c:342) -==18884== by 0x4865608: start_thread (pthread_create.c:477) -==18884== by 0x499F352: clone (clone.S:95) -==18884== Uninitialised value was created by a heap allocation -==18884== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==18884== by 0x10AE4D: threadfunc (aesdsocket.c:306) -==18884== by 0x4865608: start_thread (pthread_create.c:477) -==18884== by 0x499F352: clone (clone.S:95) -==18884== -==18884== Syscall param read(buf) points to unaddressable byte(s) -==18884== at 0x48703CC: __libc_read (read.c:26) -==18884== by 0x48703CC: read (read.c:24) -==18884== by 0x10B062: threadfunc (aesdsocket.c:340) -==18884== by 0x4865608: start_thread (pthread_create.c:477) -==18884== by 0x499F352: clone (clone.S:95) -==18884== Address 0x0 is not stack'd, malloc'd or (recently) free'd -==18884== ---18884-- REDIR: 0x4938140 (libc.so.6:__stpcpy_sse2_unaligned) redirected to 0x4842570 (__stpcpy_sse2_unaligned) -==18884== -==18884== HEAP SUMMARY: -==18884== in use at exit: 312 bytes in 2 blocks -==18884== total heap usage: 766 allocs, 764 frees, 2,091,702 bytes allocated -==18884== -==18884== Searching for pointers to 2 not-freed blocks -==18884== Checked 8,477,232 bytes -==18884== -==18884== Thread 1: -==18884== 40 bytes in 1 blocks are still reachable in loss record 1 of 2 -==18884== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==18884== by 0x10B4BF: main (aesdsocket.c:501) -==18884== -==18884== 272 bytes in 1 blocks are possibly lost in loss record 2 of 2 -==18884== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==18884== by 0x40149DA: allocate_dtv (dl-tls.c:286) -==18884== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) -==18884== by 0x4866322: allocate_stack (allocatestack.c:622) -==18884== by 0x4866322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) -==18884== by 0x10B590: main (aesdsocket.c:524) -==18884== -==18884== LEAK SUMMARY: -==18884== definitely lost: 0 bytes in 0 blocks -==18884== indirectly lost: 0 bytes in 0 blocks -==18884== possibly lost: 272 bytes in 1 blocks -==18884== still reachable: 40 bytes in 1 blocks -==18884== suppressed: 0 bytes in 0 blocks -==18884== -==18884== ERROR SUMMARY: 34 errors from 2 contexts (suppressed: 0 from 0) -==18884== -==18884== 17 errors in context 1 of 2: -==18884== Thread 2: -==18884== Syscall param read(buf) points to unaddressable byte(s) -==18884== at 0x48703CC: __libc_read (read.c:26) -==18884== by 0x48703CC: read (read.c:24) -==18884== by 0x10B062: threadfunc (aesdsocket.c:340) -==18884== by 0x4865608: start_thread (pthread_create.c:477) -==18884== by 0x499F352: clone (clone.S:95) -==18884== Address 0x0 is not stack'd, malloc'd or (recently) free'd -==18884== -==18884== -==18884== 17 errors in context 2 of 2: -==18884== Conditional jump or move depends on uninitialised value(s) -==18884== at 0x483EFB8: __strlen_sse2 (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==18884== by 0x48F8D14: __vfprintf_internal (vfprintf-internal.c:1688) -==18884== by 0x4997FF2: __vsyslog_internal (syslog.c:233) -==18884== by 0x49984A9: syslog (syslog.c:117) -==18884== by 0x10AF7F: threadfunc (aesdsocket.c:342) -==18884== by 0x4865608: start_thread (pthread_create.c:477) -==18884== by 0x499F352: clone (clone.S:95) -==18884== Uninitialised value was created by a heap allocation -==18884== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==18884== by 0x10AE4D: threadfunc (aesdsocket.c:306) -==18884== by 0x4865608: start_thread (pthread_create.c:477) -==18884== by 0x499F352: clone (clone.S:95) -==18884== -==18884== ERROR SUMMARY: 34 errors from 2 contexts (suppressed: 0 from 0) +==13967== Memcheck, a memory error detector +==13967== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. +==13967== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info +==13967== Command: ./aesdsocket +==13967== Parent PID: 13965 +==13967== +--13967-- +--13967-- Valgrind options: +--13967-- --error-exitcode=1 +--13967-- --leak-check=full +--13967-- --show-leak-kinds=all +--13967-- --track-origins=yes +--13967-- --errors-for-leak-kinds=definite +--13967-- --verbose +--13967-- --log-file=valgrind-out.txt +--13967-- Contents of /proc/version: +--13967-- Linux version 5.15.0-122-generic (buildd@lcy02-amd64-106) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #132~20.04.1-Ubuntu SMP Fri Aug 30 15:50:07 UTC 2024 +--13967-- +--13967-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3 +--13967-- Page sizes: currently 4096, max supported 4096 +--13967-- Valgrind library directory: /usr/lib/x86_64-linux-gnu/valgrind +--13967-- Reading syms from /home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocket +--13967-- Reading syms from /usr/lib/x86_64-linux-gnu/ld-2.31.so +--13967-- Considering /usr/lib/debug/.build-id/db/0420f708b806cf03260aadb916c330049580b7.debug .. +--13967-- .. build-id is valid +--13967-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-linux +--13967-- object doesn't have a symbol table +--13967-- object doesn't have a dynamic symbol table +--13967-- Scheduler: using generic scheduler lock implementation. +--13967-- Reading suppressions file: /usr/lib/x86_64-linux-gnu/valgrind/default.supp +==13967== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-13967-by-stamrakar-on-??? +==13967== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-13967-by-stamrakar-on-??? +==13967== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-13967-by-stamrakar-on-??? +==13967== +==13967== TO CONTROL THIS PROCESS USING vgdb (which you probably +==13967== don't want to do, unless you know exactly what you're doing, +==13967== or are doing some strange experiment): +==13967== /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=13967 ...command... +==13967== +==13967== TO DEBUG THIS PROCESS USING GDB: start GDB like this +==13967== /path/to/gdb ./aesdsocket +==13967== and then give GDB the following command +==13967== target remote | /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=13967 +==13967== --pid is optional if only one valgrind process is running +==13967== +--13967-- REDIR: 0x4022e20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9ce2 (???) +--13967-- REDIR: 0x4022bf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c9cfc (???) +--13967-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_core-amd64-linux.so +--13967-- object doesn't have a symbol table +--13967-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so +--13967-- object doesn't have a symbol table +==13967== WARNING: new redirection conflicts with existing -- ignoring it +--13967-- old: 0x04022e20 (strlen ) R-> (0000.0) 0x580c9ce2 ??? +--13967-- new: 0x04022e20 (strlen ) R-> (2007.0) 0x0483f060 strlen +--13967-- REDIR: 0x401f600 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ffd0 (strcmp) +--13967-- REDIR: 0x4023380 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4843a20 (mempcpy) +--13967-- Reading syms from /usr/lib/x86_64-linux-gnu/librt-2.31.so +--13967-- Considering /usr/lib/debug/.build-id/fc/7c873442781f08af6bc88f1acac7ecccec7285.debug .. +--13967-- .. build-id is valid +--13967-- Reading syms from /usr/lib/x86_64-linux-gnu/libpthread-2.31.so +--13967-- Considering /usr/lib/debug/.build-id/9a/65bb469e45a1c6fbcffae5b82a2fd7a69eb479.debug .. +--13967-- .. build-id is valid +--13967-- Reading syms from /usr/lib/x86_64-linux-gnu/libc-2.31.so +--13967-- Considering /usr/lib/debug/.build-id/07/02430aef5fa3dda43986563e9ffcc47efbd75e.debug .. +--13967-- .. build-id is valid +--13967-- REDIR: 0x492a480 (libc.so.6:memmove) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x4929780 (libc.so.6:strncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x492a7b0 (libc.so.6:strcasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x49290a0 (libc.so.6:strcat) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x49297e0 (libc.so.6:rindex) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x492bc50 (libc.so.6:rawmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x4946ce0 (libc.so.6:wmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x4946820 (libc.so.6:wcscmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x492a5e0 (libc.so.6:mempcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x492a410 (libc.so.6:bcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x4929710 (libc.so.6:strncmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x4929150 (libc.so.6:strcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x492a540 (libc.so.6:memset) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x49467e0 (libc.so.6:wcschr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x4929670 (libc.so.6:strnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x4929230 (libc.so.6:strcspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x492a800 (libc.so.6:strncasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x49291d0 (libc.so.6:strcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x492a950 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x4947f50 (libc.so.6:wcsnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x4946860 (libc.so.6:wcscpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x4929820 (libc.so.6:strpbrk) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x4929100 (libc.so.6:index) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x4929630 (libc.so.6:strlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x4932bb0 (libc.so.6:memrchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x492a850 (libc.so.6:strcasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x492a3d0 (libc.so.6:memchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x4946930 (libc.so.6:wcslen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x4929ae0 (libc.so.6:strspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x492a750 (libc.so.6:stpncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x492a6f0 (libc.so.6:stpcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x492bc90 (libc.so.6:strchrnul) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x492a8a0 (libc.so.6:strncasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13967-- REDIR: 0x493b8c0 (libc.so.6:__strrchr_sse2) redirected to 0x483ea70 (__strrchr_sse2) +--13967-- REDIR: 0x49240e0 (libc.so.6:malloc) redirected to 0x483b780 (malloc) +--13967-- REDIR: 0x4925b10 (libc.so.6:calloc) redirected to 0x483dce0 (calloc) +--13967-- REDIR: 0x493b6b0 (libc.so.6:__strchrnul_sse2) redirected to 0x4843540 (strchrnul) +--13967-- REDIR: 0x493bbc0 (libc.so.6:__strlen_sse2) redirected to 0x483efa0 (__strlen_sse2) +--13967-- REDIR: 0x49246d0 (libc.so.6:free) redirected to 0x483c9d0 (free) +--13967-- REDIR: 0x4945ad0 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4840100 (memcpy@GLIBC_2.2.5) +--13967-- REDIR: 0x4929fa0 (libc.so.6:__GI_strstr) redirected to 0x4843ca0 (__strstr_sse2) +--13967-- REDIR: 0x4a17790 (libc.so.6:__memcmp_sse4_1) redirected to 0x4842150 (__memcmp_sse4_1) +--13967-- REDIR: 0x49343b0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x483fed0 (strcmp) +--13967-- REDIR: 0x4945f00 (libc.so.6:__memset_sse2_unaligned) redirected to 0x48428e0 (memset) +--13967-- REDIR: 0x4945ab0 (libc.so.6:__mempcpy_sse2_unaligned) redirected to 0x4843660 (mempcpy) +--13967-- REDIR: 0x4924e80 (libc.so.6:realloc) redirected to 0x483df30 (realloc) +--13967-- REDIR: 0x4935ec0 (libc.so.6:__memchr_sse2) redirected to 0x4840050 (memchr) +--13967-- REDIR: 0x493b480 (libc.so.6:__strchr_sse2) redirected to 0x483eb90 (__strchr_sse2) +==13967== Syscall param timer_create(evp.sigev_value) points to uninitialised byte(s) +==13967== at 0x48618E7: timer_create@@GLIBC_2.3.3 (timer_create.c:78) +==13967== by 0x10AC30: initTimer (aesdsocket.c:239) +==13967== by 0x10B7E8: main (aesdsocket.c:563) +==13967== Address 0x1ffefffc60 is on thread 1's stack +==13967== in frame #1, created by initTimer (aesdsocket.c:219) +==13967== Uninitialised value was created by a stack allocation +==13967== at 0x10AB4B: initTimer (aesdsocket.c:219) +==13967== +--13967-- REDIR: 0x4942140 (libc.so.6:__stpcpy_sse2_unaligned) redirected to 0x4842570 (__stpcpy_sse2_unaligned) +--13967-- REDIR: 0x4940b00 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x483f090 (strcpy) +==13967== Thread 2: +==13967== Conditional jump or move depends on uninitialised value(s) +==13967== at 0x483EFB8: __strlen_sse2 (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==13967== by 0x4902D14: __vfprintf_internal (vfprintf-internal.c:1688) +==13967== by 0x49A1FF2: __vsyslog_internal (syslog.c:233) +==13967== by 0x49A24A9: syslog (syslog.c:117) +==13967== by 0x10B343: threadfunc (aesdsocket.c:438) +==13967== by 0x486F608: start_thread (pthread_create.c:477) +==13967== by 0x49A9352: clone (clone.S:95) +==13967== Uninitialised value was created by a heap allocation +==13967== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==13967== by 0x10B211: threadfunc (aesdsocket.c:402) +==13967== by 0x486F608: start_thread (pthread_create.c:477) +==13967== by 0x49A9352: clone (clone.S:95) +==13967== +==13967== Syscall param read(buf) points to unaddressable byte(s) +==13967== at 0x487A3CC: __libc_read (read.c:26) +==13967== by 0x487A3CC: read (read.c:24) +==13967== by 0x10B426: threadfunc (aesdsocket.c:436) +==13967== by 0x486F608: start_thread (pthread_create.c:477) +==13967== by 0x49A9352: clone (clone.S:95) +==13967== Address 0x0 is not stack'd, malloc'd or (recently) free'd +==13967== +==13967== +==13967== HEAP SUMMARY: +==13967== in use at exit: 312 bytes in 2 blocks +==13967== total heap usage: 773 allocs, 771 frees, 2,109,404 bytes allocated +==13967== +==13967== Searching for pointers to 2 not-freed blocks +==13967== Checked 8,477,232 bytes +==13967== +==13967== Thread 1: +==13967== 40 bytes in 1 blocks are still reachable in loss record 1 of 2 +==13967== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==13967== by 0x10B89E: main (aesdsocket.c:586) +==13967== +==13967== 272 bytes in 1 blocks are possibly lost in loss record 2 of 2 +==13967== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==13967== by 0x40149DA: allocate_dtv (dl-tls.c:286) +==13967== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) +==13967== by 0x4870322: allocate_stack (allocatestack.c:622) +==13967== by 0x4870322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) +==13967== by 0x10B96F: main (aesdsocket.c:609) +==13967== +==13967== LEAK SUMMARY: +==13967== definitely lost: 0 bytes in 0 blocks +==13967== indirectly lost: 0 bytes in 0 blocks +==13967== possibly lost: 272 bytes in 1 blocks +==13967== still reachable: 40 bytes in 1 blocks +==13967== suppressed: 0 bytes in 0 blocks +==13967== +==13967== ERROR SUMMARY: 35 errors from 3 contexts (suppressed: 0 from 0) +==13967== +==13967== 1 errors in context 1 of 3: +==13967== Syscall param timer_create(evp.sigev_value) points to uninitialised byte(s) +==13967== at 0x48618E7: timer_create@@GLIBC_2.3.3 (timer_create.c:78) +==13967== by 0x10AC30: initTimer (aesdsocket.c:239) +==13967== by 0x10B7E8: main (aesdsocket.c:563) +==13967== Address 0x1ffefffc60 is on thread 1's stack +==13967== in frame #1, created by initTimer (aesdsocket.c:219) +==13967== Uninitialised value was created by a stack allocation +==13967== at 0x10AB4B: initTimer (aesdsocket.c:219) +==13967== +==13967== +==13967== 17 errors in context 2 of 3: +==13967== Thread 2: +==13967== Syscall param read(buf) points to unaddressable byte(s) +==13967== at 0x487A3CC: __libc_read (read.c:26) +==13967== by 0x487A3CC: read (read.c:24) +==13967== by 0x10B426: threadfunc (aesdsocket.c:436) +==13967== by 0x486F608: start_thread (pthread_create.c:477) +==13967== by 0x49A9352: clone (clone.S:95) +==13967== Address 0x0 is not stack'd, malloc'd or (recently) free'd +==13967== +==13967== +==13967== 17 errors in context 3 of 3: +==13967== Conditional jump or move depends on uninitialised value(s) +==13967== at 0x483EFB8: __strlen_sse2 (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==13967== by 0x4902D14: __vfprintf_internal (vfprintf-internal.c:1688) +==13967== by 0x49A1FF2: __vsyslog_internal (syslog.c:233) +==13967== by 0x49A24A9: syslog (syslog.c:117) +==13967== by 0x10B343: threadfunc (aesdsocket.c:438) +==13967== by 0x486F608: start_thread (pthread_create.c:477) +==13967== by 0x49A9352: clone (clone.S:95) +==13967== Uninitialised value was created by a heap allocation +==13967== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==13967== by 0x10B211: threadfunc (aesdsocket.c:402) +==13967== by 0x486F608: start_thread (pthread_create.c:477) +==13967== by 0x49A9352: clone (clone.S:95) +==13967== +==13967== ERROR SUMMARY: 35 errors from 3 contexts (suppressed: 0 from 0) From 769f3144559f6b24e9566f4df0978e8d73bae309 Mon Sep 17 00:00:00 2001 From: stamrakar Date: Mon, 14 Oct 2024 16:07:08 -0600 Subject: [PATCH 09/17] Timer not functional --- server/aesdsocket.c | 176 ++++++++--------- server/aesdsocketdata | 17 -- server/valgrind-out.txt | 419 +++++++++++++++++++--------------------- 3 files changed, 293 insertions(+), 319 deletions(-) delete mode 100644 server/aesdsocketdata diff --git a/server/aesdsocket.c b/server/aesdsocket.c index e321fdc..1f414f0 100644 --- a/server/aesdsocket.c +++ b/server/aesdsocket.c @@ -92,8 +92,9 @@ static void closeAll(int exit_flag); static void initTimer(void); static void init_sigHandler(void); static void signal_handler(int signal_number); -static void timer_handler(int signal_number); +//static void timer_handler(void); void *threadfunc(void *arg); +void *threadtimerfunc(void *arg); static void signal_handler (int signal_number) { @@ -104,48 +105,6 @@ static void signal_handler (int signal_number) } } -static void timer_handler(int signal_number) -{ - int rc; - ssize_t nr; - ssize_t strf_ret; - time_t now; - struct tm *ttime; - char curr_tstamp[50]; - time(&now); - ttime = localtime(&now); - - - strf_ret = strftime(curr_tstamp, sizeof(curr_tstamp), "timestamp:%Y %b %d %H:%M:%S\n", ttime); - - if (!strf_ret) - { - syslog(LOG_ERR, "strftime error, receiving 0 bytes"); - } - - rc = pthread_mutex_lock(&writeSocket); - if (rc != 0) - { - syslog(LOG_ERR, "pthread_mutex_lock failed, error was %d", rc); - perror("pthread mutex_lock failed"); - } - - nr = write(recvfile_fd, curr_tstamp, strf_ret); - - rc = pthread_mutex_unlock(&writeSocket); - if (rc != 0) - { - syslog(LOG_ERR, "pthread_mutex_unlock failed, error was %d", rc); - perror("pthread mutex_unlock failed"); - } - - if(nr != strf_ret) - { - syslog(LOG_DEBUG, "Inconsistent bytes written"); - } - -} - static void init_sigHandler(void) { struct sigaction sig1; @@ -217,44 +176,25 @@ static int create_daemon() static void initTimer(void) { - struct sigaction sigt; - struct sigevent sev; - struct itimerspec mytime; - - memset(&sigt, 0, sizeof(struct sigaction)); - sigt.sa_handler = timer_handler; - if( sigaction(SIGALRM, &sigt, NULL) != 0) - { - syslog(LOG_ERR, "Error %d (%s) registering for SIGALRM", errno, strerror(errno)); - perror("sigalrm: fail"); - closeAll(EXIT_FAILURE); - } - - sev.sigev_notify = SIGEV_SIGNAL; - //sev.sigev_notify_function = &timer_handler; - sev.sigev_signo = SIGALRM; - if (timer_create(CLOCK_MONOTONIC, &sev, &timerid) == -1) + pthread_t timertid; + my_threads *timer_thread = (my_threads *)malloc(sizeof(my_threads)); + if (timer_thread == NULL) { - perror("initTimer: timer_create"); - syslog(LOG_ERR, "Error creating timer: %s", strerror(errno)); - return; + syslog(LOG_ERR, "server: timer thread allocation"); + perror("server: timer thread allocation"); + //should I be exiting everything here or just keep trying } - - mytime.it_value.tv_sec = TSTAMP_INTERVAL; - mytime.it_value.tv_nsec = 0; - mytime.it_interval.tv_sec = TSTAMP_INTERVAL; - mytime.it_interval.tv_nsec = 0; - - - - if(timer_settime(timerid, 0, &mytime, NULL) == -1) + else { - perror("initTimer: timer_settime"); - syslog(LOG_ERR, "Timer couldn't be started: %s", strerror(errno)); + int timer_rc; + if((timer_rc = pthread_create(&timertid, NULL, threadtimerfunc, (void*) &(timer_thread->thread_info))) != 0) + { + syslog(LOG_ERR, "Failed to pthread_create() timer_thread, error was %d", timer_rc); + perror("Failed to pthread_create() timer_thread"); + free(timer_thread); + } } - - - + syslog(LOG_DEBUG, "Timer thread created successfully"); return; } @@ -265,10 +205,10 @@ void closeAll(int exit_flag) if(sockfd != -1) close(sockfd); if(new_fd != -1) close(new_fd); if(recvfile_fd != -1) close(recvfile_fd); - // if(remove(recvfile) != 0) - // { - // syslog(LOG_ERR, "File removal not successful"); - // } + if(remove(recvfile) != 0) + { + syslog(LOG_ERR, "File removal not successful"); + } timer_delete(timerid); pthread_mutex_destroy(&writeSocket); @@ -278,6 +218,67 @@ void closeAll(int exit_flag) } +void *threadtimerfunc(void *args) +{ + time_t now; + struct tm *tm; + char timestamp[100]; + struct timespec ts; + ts.tv_sec = 10; + ts.tv_nsec = 0; + time_t start, end; + start = time(NULL); + int rc; + + while(!sig) + { + + syslog(LOG_DEBUG, "Starting sleep at %ld", start); + + clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL); + + end = time(NULL); + syslog(LOG_DEBUG, "Ending sleep at %ld, slept for %ld seconds", end, end-start); + + + now = time(NULL); + + tm = localtime(&now); + + + if(strftime(timestamp, sizeof(timestamp), "timestamp:%Y-%m-%d %H:%M:%S\n", tm)==0) + { + syslog(LOG_ERR,"strftime failed"); + continue; + } + + rc = pthread_mutex_lock(&writeSocket); + if (rc != 0) + { + syslog(LOG_ERR, "pthread_mutex_lock failed, error was %d", rc); + perror("pthread mutex_lock failed"); + } + if(write(recvfile_fd, timestamp, strlen(timestamp))==-1) + { + syslog(LOG_ERR, "write failed to timestamp"); + rc = pthread_mutex_unlock(&writeSocket); + if (rc != 0) + { + syslog(LOG_ERR, "pthread_mutex_unlock failed, error was %d", rc); + perror("pthread mutex_unlock failed"); + } + continue; + } + + rc = pthread_mutex_unlock(&writeSocket); + if (rc != 0) + { + syslog(LOG_ERR, "pthread_mutex_unlock failed, error was %d", rc); + perror("pthread mutex_unlock failed"); + } + } + return NULL; +} void *threadfunc(void *args) { my_threads *thread_func_args = (my_threads *) args; @@ -303,7 +304,7 @@ void *threadfunc(void *args) int errnum; do{ bytes_rx = recv(thread_func_args->thread_info.afd, my_buffer+supplementBuf, BUF_SIZE-1, 0); - syslog(LOG_DEBUG, "Receiving: %s", my_buffer); + //syslog(LOG_DEBUG, "Receiving: %s", my_buffer); // syslog(LOG_DEBUG, "new_fd is %d", thread_func_args->thread_info.afd); syslog(LOG_DEBUG, "I have received %ld bytes", bytes_rx); if (bytes_rx < 0) @@ -432,7 +433,7 @@ void *threadfunc(void *args) while ((bytes_read = read(recvfile_fd, send_my_buffer, total_size)) > 0) { syslog(LOG_DEBUG, "bytes_read is %ld", bytes_read); - syslog(LOG_DEBUG, "Sending: %s",send_my_buffer); + //syslog(LOG_DEBUG, "Sending: %s",send_my_buffer); if (send(thread_func_args->thread_info.afd, send_my_buffer, bytes_read, 0) != bytes_read) { errnum9 = errno; @@ -557,13 +558,14 @@ int main(int argc, char *argv[]) syslog(LOG_DEBUG, "listen pass"); - initTimer(); - syslog(LOG_DEBUG, "Timer has been set"); - syslog(LOG_DEBUG, "server: waiting for connections.........\n"); + //syslog(LOG_DEBUG, "Timer has been set"); - + //syslog(LOG_DEBUG, "server: waiting for connections.........\n"); + + + initTimer(); while(!sig){ diff --git a/server/aesdsocketdata b/server/aesdsocketdata deleted file mode 100644 index d2c26f9..0000000 --- a/server/aesdsocketdata +++ /dev/null @@ -1,17 +0,0 @@ -timestamp:wait-for-startup -abcdefg -hijklmnop -1234567890 -9876543210 -One best book is equal to a hundred good friends, but one good friend is equal to a library -If you want to shine like a sun, first burn like a sun -Never stop fighting until you arrive at your destined place - that is, the unique you -Never stop fighting until you arrive at your destined place - that is, the unique you -One best book is equal to a hundred good friends, but one good friend is equal to a library -If you want to shine like a sun, first burn like a sun -Never stop fighting until you arrive at your destined place - that is, the unique you -One best book is equal to a hundred good friends, but one good friend is equal to a library -If you want to shine like a sun, first burn like a sun -validate_multithreaded -test_socket_timer -test_socket_timer diff --git a/server/valgrind-out.txt b/server/valgrind-out.txt index 144ffaf..8517f86 100644 --- a/server/valgrind-out.txt +++ b/server/valgrind-out.txt @@ -1,215 +1,204 @@ -==13967== Memcheck, a memory error detector -==13967== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. -==13967== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info -==13967== Command: ./aesdsocket -==13967== Parent PID: 13965 -==13967== ---13967-- ---13967-- Valgrind options: ---13967-- --error-exitcode=1 ---13967-- --leak-check=full ---13967-- --show-leak-kinds=all ---13967-- --track-origins=yes ---13967-- --errors-for-leak-kinds=definite ---13967-- --verbose ---13967-- --log-file=valgrind-out.txt ---13967-- Contents of /proc/version: ---13967-- Linux version 5.15.0-122-generic (buildd@lcy02-amd64-106) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #132~20.04.1-Ubuntu SMP Fri Aug 30 15:50:07 UTC 2024 ---13967-- ---13967-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3 ---13967-- Page sizes: currently 4096, max supported 4096 ---13967-- Valgrind library directory: /usr/lib/x86_64-linux-gnu/valgrind ---13967-- Reading syms from /home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocket ---13967-- Reading syms from /usr/lib/x86_64-linux-gnu/ld-2.31.so ---13967-- Considering /usr/lib/debug/.build-id/db/0420f708b806cf03260aadb916c330049580b7.debug .. ---13967-- .. build-id is valid ---13967-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-linux ---13967-- object doesn't have a symbol table ---13967-- object doesn't have a dynamic symbol table ---13967-- Scheduler: using generic scheduler lock implementation. ---13967-- Reading suppressions file: /usr/lib/x86_64-linux-gnu/valgrind/default.supp -==13967== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-13967-by-stamrakar-on-??? -==13967== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-13967-by-stamrakar-on-??? -==13967== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-13967-by-stamrakar-on-??? -==13967== -==13967== TO CONTROL THIS PROCESS USING vgdb (which you probably -==13967== don't want to do, unless you know exactly what you're doing, -==13967== or are doing some strange experiment): -==13967== /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=13967 ...command... -==13967== -==13967== TO DEBUG THIS PROCESS USING GDB: start GDB like this -==13967== /path/to/gdb ./aesdsocket -==13967== and then give GDB the following command -==13967== target remote | /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=13967 -==13967== --pid is optional if only one valgrind process is running -==13967== ---13967-- REDIR: 0x4022e20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9ce2 (???) ---13967-- REDIR: 0x4022bf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c9cfc (???) ---13967-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_core-amd64-linux.so ---13967-- object doesn't have a symbol table ---13967-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so ---13967-- object doesn't have a symbol table -==13967== WARNING: new redirection conflicts with existing -- ignoring it ---13967-- old: 0x04022e20 (strlen ) R-> (0000.0) 0x580c9ce2 ??? ---13967-- new: 0x04022e20 (strlen ) R-> (2007.0) 0x0483f060 strlen ---13967-- REDIR: 0x401f600 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ffd0 (strcmp) ---13967-- REDIR: 0x4023380 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4843a20 (mempcpy) ---13967-- Reading syms from /usr/lib/x86_64-linux-gnu/librt-2.31.so ---13967-- Considering /usr/lib/debug/.build-id/fc/7c873442781f08af6bc88f1acac7ecccec7285.debug .. ---13967-- .. build-id is valid ---13967-- Reading syms from /usr/lib/x86_64-linux-gnu/libpthread-2.31.so ---13967-- Considering /usr/lib/debug/.build-id/9a/65bb469e45a1c6fbcffae5b82a2fd7a69eb479.debug .. ---13967-- .. build-id is valid ---13967-- Reading syms from /usr/lib/x86_64-linux-gnu/libc-2.31.so ---13967-- Considering /usr/lib/debug/.build-id/07/02430aef5fa3dda43986563e9ffcc47efbd75e.debug .. ---13967-- .. build-id is valid ---13967-- REDIR: 0x492a480 (libc.so.6:memmove) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x4929780 (libc.so.6:strncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x492a7b0 (libc.so.6:strcasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x49290a0 (libc.so.6:strcat) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x49297e0 (libc.so.6:rindex) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x492bc50 (libc.so.6:rawmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x4946ce0 (libc.so.6:wmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x4946820 (libc.so.6:wcscmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x492a5e0 (libc.so.6:mempcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x492a410 (libc.so.6:bcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x4929710 (libc.so.6:strncmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x4929150 (libc.so.6:strcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x492a540 (libc.so.6:memset) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x49467e0 (libc.so.6:wcschr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x4929670 (libc.so.6:strnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x4929230 (libc.so.6:strcspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x492a800 (libc.so.6:strncasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x49291d0 (libc.so.6:strcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x492a950 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x4947f50 (libc.so.6:wcsnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x4946860 (libc.so.6:wcscpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x4929820 (libc.so.6:strpbrk) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x4929100 (libc.so.6:index) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x4929630 (libc.so.6:strlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x4932bb0 (libc.so.6:memrchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x492a850 (libc.so.6:strcasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x492a3d0 (libc.so.6:memchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x4946930 (libc.so.6:wcslen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x4929ae0 (libc.so.6:strspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x492a750 (libc.so.6:stpncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x492a6f0 (libc.so.6:stpcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x492bc90 (libc.so.6:strchrnul) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x492a8a0 (libc.so.6:strncasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13967-- REDIR: 0x493b8c0 (libc.so.6:__strrchr_sse2) redirected to 0x483ea70 (__strrchr_sse2) ---13967-- REDIR: 0x49240e0 (libc.so.6:malloc) redirected to 0x483b780 (malloc) ---13967-- REDIR: 0x4925b10 (libc.so.6:calloc) redirected to 0x483dce0 (calloc) ---13967-- REDIR: 0x493b6b0 (libc.so.6:__strchrnul_sse2) redirected to 0x4843540 (strchrnul) ---13967-- REDIR: 0x493bbc0 (libc.so.6:__strlen_sse2) redirected to 0x483efa0 (__strlen_sse2) ---13967-- REDIR: 0x49246d0 (libc.so.6:free) redirected to 0x483c9d0 (free) ---13967-- REDIR: 0x4945ad0 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4840100 (memcpy@GLIBC_2.2.5) ---13967-- REDIR: 0x4929fa0 (libc.so.6:__GI_strstr) redirected to 0x4843ca0 (__strstr_sse2) ---13967-- REDIR: 0x4a17790 (libc.so.6:__memcmp_sse4_1) redirected to 0x4842150 (__memcmp_sse4_1) ---13967-- REDIR: 0x49343b0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x483fed0 (strcmp) ---13967-- REDIR: 0x4945f00 (libc.so.6:__memset_sse2_unaligned) redirected to 0x48428e0 (memset) ---13967-- REDIR: 0x4945ab0 (libc.so.6:__mempcpy_sse2_unaligned) redirected to 0x4843660 (mempcpy) ---13967-- REDIR: 0x4924e80 (libc.so.6:realloc) redirected to 0x483df30 (realloc) ---13967-- REDIR: 0x4935ec0 (libc.so.6:__memchr_sse2) redirected to 0x4840050 (memchr) ---13967-- REDIR: 0x493b480 (libc.so.6:__strchr_sse2) redirected to 0x483eb90 (__strchr_sse2) -==13967== Syscall param timer_create(evp.sigev_value) points to uninitialised byte(s) -==13967== at 0x48618E7: timer_create@@GLIBC_2.3.3 (timer_create.c:78) -==13967== by 0x10AC30: initTimer (aesdsocket.c:239) -==13967== by 0x10B7E8: main (aesdsocket.c:563) -==13967== Address 0x1ffefffc60 is on thread 1's stack -==13967== in frame #1, created by initTimer (aesdsocket.c:219) -==13967== Uninitialised value was created by a stack allocation -==13967== at 0x10AB4B: initTimer (aesdsocket.c:219) -==13967== ---13967-- REDIR: 0x4942140 (libc.so.6:__stpcpy_sse2_unaligned) redirected to 0x4842570 (__stpcpy_sse2_unaligned) ---13967-- REDIR: 0x4940b00 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x483f090 (strcpy) -==13967== Thread 2: -==13967== Conditional jump or move depends on uninitialised value(s) -==13967== at 0x483EFB8: __strlen_sse2 (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==13967== by 0x4902D14: __vfprintf_internal (vfprintf-internal.c:1688) -==13967== by 0x49A1FF2: __vsyslog_internal (syslog.c:233) -==13967== by 0x49A24A9: syslog (syslog.c:117) -==13967== by 0x10B343: threadfunc (aesdsocket.c:438) -==13967== by 0x486F608: start_thread (pthread_create.c:477) -==13967== by 0x49A9352: clone (clone.S:95) -==13967== Uninitialised value was created by a heap allocation -==13967== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==13967== by 0x10B211: threadfunc (aesdsocket.c:402) -==13967== by 0x486F608: start_thread (pthread_create.c:477) -==13967== by 0x49A9352: clone (clone.S:95) -==13967== -==13967== Syscall param read(buf) points to unaddressable byte(s) -==13967== at 0x487A3CC: __libc_read (read.c:26) -==13967== by 0x487A3CC: read (read.c:24) -==13967== by 0x10B426: threadfunc (aesdsocket.c:436) -==13967== by 0x486F608: start_thread (pthread_create.c:477) -==13967== by 0x49A9352: clone (clone.S:95) -==13967== Address 0x0 is not stack'd, malloc'd or (recently) free'd -==13967== -==13967== -==13967== HEAP SUMMARY: -==13967== in use at exit: 312 bytes in 2 blocks -==13967== total heap usage: 773 allocs, 771 frees, 2,109,404 bytes allocated -==13967== -==13967== Searching for pointers to 2 not-freed blocks -==13967== Checked 8,477,232 bytes -==13967== -==13967== Thread 1: -==13967== 40 bytes in 1 blocks are still reachable in loss record 1 of 2 -==13967== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==13967== by 0x10B89E: main (aesdsocket.c:586) -==13967== -==13967== 272 bytes in 1 blocks are possibly lost in loss record 2 of 2 -==13967== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==13967== by 0x40149DA: allocate_dtv (dl-tls.c:286) -==13967== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) -==13967== by 0x4870322: allocate_stack (allocatestack.c:622) -==13967== by 0x4870322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) -==13967== by 0x10B96F: main (aesdsocket.c:609) -==13967== -==13967== LEAK SUMMARY: -==13967== definitely lost: 0 bytes in 0 blocks -==13967== indirectly lost: 0 bytes in 0 blocks -==13967== possibly lost: 272 bytes in 1 blocks -==13967== still reachable: 40 bytes in 1 blocks -==13967== suppressed: 0 bytes in 0 blocks -==13967== -==13967== ERROR SUMMARY: 35 errors from 3 contexts (suppressed: 0 from 0) -==13967== -==13967== 1 errors in context 1 of 3: -==13967== Syscall param timer_create(evp.sigev_value) points to uninitialised byte(s) -==13967== at 0x48618E7: timer_create@@GLIBC_2.3.3 (timer_create.c:78) -==13967== by 0x10AC30: initTimer (aesdsocket.c:239) -==13967== by 0x10B7E8: main (aesdsocket.c:563) -==13967== Address 0x1ffefffc60 is on thread 1's stack -==13967== in frame #1, created by initTimer (aesdsocket.c:219) -==13967== Uninitialised value was created by a stack allocation -==13967== at 0x10AB4B: initTimer (aesdsocket.c:219) -==13967== -==13967== -==13967== 17 errors in context 2 of 3: -==13967== Thread 2: -==13967== Syscall param read(buf) points to unaddressable byte(s) -==13967== at 0x487A3CC: __libc_read (read.c:26) -==13967== by 0x487A3CC: read (read.c:24) -==13967== by 0x10B426: threadfunc (aesdsocket.c:436) -==13967== by 0x486F608: start_thread (pthread_create.c:477) -==13967== by 0x49A9352: clone (clone.S:95) -==13967== Address 0x0 is not stack'd, malloc'd or (recently) free'd -==13967== -==13967== -==13967== 17 errors in context 3 of 3: -==13967== Conditional jump or move depends on uninitialised value(s) -==13967== at 0x483EFB8: __strlen_sse2 (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==13967== by 0x4902D14: __vfprintf_internal (vfprintf-internal.c:1688) -==13967== by 0x49A1FF2: __vsyslog_internal (syslog.c:233) -==13967== by 0x49A24A9: syslog (syslog.c:117) -==13967== by 0x10B343: threadfunc (aesdsocket.c:438) -==13967== by 0x486F608: start_thread (pthread_create.c:477) -==13967== by 0x49A9352: clone (clone.S:95) -==13967== Uninitialised value was created by a heap allocation -==13967== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==13967== by 0x10B211: threadfunc (aesdsocket.c:402) -==13967== by 0x486F608: start_thread (pthread_create.c:477) -==13967== by 0x49A9352: clone (clone.S:95) -==13967== -==13967== ERROR SUMMARY: 35 errors from 3 contexts (suppressed: 0 from 0) +==13982== Memcheck, a memory error detector +==13982== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. +==13982== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info +==13982== Command: ./aesdsocket +==13982== Parent PID: 13978 +==13982== +--13982-- +--13982-- Valgrind options: +--13982-- --error-exitcode=1 +--13982-- --leak-check=full +--13982-- --show-leak-kinds=all +--13982-- --track-origins=yes +--13982-- --errors-for-leak-kinds=definite +--13982-- --verbose +--13982-- --log-file=valgrind-out.txt +--13982-- Contents of /proc/version: +--13982-- Linux version 5.15.0-122-generic (buildd@lcy02-amd64-106) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #132~20.04.1-Ubuntu SMP Fri Aug 30 15:50:07 UTC 2024 +--13982-- +--13982-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3 +--13982-- Page sizes: currently 4096, max supported 4096 +--13982-- Valgrind library directory: /usr/lib/x86_64-linux-gnu/valgrind +--13982-- Reading syms from /home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocket +--13982-- Reading syms from /usr/lib/x86_64-linux-gnu/ld-2.31.so +--13982-- Considering /usr/lib/debug/.build-id/db/0420f708b806cf03260aadb916c330049580b7.debug .. +--13982-- .. build-id is valid +--13982-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-linux +--13982-- object doesn't have a symbol table +--13982-- object doesn't have a dynamic symbol table +--13982-- Scheduler: using generic scheduler lock implementation. +--13982-- Reading suppressions file: /usr/lib/x86_64-linux-gnu/valgrind/default.supp +==13982== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-13982-by-stamrakar-on-??? +==13982== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-13982-by-stamrakar-on-??? +==13982== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-13982-by-stamrakar-on-??? +==13982== +==13982== TO CONTROL THIS PROCESS USING vgdb (which you probably +==13982== don't want to do, unless you know exactly what you're doing, +==13982== or are doing some strange experiment): +==13982== /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=13982 ...command... +==13982== +==13982== TO DEBUG THIS PROCESS USING GDB: start GDB like this +==13982== /path/to/gdb ./aesdsocket +==13982== and then give GDB the following command +==13982== target remote | /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=13982 +==13982== --pid is optional if only one valgrind process is running +==13982== +--13982-- REDIR: 0x4022e20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9ce2 (???) +--13982-- REDIR: 0x4022bf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c9cfc (???) +--13982-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_core-amd64-linux.so +--13982-- object doesn't have a symbol table +--13982-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so +--13982-- object doesn't have a symbol table +==13982== WARNING: new redirection conflicts with existing -- ignoring it +--13982-- old: 0x04022e20 (strlen ) R-> (0000.0) 0x580c9ce2 ??? +--13982-- new: 0x04022e20 (strlen ) R-> (2007.0) 0x0483f060 strlen +--13982-- REDIR: 0x401f600 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ffd0 (strcmp) +--13982-- REDIR: 0x4023380 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4843a20 (mempcpy) +--13982-- Reading syms from /usr/lib/x86_64-linux-gnu/librt-2.31.so +--13982-- Considering /usr/lib/debug/.build-id/fc/7c873442781f08af6bc88f1acac7ecccec7285.debug .. +--13982-- .. build-id is valid +--13982-- Reading syms from /usr/lib/x86_64-linux-gnu/libpthread-2.31.so +--13982-- Considering /usr/lib/debug/.build-id/9a/65bb469e45a1c6fbcffae5b82a2fd7a69eb479.debug .. +--13982-- .. build-id is valid +--13982-- Reading syms from /usr/lib/x86_64-linux-gnu/libc-2.31.so +--13982-- Considering /usr/lib/debug/.build-id/07/02430aef5fa3dda43986563e9ffcc47efbd75e.debug .. +--13982-- .. build-id is valid +--13982-- REDIR: 0x492a480 (libc.so.6:memmove) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x4929780 (libc.so.6:strncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x492a7b0 (libc.so.6:strcasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x49290a0 (libc.so.6:strcat) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x49297e0 (libc.so.6:rindex) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x492bc50 (libc.so.6:rawmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x4946ce0 (libc.so.6:wmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x4946820 (libc.so.6:wcscmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x492a5e0 (libc.so.6:mempcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x492a410 (libc.so.6:bcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x4929710 (libc.so.6:strncmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x4929150 (libc.so.6:strcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x492a540 (libc.so.6:memset) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x49467e0 (libc.so.6:wcschr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x4929670 (libc.so.6:strnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x4929230 (libc.so.6:strcspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x492a800 (libc.so.6:strncasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x49291d0 (libc.so.6:strcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x492a950 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x4947f50 (libc.so.6:wcsnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x4946860 (libc.so.6:wcscpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x4929820 (libc.so.6:strpbrk) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x4929100 (libc.so.6:index) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x4929630 (libc.so.6:strlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x4932bb0 (libc.so.6:memrchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x492a850 (libc.so.6:strcasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x492a3d0 (libc.so.6:memchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x4946930 (libc.so.6:wcslen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x4929ae0 (libc.so.6:strspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x492a750 (libc.so.6:stpncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x492a6f0 (libc.so.6:stpcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x492bc90 (libc.so.6:strchrnul) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x492a8a0 (libc.so.6:strncasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--13982-- REDIR: 0x493b8c0 (libc.so.6:__strrchr_sse2) redirected to 0x483ea70 (__strrchr_sse2) +--13982-- REDIR: 0x49240e0 (libc.so.6:malloc) redirected to 0x483b780 (malloc) +--13982-- REDIR: 0x4925b10 (libc.so.6:calloc) redirected to 0x483dce0 (calloc) +--13982-- REDIR: 0x493b6b0 (libc.so.6:__strchrnul_sse2) redirected to 0x4843540 (strchrnul) +--13982-- REDIR: 0x493bbc0 (libc.so.6:__strlen_sse2) redirected to 0x483efa0 (__strlen_sse2) +--13982-- REDIR: 0x49246d0 (libc.so.6:free) redirected to 0x483c9d0 (free) +--13982-- REDIR: 0x4945ad0 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4840100 (memcpy@GLIBC_2.2.5) +--13982-- REDIR: 0x4929fa0 (libc.so.6:__GI_strstr) redirected to 0x4843ca0 (__strstr_sse2) +--13982-- REDIR: 0x4a17790 (libc.so.6:__memcmp_sse4_1) redirected to 0x4842150 (__memcmp_sse4_1) +--13982-- REDIR: 0x49343b0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x483fed0 (strcmp) +--13982-- REDIR: 0x4945f00 (libc.so.6:__memset_sse2_unaligned) redirected to 0x48428e0 (memset) +--13982-- REDIR: 0x4945ab0 (libc.so.6:__mempcpy_sse2_unaligned) redirected to 0x4843660 (mempcpy) +--13982-- REDIR: 0x4924e80 (libc.so.6:realloc) redirected to 0x483df30 (realloc) +--13982-- REDIR: 0x4935ec0 (libc.so.6:__memchr_sse2) redirected to 0x4840050 (memchr) +--13982-- REDIR: 0x493b480 (libc.so.6:__strchr_sse2) redirected to 0x483eb90 (__strchr_sse2) +--13982-- REDIR: 0x4940b00 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x483f090 (strcpy) +==13982== Thread 3: +==13982== Syscall param read(buf) points to unaddressable byte(s) +==13982== at 0x487A3CC: __libc_read (read.c:26) +==13982== by 0x487A3CC: read (read.c:24) +==13982== by 0x10B440: threadfunc (aesdsocket.c:434) +==13982== by 0x486F608: start_thread (pthread_create.c:477) +==13982== by 0x49A9352: clone (clone.S:95) +==13982== Address 0x0 is not stack'd, malloc'd or (recently) free'd +==13982== +--13982-- REDIR: 0x4942140 (libc.so.6:__stpcpy_sse2_unaligned) redirected to 0x4842570 (__stpcpy_sse2_unaligned) +==13982== Thread 1: +==13982== Invalid read of size 4 +==13982== at 0x4861BC3: timer_delete@@GLIBC_2.3.3 (timer_delete.c:38) +==13982== by 0x10AB7D: closeAll (aesdsocket.c:213) +==13982== by 0x10BC67: main (aesdsocket.c:680) +==13982== Address 0x4 is not stack'd, malloc'd or (recently) free'd +==13982== +==13982== +==13982== Process terminating with default action of signal 11 (SIGSEGV) +==13982== Access not within mapped region at address 0x4 +==13982== at 0x4861BC3: timer_delete@@GLIBC_2.3.3 (timer_delete.c:38) +==13982== by 0x10AB7D: closeAll (aesdsocket.c:213) +==13982== by 0x10BC67: main (aesdsocket.c:680) +==13982== If you believe this happened as a result of a stack +==13982== overflow in your program's main thread (unlikely but +==13982== possible), you can try to increase the size of the +==13982== main thread stack using the --main-stacksize= flag. +==13982== The main thread stack size used in this run was 8388608. +==13982== +==13982== HEAP SUMMARY: +==13982== in use at exit: 624 bytes in 4 blocks +==13982== total heap usage: 687 allocs, 683 frees, 1,839,662 bytes allocated +==13982== +==13982== Searching for pointers to 4 not-freed blocks +==13982== Checked 16,863,600 bytes +==13982== +==13982== 40 bytes in 1 blocks are still reachable in loss record 1 of 4 +==13982== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==13982== by 0x10AA21: initTimer (aesdsocket.c:180) +==13982== by 0x10B802: main (aesdsocket.c:568) +==13982== +==13982== 40 bytes in 1 blocks are still reachable in loss record 2 of 4 +==13982== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==13982== by 0x10B88C: main (aesdsocket.c:585) +==13982== +==13982== 272 bytes in 1 blocks are possibly lost in loss record 3 of 4 +==13982== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==13982== by 0x40149DA: allocate_dtv (dl-tls.c:286) +==13982== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) +==13982== by 0x4870322: allocate_stack (allocatestack.c:622) +==13982== by 0x4870322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) +==13982== by 0x10AA6F: initTimer (aesdsocket.c:190) +==13982== by 0x10B802: main (aesdsocket.c:568) +==13982== +==13982== 272 bytes in 1 blocks are possibly lost in loss record 4 of 4 +==13982== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==13982== by 0x40149DA: allocate_dtv (dl-tls.c:286) +==13982== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) +==13982== by 0x4870322: allocate_stack (allocatestack.c:622) +==13982== by 0x4870322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) +==13982== by 0x10B95D: main (aesdsocket.c:608) +==13982== +==13982== LEAK SUMMARY: +==13982== definitely lost: 0 bytes in 0 blocks +==13982== indirectly lost: 0 bytes in 0 blocks +==13982== possibly lost: 544 bytes in 2 blocks +==13982== still reachable: 80 bytes in 2 blocks +==13982== suppressed: 0 bytes in 0 blocks +==13982== +==13982== ERROR SUMMARY: 18 errors from 2 contexts (suppressed: 0 from 0) +==13982== +==13982== 1 errors in context 1 of 2: +==13982== Invalid read of size 4 +==13982== at 0x4861BC3: timer_delete@@GLIBC_2.3.3 (timer_delete.c:38) +==13982== by 0x10AB7D: closeAll (aesdsocket.c:213) +==13982== by 0x10BC67: main (aesdsocket.c:680) +==13982== Address 0x4 is not stack'd, malloc'd or (recently) free'd +==13982== +==13982== +==13982== 17 errors in context 2 of 2: +==13982== Thread 3: +==13982== Syscall param read(buf) points to unaddressable byte(s) +==13982== at 0x487A3CC: __libc_read (read.c:26) +==13982== by 0x487A3CC: read (read.c:24) +==13982== by 0x10B440: threadfunc (aesdsocket.c:434) +==13982== by 0x486F608: start_thread (pthread_create.c:477) +==13982== by 0x49A9352: clone (clone.S:95) +==13982== Address 0x0 is not stack'd, malloc'd or (recently) free'd +==13982== +==13982== ERROR SUMMARY: 18 errors from 2 contexts (suppressed: 0 from 0) From 82e5143bc65b7ee93f1a4f4d9b4a3f05512b273c Mon Sep 17 00:00:00 2001 From: stamrakar Date: Mon, 14 Oct 2024 16:40:53 -0600 Subject: [PATCH 10/17] OH debugggin --- server/aesdsocket.c | 26 ++- server/valgrind-out.txt | 408 ++++++++++++++++++++-------------------- 2 files changed, 229 insertions(+), 205 deletions(-) diff --git a/server/aesdsocket.c b/server/aesdsocket.c index 1f414f0..c6d7b9d 100644 --- a/server/aesdsocket.c +++ b/server/aesdsocket.c @@ -50,6 +50,7 @@ #define BACKLOG (10) // pending connections #define BUF_SIZE 1024 #define TSTAMP_INTERVAL (10) +#define TIMESTAMP_INTERVAL (10) typedef struct thread_info_s thread_info_t; typedef struct slist_data_s my_threads; @@ -57,10 +58,12 @@ static timer_t timerid; pthread_mutex_t writeSocket = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t size_val = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t ll_lock = PTHREAD_MUTEX_INITIALIZER; +//pthread_mutex_t timer_mutex; struct thread_info_s{ pthread_t threadid; + //int write_file_fd; int afd; //accepted fd psot accept() connection. bool thread_complete_success; char ip4[INET_ADDRSTRLEN]; //space to hold the IPv4 string @@ -92,9 +95,9 @@ static void closeAll(int exit_flag); static void initTimer(void); static void init_sigHandler(void); static void signal_handler(int signal_number); -//static void timer_handler(void); void *threadfunc(void *arg); void *threadtimerfunc(void *arg); +void timer_handler(int signo); static void signal_handler (int signal_number) { @@ -198,6 +201,8 @@ static void initTimer(void) return; } + + void closeAll(int exit_flag) { //int rc; @@ -212,6 +217,8 @@ void closeAll(int exit_flag) timer_delete(timerid); pthread_mutex_destroy(&writeSocket); + pthread_mutex_destroy(&ll_lock); + pthread_mutex_destroy(&size_val); syslog(LOG_DEBUG, "CLEANUP COMPLETED."); closelog(); exit(exit_flag); @@ -270,6 +277,22 @@ void *threadtimerfunc(void *args) continue; } + rc = pthread_mutex_lock(&size_val); + if (rc != 0) + { + syslog(LOG_ERR, "pthread_mutex_lock failed on total size, error was %d", rc); + perror("pthread mutex_lock failed"); + } + + total_size += strlen(timestamp); + + rc = pthread_mutex_unlock(&size_val); + if (rc != 0) + { + syslog(LOG_ERR, "pthread_mutex_unlock failed on total size, error was %d", rc); + perror("pthread mutex_lock failed"); + } + rc = pthread_mutex_unlock(&writeSocket); if (rc != 0) { @@ -566,6 +589,7 @@ int main(int argc, char *argv[]) initTimer(); + //initTimer2(); while(!sig){ diff --git a/server/valgrind-out.txt b/server/valgrind-out.txt index 8517f86..49cabc1 100644 --- a/server/valgrind-out.txt +++ b/server/valgrind-out.txt @@ -1,204 +1,204 @@ -==13982== Memcheck, a memory error detector -==13982== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. -==13982== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info -==13982== Command: ./aesdsocket -==13982== Parent PID: 13978 -==13982== ---13982-- ---13982-- Valgrind options: ---13982-- --error-exitcode=1 ---13982-- --leak-check=full ---13982-- --show-leak-kinds=all ---13982-- --track-origins=yes ---13982-- --errors-for-leak-kinds=definite ---13982-- --verbose ---13982-- --log-file=valgrind-out.txt ---13982-- Contents of /proc/version: ---13982-- Linux version 5.15.0-122-generic (buildd@lcy02-amd64-106) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #132~20.04.1-Ubuntu SMP Fri Aug 30 15:50:07 UTC 2024 ---13982-- ---13982-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3 ---13982-- Page sizes: currently 4096, max supported 4096 ---13982-- Valgrind library directory: /usr/lib/x86_64-linux-gnu/valgrind ---13982-- Reading syms from /home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocket ---13982-- Reading syms from /usr/lib/x86_64-linux-gnu/ld-2.31.so ---13982-- Considering /usr/lib/debug/.build-id/db/0420f708b806cf03260aadb916c330049580b7.debug .. ---13982-- .. build-id is valid ---13982-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-linux ---13982-- object doesn't have a symbol table ---13982-- object doesn't have a dynamic symbol table ---13982-- Scheduler: using generic scheduler lock implementation. ---13982-- Reading suppressions file: /usr/lib/x86_64-linux-gnu/valgrind/default.supp -==13982== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-13982-by-stamrakar-on-??? -==13982== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-13982-by-stamrakar-on-??? -==13982== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-13982-by-stamrakar-on-??? -==13982== -==13982== TO CONTROL THIS PROCESS USING vgdb (which you probably -==13982== don't want to do, unless you know exactly what you're doing, -==13982== or are doing some strange experiment): -==13982== /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=13982 ...command... -==13982== -==13982== TO DEBUG THIS PROCESS USING GDB: start GDB like this -==13982== /path/to/gdb ./aesdsocket -==13982== and then give GDB the following command -==13982== target remote | /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=13982 -==13982== --pid is optional if only one valgrind process is running -==13982== ---13982-- REDIR: 0x4022e20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9ce2 (???) ---13982-- REDIR: 0x4022bf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c9cfc (???) ---13982-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_core-amd64-linux.so ---13982-- object doesn't have a symbol table ---13982-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so ---13982-- object doesn't have a symbol table -==13982== WARNING: new redirection conflicts with existing -- ignoring it ---13982-- old: 0x04022e20 (strlen ) R-> (0000.0) 0x580c9ce2 ??? ---13982-- new: 0x04022e20 (strlen ) R-> (2007.0) 0x0483f060 strlen ---13982-- REDIR: 0x401f600 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ffd0 (strcmp) ---13982-- REDIR: 0x4023380 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4843a20 (mempcpy) ---13982-- Reading syms from /usr/lib/x86_64-linux-gnu/librt-2.31.so ---13982-- Considering /usr/lib/debug/.build-id/fc/7c873442781f08af6bc88f1acac7ecccec7285.debug .. ---13982-- .. build-id is valid ---13982-- Reading syms from /usr/lib/x86_64-linux-gnu/libpthread-2.31.so ---13982-- Considering /usr/lib/debug/.build-id/9a/65bb469e45a1c6fbcffae5b82a2fd7a69eb479.debug .. ---13982-- .. build-id is valid ---13982-- Reading syms from /usr/lib/x86_64-linux-gnu/libc-2.31.so ---13982-- Considering /usr/lib/debug/.build-id/07/02430aef5fa3dda43986563e9ffcc47efbd75e.debug .. ---13982-- .. build-id is valid ---13982-- REDIR: 0x492a480 (libc.so.6:memmove) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x4929780 (libc.so.6:strncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x492a7b0 (libc.so.6:strcasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x49290a0 (libc.so.6:strcat) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x49297e0 (libc.so.6:rindex) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x492bc50 (libc.so.6:rawmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x4946ce0 (libc.so.6:wmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x4946820 (libc.so.6:wcscmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x492a5e0 (libc.so.6:mempcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x492a410 (libc.so.6:bcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x4929710 (libc.so.6:strncmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x4929150 (libc.so.6:strcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x492a540 (libc.so.6:memset) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x49467e0 (libc.so.6:wcschr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x4929670 (libc.so.6:strnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x4929230 (libc.so.6:strcspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x492a800 (libc.so.6:strncasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x49291d0 (libc.so.6:strcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x492a950 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x4947f50 (libc.so.6:wcsnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x4946860 (libc.so.6:wcscpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x4929820 (libc.so.6:strpbrk) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x4929100 (libc.so.6:index) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x4929630 (libc.so.6:strlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x4932bb0 (libc.so.6:memrchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x492a850 (libc.so.6:strcasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x492a3d0 (libc.so.6:memchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x4946930 (libc.so.6:wcslen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x4929ae0 (libc.so.6:strspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x492a750 (libc.so.6:stpncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x492a6f0 (libc.so.6:stpcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x492bc90 (libc.so.6:strchrnul) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x492a8a0 (libc.so.6:strncasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---13982-- REDIR: 0x493b8c0 (libc.so.6:__strrchr_sse2) redirected to 0x483ea70 (__strrchr_sse2) ---13982-- REDIR: 0x49240e0 (libc.so.6:malloc) redirected to 0x483b780 (malloc) ---13982-- REDIR: 0x4925b10 (libc.so.6:calloc) redirected to 0x483dce0 (calloc) ---13982-- REDIR: 0x493b6b0 (libc.so.6:__strchrnul_sse2) redirected to 0x4843540 (strchrnul) ---13982-- REDIR: 0x493bbc0 (libc.so.6:__strlen_sse2) redirected to 0x483efa0 (__strlen_sse2) ---13982-- REDIR: 0x49246d0 (libc.so.6:free) redirected to 0x483c9d0 (free) ---13982-- REDIR: 0x4945ad0 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4840100 (memcpy@GLIBC_2.2.5) ---13982-- REDIR: 0x4929fa0 (libc.so.6:__GI_strstr) redirected to 0x4843ca0 (__strstr_sse2) ---13982-- REDIR: 0x4a17790 (libc.so.6:__memcmp_sse4_1) redirected to 0x4842150 (__memcmp_sse4_1) ---13982-- REDIR: 0x49343b0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x483fed0 (strcmp) ---13982-- REDIR: 0x4945f00 (libc.so.6:__memset_sse2_unaligned) redirected to 0x48428e0 (memset) ---13982-- REDIR: 0x4945ab0 (libc.so.6:__mempcpy_sse2_unaligned) redirected to 0x4843660 (mempcpy) ---13982-- REDIR: 0x4924e80 (libc.so.6:realloc) redirected to 0x483df30 (realloc) ---13982-- REDIR: 0x4935ec0 (libc.so.6:__memchr_sse2) redirected to 0x4840050 (memchr) ---13982-- REDIR: 0x493b480 (libc.so.6:__strchr_sse2) redirected to 0x483eb90 (__strchr_sse2) ---13982-- REDIR: 0x4940b00 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x483f090 (strcpy) -==13982== Thread 3: -==13982== Syscall param read(buf) points to unaddressable byte(s) -==13982== at 0x487A3CC: __libc_read (read.c:26) -==13982== by 0x487A3CC: read (read.c:24) -==13982== by 0x10B440: threadfunc (aesdsocket.c:434) -==13982== by 0x486F608: start_thread (pthread_create.c:477) -==13982== by 0x49A9352: clone (clone.S:95) -==13982== Address 0x0 is not stack'd, malloc'd or (recently) free'd -==13982== ---13982-- REDIR: 0x4942140 (libc.so.6:__stpcpy_sse2_unaligned) redirected to 0x4842570 (__stpcpy_sse2_unaligned) -==13982== Thread 1: -==13982== Invalid read of size 4 -==13982== at 0x4861BC3: timer_delete@@GLIBC_2.3.3 (timer_delete.c:38) -==13982== by 0x10AB7D: closeAll (aesdsocket.c:213) -==13982== by 0x10BC67: main (aesdsocket.c:680) -==13982== Address 0x4 is not stack'd, malloc'd or (recently) free'd -==13982== -==13982== -==13982== Process terminating with default action of signal 11 (SIGSEGV) -==13982== Access not within mapped region at address 0x4 -==13982== at 0x4861BC3: timer_delete@@GLIBC_2.3.3 (timer_delete.c:38) -==13982== by 0x10AB7D: closeAll (aesdsocket.c:213) -==13982== by 0x10BC67: main (aesdsocket.c:680) -==13982== If you believe this happened as a result of a stack -==13982== overflow in your program's main thread (unlikely but -==13982== possible), you can try to increase the size of the -==13982== main thread stack using the --main-stacksize= flag. -==13982== The main thread stack size used in this run was 8388608. -==13982== -==13982== HEAP SUMMARY: -==13982== in use at exit: 624 bytes in 4 blocks -==13982== total heap usage: 687 allocs, 683 frees, 1,839,662 bytes allocated -==13982== -==13982== Searching for pointers to 4 not-freed blocks -==13982== Checked 16,863,600 bytes -==13982== -==13982== 40 bytes in 1 blocks are still reachable in loss record 1 of 4 -==13982== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==13982== by 0x10AA21: initTimer (aesdsocket.c:180) -==13982== by 0x10B802: main (aesdsocket.c:568) -==13982== -==13982== 40 bytes in 1 blocks are still reachable in loss record 2 of 4 -==13982== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==13982== by 0x10B88C: main (aesdsocket.c:585) -==13982== -==13982== 272 bytes in 1 blocks are possibly lost in loss record 3 of 4 -==13982== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==13982== by 0x40149DA: allocate_dtv (dl-tls.c:286) -==13982== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) -==13982== by 0x4870322: allocate_stack (allocatestack.c:622) -==13982== by 0x4870322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) -==13982== by 0x10AA6F: initTimer (aesdsocket.c:190) -==13982== by 0x10B802: main (aesdsocket.c:568) -==13982== -==13982== 272 bytes in 1 blocks are possibly lost in loss record 4 of 4 -==13982== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==13982== by 0x40149DA: allocate_dtv (dl-tls.c:286) -==13982== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) -==13982== by 0x4870322: allocate_stack (allocatestack.c:622) -==13982== by 0x4870322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) -==13982== by 0x10B95D: main (aesdsocket.c:608) -==13982== -==13982== LEAK SUMMARY: -==13982== definitely lost: 0 bytes in 0 blocks -==13982== indirectly lost: 0 bytes in 0 blocks -==13982== possibly lost: 544 bytes in 2 blocks -==13982== still reachable: 80 bytes in 2 blocks -==13982== suppressed: 0 bytes in 0 blocks -==13982== -==13982== ERROR SUMMARY: 18 errors from 2 contexts (suppressed: 0 from 0) -==13982== -==13982== 1 errors in context 1 of 2: -==13982== Invalid read of size 4 -==13982== at 0x4861BC3: timer_delete@@GLIBC_2.3.3 (timer_delete.c:38) -==13982== by 0x10AB7D: closeAll (aesdsocket.c:213) -==13982== by 0x10BC67: main (aesdsocket.c:680) -==13982== Address 0x4 is not stack'd, malloc'd or (recently) free'd -==13982== -==13982== -==13982== 17 errors in context 2 of 2: -==13982== Thread 3: -==13982== Syscall param read(buf) points to unaddressable byte(s) -==13982== at 0x487A3CC: __libc_read (read.c:26) -==13982== by 0x487A3CC: read (read.c:24) -==13982== by 0x10B440: threadfunc (aesdsocket.c:434) -==13982== by 0x486F608: start_thread (pthread_create.c:477) -==13982== by 0x49A9352: clone (clone.S:95) -==13982== Address 0x0 is not stack'd, malloc'd or (recently) free'd -==13982== -==13982== ERROR SUMMARY: 18 errors from 2 contexts (suppressed: 0 from 0) +==16783== Memcheck, a memory error detector +==16783== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. +==16783== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info +==16783== Command: ./aesdsocket +==16783== Parent PID: 16780 +==16783== +--16783-- +--16783-- Valgrind options: +--16783-- --error-exitcode=1 +--16783-- --leak-check=full +--16783-- --show-leak-kinds=all +--16783-- --track-origins=yes +--16783-- --errors-for-leak-kinds=definite +--16783-- --verbose +--16783-- --log-file=valgrind-out.txt +--16783-- Contents of /proc/version: +--16783-- Linux version 5.15.0-122-generic (buildd@lcy02-amd64-106) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #132~20.04.1-Ubuntu SMP Fri Aug 30 15:50:07 UTC 2024 +--16783-- +--16783-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3 +--16783-- Page sizes: currently 4096, max supported 4096 +--16783-- Valgrind library directory: /usr/lib/x86_64-linux-gnu/valgrind +--16783-- Reading syms from /home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocket +--16783-- Reading syms from /usr/lib/x86_64-linux-gnu/ld-2.31.so +--16783-- Considering /usr/lib/debug/.build-id/db/0420f708b806cf03260aadb916c330049580b7.debug .. +--16783-- .. build-id is valid +--16783-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-linux +--16783-- object doesn't have a symbol table +--16783-- object doesn't have a dynamic symbol table +--16783-- Scheduler: using generic scheduler lock implementation. +--16783-- Reading suppressions file: /usr/lib/x86_64-linux-gnu/valgrind/default.supp +==16783== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-16783-by-stamrakar-on-??? +==16783== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-16783-by-stamrakar-on-??? +==16783== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-16783-by-stamrakar-on-??? +==16783== +==16783== TO CONTROL THIS PROCESS USING vgdb (which you probably +==16783== don't want to do, unless you know exactly what you're doing, +==16783== or are doing some strange experiment): +==16783== /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=16783 ...command... +==16783== +==16783== TO DEBUG THIS PROCESS USING GDB: start GDB like this +==16783== /path/to/gdb ./aesdsocket +==16783== and then give GDB the following command +==16783== target remote | /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=16783 +==16783== --pid is optional if only one valgrind process is running +==16783== +--16783-- REDIR: 0x4022e20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9ce2 (???) +--16783-- REDIR: 0x4022bf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c9cfc (???) +--16783-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_core-amd64-linux.so +--16783-- object doesn't have a symbol table +--16783-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so +--16783-- object doesn't have a symbol table +==16783== WARNING: new redirection conflicts with existing -- ignoring it +--16783-- old: 0x04022e20 (strlen ) R-> (0000.0) 0x580c9ce2 ??? +--16783-- new: 0x04022e20 (strlen ) R-> (2007.0) 0x0483f060 strlen +--16783-- REDIR: 0x401f600 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ffd0 (strcmp) +--16783-- REDIR: 0x4023380 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4843a20 (mempcpy) +--16783-- Reading syms from /usr/lib/x86_64-linux-gnu/librt-2.31.so +--16783-- Considering /usr/lib/debug/.build-id/fc/7c873442781f08af6bc88f1acac7ecccec7285.debug .. +--16783-- .. build-id is valid +--16783-- Reading syms from /usr/lib/x86_64-linux-gnu/libpthread-2.31.so +--16783-- Considering /usr/lib/debug/.build-id/9a/65bb469e45a1c6fbcffae5b82a2fd7a69eb479.debug .. +--16783-- .. build-id is valid +--16783-- Reading syms from /usr/lib/x86_64-linux-gnu/libc-2.31.so +--16783-- Considering /usr/lib/debug/.build-id/07/02430aef5fa3dda43986563e9ffcc47efbd75e.debug .. +--16783-- .. build-id is valid +--16783-- REDIR: 0x492a480 (libc.so.6:memmove) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x4929780 (libc.so.6:strncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x492a7b0 (libc.so.6:strcasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x49290a0 (libc.so.6:strcat) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x49297e0 (libc.so.6:rindex) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x492bc50 (libc.so.6:rawmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x4946ce0 (libc.so.6:wmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x4946820 (libc.so.6:wcscmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x492a5e0 (libc.so.6:mempcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x492a410 (libc.so.6:bcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x4929710 (libc.so.6:strncmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x4929150 (libc.so.6:strcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x492a540 (libc.so.6:memset) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x49467e0 (libc.so.6:wcschr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x4929670 (libc.so.6:strnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x4929230 (libc.so.6:strcspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x492a800 (libc.so.6:strncasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x49291d0 (libc.so.6:strcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x492a950 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x4947f50 (libc.so.6:wcsnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x4946860 (libc.so.6:wcscpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x4929820 (libc.so.6:strpbrk) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x4929100 (libc.so.6:index) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x4929630 (libc.so.6:strlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x4932bb0 (libc.so.6:memrchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x492a850 (libc.so.6:strcasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x492a3d0 (libc.so.6:memchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x4946930 (libc.so.6:wcslen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x4929ae0 (libc.so.6:strspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x492a750 (libc.so.6:stpncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x492a6f0 (libc.so.6:stpcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x492bc90 (libc.so.6:strchrnul) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x492a8a0 (libc.so.6:strncasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--16783-- REDIR: 0x493b8c0 (libc.so.6:__strrchr_sse2) redirected to 0x483ea70 (__strrchr_sse2) +--16783-- REDIR: 0x49240e0 (libc.so.6:malloc) redirected to 0x483b780 (malloc) +--16783-- REDIR: 0x4925b10 (libc.so.6:calloc) redirected to 0x483dce0 (calloc) +--16783-- REDIR: 0x493b6b0 (libc.so.6:__strchrnul_sse2) redirected to 0x4843540 (strchrnul) +--16783-- REDIR: 0x493bbc0 (libc.so.6:__strlen_sse2) redirected to 0x483efa0 (__strlen_sse2) +--16783-- REDIR: 0x49246d0 (libc.so.6:free) redirected to 0x483c9d0 (free) +--16783-- REDIR: 0x4945ad0 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4840100 (memcpy@GLIBC_2.2.5) +--16783-- REDIR: 0x4929fa0 (libc.so.6:__GI_strstr) redirected to 0x4843ca0 (__strstr_sse2) +--16783-- REDIR: 0x4a17790 (libc.so.6:__memcmp_sse4_1) redirected to 0x4842150 (__memcmp_sse4_1) +--16783-- REDIR: 0x49343b0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x483fed0 (strcmp) +--16783-- REDIR: 0x4945f00 (libc.so.6:__memset_sse2_unaligned) redirected to 0x48428e0 (memset) +--16783-- REDIR: 0x4945ab0 (libc.so.6:__mempcpy_sse2_unaligned) redirected to 0x4843660 (mempcpy) +--16783-- REDIR: 0x4924e80 (libc.so.6:realloc) redirected to 0x483df30 (realloc) +--16783-- REDIR: 0x4935ec0 (libc.so.6:__memchr_sse2) redirected to 0x4840050 (memchr) +--16783-- REDIR: 0x493b480 (libc.so.6:__strchr_sse2) redirected to 0x483eb90 (__strchr_sse2) +--16783-- REDIR: 0x4940b00 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x483f090 (strcpy) +==16783== Thread 3: +==16783== Syscall param read(buf) points to unaddressable byte(s) +==16783== at 0x487A3CC: __libc_read (read.c:26) +==16783== by 0x487A3CC: read (read.c:24) +==16783== by 0x10B506: threadfunc (aesdsocket.c:457) +==16783== by 0x486F608: start_thread (pthread_create.c:477) +==16783== by 0x49A9352: clone (clone.S:95) +==16783== Address 0x0 is not stack'd, malloc'd or (recently) free'd +==16783== +--16783-- REDIR: 0x4942140 (libc.so.6:__stpcpy_sse2_unaligned) redirected to 0x4842570 (__stpcpy_sse2_unaligned) +==16783== Thread 1: +==16783== Invalid read of size 4 +==16783== at 0x4861BC3: timer_delete@@GLIBC_2.3.3 (timer_delete.c:38) +==16783== by 0x10AB7D: closeAll (aesdsocket.c:218) +==16783== by 0x10BD2D: main (aesdsocket.c:704) +==16783== Address 0x4 is not stack'd, malloc'd or (recently) free'd +==16783== +==16783== +==16783== Process terminating with default action of signal 11 (SIGSEGV) +==16783== Access not within mapped region at address 0x4 +==16783== at 0x4861BC3: timer_delete@@GLIBC_2.3.3 (timer_delete.c:38) +==16783== by 0x10AB7D: closeAll (aesdsocket.c:218) +==16783== by 0x10BD2D: main (aesdsocket.c:704) +==16783== If you believe this happened as a result of a stack +==16783== overflow in your program's main thread (unlikely but +==16783== possible), you can try to increase the size of the +==16783== main thread stack using the --main-stacksize= flag. +==16783== The main thread stack size used in this run was 8388608. +==16783== +==16783== HEAP SUMMARY: +==16783== in use at exit: 624 bytes in 4 blocks +==16783== total heap usage: 687 allocs, 683 frees, 1,839,659 bytes allocated +==16783== +==16783== Searching for pointers to 4 not-freed blocks +==16783== Checked 16,863,520 bytes +==16783== +==16783== 40 bytes in 1 blocks are still reachable in loss record 1 of 4 +==16783== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==16783== by 0x10AA21: initTimer (aesdsocket.c:183) +==16783== by 0x10B8C8: main (aesdsocket.c:591) +==16783== +==16783== 40 bytes in 1 blocks are still reachable in loss record 2 of 4 +==16783== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==16783== by 0x10B952: main (aesdsocket.c:609) +==16783== +==16783== 272 bytes in 1 blocks are possibly lost in loss record 3 of 4 +==16783== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==16783== by 0x40149DA: allocate_dtv (dl-tls.c:286) +==16783== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) +==16783== by 0x4870322: allocate_stack (allocatestack.c:622) +==16783== by 0x4870322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) +==16783== by 0x10AA6F: initTimer (aesdsocket.c:193) +==16783== by 0x10B8C8: main (aesdsocket.c:591) +==16783== +==16783== 272 bytes in 1 blocks are possibly lost in loss record 4 of 4 +==16783== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==16783== by 0x40149DA: allocate_dtv (dl-tls.c:286) +==16783== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) +==16783== by 0x4870322: allocate_stack (allocatestack.c:622) +==16783== by 0x4870322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) +==16783== by 0x10BA23: main (aesdsocket.c:632) +==16783== +==16783== LEAK SUMMARY: +==16783== definitely lost: 0 bytes in 0 blocks +==16783== indirectly lost: 0 bytes in 0 blocks +==16783== possibly lost: 544 bytes in 2 blocks +==16783== still reachable: 80 bytes in 2 blocks +==16783== suppressed: 0 bytes in 0 blocks +==16783== +==16783== ERROR SUMMARY: 18 errors from 2 contexts (suppressed: 0 from 0) +==16783== +==16783== 1 errors in context 1 of 2: +==16783== Invalid read of size 4 +==16783== at 0x4861BC3: timer_delete@@GLIBC_2.3.3 (timer_delete.c:38) +==16783== by 0x10AB7D: closeAll (aesdsocket.c:218) +==16783== by 0x10BD2D: main (aesdsocket.c:704) +==16783== Address 0x4 is not stack'd, malloc'd or (recently) free'd +==16783== +==16783== +==16783== 17 errors in context 2 of 2: +==16783== Thread 3: +==16783== Syscall param read(buf) points to unaddressable byte(s) +==16783== at 0x487A3CC: __libc_read (read.c:26) +==16783== by 0x487A3CC: read (read.c:24) +==16783== by 0x10B506: threadfunc (aesdsocket.c:457) +==16783== by 0x486F608: start_thread (pthread_create.c:477) +==16783== by 0x49A9352: clone (clone.S:95) +==16783== Address 0x0 is not stack'd, malloc'd or (recently) free'd +==16783== +==16783== ERROR SUMMARY: 18 errors from 2 contexts (suppressed: 0 from 0) From 76b02a6cfd23edc9eecff59c5ae919f438a80e10 Mon Sep 17 00:00:00 2001 From: stamrakar Date: Mon, 14 Oct 2024 18:43:16 -0600 Subject: [PATCH 11/17] first run.sh --- server/aesdsocket.c | 92 ++++++++-- server/valgrind-out.txt | 363 ++++++++++++++++++---------------------- 2 files changed, 233 insertions(+), 222 deletions(-) diff --git a/server/aesdsocket.c b/server/aesdsocket.c index c6d7b9d..df53564 100644 --- a/server/aesdsocket.c +++ b/server/aesdsocket.c @@ -54,7 +54,7 @@ typedef struct thread_info_s thread_info_t; typedef struct slist_data_s my_threads; -static timer_t timerid; +//static timer_t timerid; pthread_mutex_t writeSocket = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t size_val = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t ll_lock = PTHREAD_MUTEX_INITIALIZER; @@ -179,24 +179,26 @@ static int create_daemon() static void initTimer(void) { - pthread_t timertid; - my_threads *timer_thread = (my_threads *)malloc(sizeof(my_threads)); - if (timer_thread == NULL) - { - syslog(LOG_ERR, "server: timer thread allocation"); - perror("server: timer thread allocation"); + //pthread_t timertid; + //my_threads *timer_thread = (my_threads *)malloc(sizeof(my_threads)); + //if (timer_thread == NULL) + //{ + // syslog(LOG_ERR, "server: timer thread allocation"); + // perror("server: timer thread allocation"); //should I be exiting everything here or just keep trying - } - else - { + //} + //else + //{ + // timer_thread->thread_info.thread_complete_success = false; int timer_rc; - if((timer_rc = pthread_create(&timertid, NULL, threadtimerfunc, (void*) &(timer_thread->thread_info))) != 0) + pthread_t timertid; + if((timer_rc = pthread_create(&timertid, NULL, threadtimerfunc, NULL)) != 0) { syslog(LOG_ERR, "Failed to pthread_create() timer_thread, error was %d", timer_rc); perror("Failed to pthread_create() timer_thread"); - free(timer_thread); + //free(timer_thread); } - } + //} syslog(LOG_DEBUG, "Timer thread created successfully"); return; } @@ -214,10 +216,11 @@ void closeAll(int exit_flag) { syslog(LOG_ERR, "File removal not successful"); } - - timer_delete(timerid); + syslog(LOG_DEBUG, "PERFORMING CLEANUP1"); + //timer_delete(timerid); pthread_mutex_destroy(&writeSocket); pthread_mutex_destroy(&ll_lock); + syslog(LOG_DEBUG, "PERFORMING CLEANUP2"); pthread_mutex_destroy(&size_val); syslog(LOG_DEBUG, "CLEANUP COMPLETED."); closelog(); @@ -227,6 +230,11 @@ void closeAll(int exit_flag) void *threadtimerfunc(void *args) { + //my_threads *thread_func_args = (my_threads *) args; + if (args != NULL) + { + printf("args passed is not NULL"); + } time_t now; struct tm *tm; char timestamp[100]; @@ -235,18 +243,31 @@ void *threadtimerfunc(void *args) ts.tv_nsec = 0; time_t start, end; start = time(NULL); + int nanosleep_rc; int rc; while(!sig) { + if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) // 515 , ts.tv_sec = 515; + { + printf("clock_gettime failed.\n"); + } + ts.tv_sec += 10; // ts.tv_sec = 525; - syslog(LOG_DEBUG, "Starting sleep at %ld", start); + syslog(LOG_DEBUG, "Starting sleep at %ld\n", start); + printf("Starting sleep at %ld", start); - clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL); + nanosleep_rc = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, NULL); + if (nanosleep_rc != 0) + { + printf("nanosleep failed.\n"); + } + + printf("nanosleep_rc is %d\n", nanosleep_rc); end = time(NULL); syslog(LOG_DEBUG, "Ending sleep at %ld, slept for %ld seconds", end, end-start); - + printf("Ending sleep at %ld, slept for %ld seconds\n", end, end-start); now = time(NULL); @@ -300,6 +321,8 @@ void *threadtimerfunc(void *args) perror("pthread mutex_unlock failed"); } } + printf("Thread should be completed here.\n"); + //thread_func_args->thread_info.thread_complete_success = true; return NULL; } void *threadfunc(void *args) @@ -700,6 +723,39 @@ int main(int argc, char *argv[]) } } + my_threads *datap1 = NULL; + my_threads *temp1 = NULL; + int join_rc1; + + if(SLIST_EMPTY(&head)) + { + printf("The list is empty\n"); + } + else + { + printf("\nThe list is not empty. About to join every threads\n"); + SLIST_FOREACH_SAFE(datap1, &head, nextThread, temp1) + { + join_rc1 = pthread_join(datap1->thread_info.threadid, NULL); + if(join_rc1 != 0) + { + syslog(LOG_ERR, "Failed to pthread_join(), error was %d", join_rc1); + perror("Failed to pthread_join()"); + continue; + } + syslog(LOG_DEBUG, "Joined thread %lu", datap1->thread_info.threadid); + SLIST_REMOVE(&head, datap1, slist_data_s, nextThread); + free(datap1); + datap1 = NULL; + } + } + + if(SLIST_EMPTY(&head)) + { + printf("List now empty.\n"); + } + else { printf("List still populated.\n"); + } syslog(LOG_DEBUG, "Do I reach here?"); closeAll(EXIT_SUCCESS); return 0; diff --git a/server/valgrind-out.txt b/server/valgrind-out.txt index 49cabc1..59a4e54 100644 --- a/server/valgrind-out.txt +++ b/server/valgrind-out.txt @@ -1,204 +1,159 @@ -==16783== Memcheck, a memory error detector -==16783== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. -==16783== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info -==16783== Command: ./aesdsocket -==16783== Parent PID: 16780 -==16783== ---16783-- ---16783-- Valgrind options: ---16783-- --error-exitcode=1 ---16783-- --leak-check=full ---16783-- --show-leak-kinds=all ---16783-- --track-origins=yes ---16783-- --errors-for-leak-kinds=definite ---16783-- --verbose ---16783-- --log-file=valgrind-out.txt ---16783-- Contents of /proc/version: ---16783-- Linux version 5.15.0-122-generic (buildd@lcy02-amd64-106) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #132~20.04.1-Ubuntu SMP Fri Aug 30 15:50:07 UTC 2024 ---16783-- ---16783-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3 ---16783-- Page sizes: currently 4096, max supported 4096 ---16783-- Valgrind library directory: /usr/lib/x86_64-linux-gnu/valgrind ---16783-- Reading syms from /home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocket ---16783-- Reading syms from /usr/lib/x86_64-linux-gnu/ld-2.31.so ---16783-- Considering /usr/lib/debug/.build-id/db/0420f708b806cf03260aadb916c330049580b7.debug .. ---16783-- .. build-id is valid ---16783-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-linux ---16783-- object doesn't have a symbol table ---16783-- object doesn't have a dynamic symbol table ---16783-- Scheduler: using generic scheduler lock implementation. ---16783-- Reading suppressions file: /usr/lib/x86_64-linux-gnu/valgrind/default.supp -==16783== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-16783-by-stamrakar-on-??? -==16783== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-16783-by-stamrakar-on-??? -==16783== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-16783-by-stamrakar-on-??? -==16783== -==16783== TO CONTROL THIS PROCESS USING vgdb (which you probably -==16783== don't want to do, unless you know exactly what you're doing, -==16783== or are doing some strange experiment): -==16783== /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=16783 ...command... -==16783== -==16783== TO DEBUG THIS PROCESS USING GDB: start GDB like this -==16783== /path/to/gdb ./aesdsocket -==16783== and then give GDB the following command -==16783== target remote | /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=16783 -==16783== --pid is optional if only one valgrind process is running -==16783== ---16783-- REDIR: 0x4022e20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9ce2 (???) ---16783-- REDIR: 0x4022bf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c9cfc (???) ---16783-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_core-amd64-linux.so ---16783-- object doesn't have a symbol table ---16783-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so ---16783-- object doesn't have a symbol table -==16783== WARNING: new redirection conflicts with existing -- ignoring it ---16783-- old: 0x04022e20 (strlen ) R-> (0000.0) 0x580c9ce2 ??? ---16783-- new: 0x04022e20 (strlen ) R-> (2007.0) 0x0483f060 strlen ---16783-- REDIR: 0x401f600 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ffd0 (strcmp) ---16783-- REDIR: 0x4023380 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4843a20 (mempcpy) ---16783-- Reading syms from /usr/lib/x86_64-linux-gnu/librt-2.31.so ---16783-- Considering /usr/lib/debug/.build-id/fc/7c873442781f08af6bc88f1acac7ecccec7285.debug .. ---16783-- .. build-id is valid ---16783-- Reading syms from /usr/lib/x86_64-linux-gnu/libpthread-2.31.so ---16783-- Considering /usr/lib/debug/.build-id/9a/65bb469e45a1c6fbcffae5b82a2fd7a69eb479.debug .. ---16783-- .. build-id is valid ---16783-- Reading syms from /usr/lib/x86_64-linux-gnu/libc-2.31.so ---16783-- Considering /usr/lib/debug/.build-id/07/02430aef5fa3dda43986563e9ffcc47efbd75e.debug .. ---16783-- .. build-id is valid ---16783-- REDIR: 0x492a480 (libc.so.6:memmove) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x4929780 (libc.so.6:strncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x492a7b0 (libc.so.6:strcasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x49290a0 (libc.so.6:strcat) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x49297e0 (libc.so.6:rindex) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x492bc50 (libc.so.6:rawmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x4946ce0 (libc.so.6:wmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x4946820 (libc.so.6:wcscmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x492a5e0 (libc.so.6:mempcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x492a410 (libc.so.6:bcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x4929710 (libc.so.6:strncmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x4929150 (libc.so.6:strcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x492a540 (libc.so.6:memset) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x49467e0 (libc.so.6:wcschr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x4929670 (libc.so.6:strnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x4929230 (libc.so.6:strcspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x492a800 (libc.so.6:strncasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x49291d0 (libc.so.6:strcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x492a950 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x4947f50 (libc.so.6:wcsnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x4946860 (libc.so.6:wcscpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x4929820 (libc.so.6:strpbrk) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x4929100 (libc.so.6:index) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x4929630 (libc.so.6:strlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x4932bb0 (libc.so.6:memrchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x492a850 (libc.so.6:strcasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x492a3d0 (libc.so.6:memchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x4946930 (libc.so.6:wcslen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x4929ae0 (libc.so.6:strspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x492a750 (libc.so.6:stpncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x492a6f0 (libc.so.6:stpcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x492bc90 (libc.so.6:strchrnul) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x492a8a0 (libc.so.6:strncasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---16783-- REDIR: 0x493b8c0 (libc.so.6:__strrchr_sse2) redirected to 0x483ea70 (__strrchr_sse2) ---16783-- REDIR: 0x49240e0 (libc.so.6:malloc) redirected to 0x483b780 (malloc) ---16783-- REDIR: 0x4925b10 (libc.so.6:calloc) redirected to 0x483dce0 (calloc) ---16783-- REDIR: 0x493b6b0 (libc.so.6:__strchrnul_sse2) redirected to 0x4843540 (strchrnul) ---16783-- REDIR: 0x493bbc0 (libc.so.6:__strlen_sse2) redirected to 0x483efa0 (__strlen_sse2) ---16783-- REDIR: 0x49246d0 (libc.so.6:free) redirected to 0x483c9d0 (free) ---16783-- REDIR: 0x4945ad0 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4840100 (memcpy@GLIBC_2.2.5) ---16783-- REDIR: 0x4929fa0 (libc.so.6:__GI_strstr) redirected to 0x4843ca0 (__strstr_sse2) ---16783-- REDIR: 0x4a17790 (libc.so.6:__memcmp_sse4_1) redirected to 0x4842150 (__memcmp_sse4_1) ---16783-- REDIR: 0x49343b0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x483fed0 (strcmp) ---16783-- REDIR: 0x4945f00 (libc.so.6:__memset_sse2_unaligned) redirected to 0x48428e0 (memset) ---16783-- REDIR: 0x4945ab0 (libc.so.6:__mempcpy_sse2_unaligned) redirected to 0x4843660 (mempcpy) ---16783-- REDIR: 0x4924e80 (libc.so.6:realloc) redirected to 0x483df30 (realloc) ---16783-- REDIR: 0x4935ec0 (libc.so.6:__memchr_sse2) redirected to 0x4840050 (memchr) ---16783-- REDIR: 0x493b480 (libc.so.6:__strchr_sse2) redirected to 0x483eb90 (__strchr_sse2) ---16783-- REDIR: 0x4940b00 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x483f090 (strcpy) -==16783== Thread 3: -==16783== Syscall param read(buf) points to unaddressable byte(s) -==16783== at 0x487A3CC: __libc_read (read.c:26) -==16783== by 0x487A3CC: read (read.c:24) -==16783== by 0x10B506: threadfunc (aesdsocket.c:457) -==16783== by 0x486F608: start_thread (pthread_create.c:477) -==16783== by 0x49A9352: clone (clone.S:95) -==16783== Address 0x0 is not stack'd, malloc'd or (recently) free'd -==16783== ---16783-- REDIR: 0x4942140 (libc.so.6:__stpcpy_sse2_unaligned) redirected to 0x4842570 (__stpcpy_sse2_unaligned) -==16783== Thread 1: -==16783== Invalid read of size 4 -==16783== at 0x4861BC3: timer_delete@@GLIBC_2.3.3 (timer_delete.c:38) -==16783== by 0x10AB7D: closeAll (aesdsocket.c:218) -==16783== by 0x10BD2D: main (aesdsocket.c:704) -==16783== Address 0x4 is not stack'd, malloc'd or (recently) free'd -==16783== -==16783== -==16783== Process terminating with default action of signal 11 (SIGSEGV) -==16783== Access not within mapped region at address 0x4 -==16783== at 0x4861BC3: timer_delete@@GLIBC_2.3.3 (timer_delete.c:38) -==16783== by 0x10AB7D: closeAll (aesdsocket.c:218) -==16783== by 0x10BD2D: main (aesdsocket.c:704) -==16783== If you believe this happened as a result of a stack -==16783== overflow in your program's main thread (unlikely but -==16783== possible), you can try to increase the size of the -==16783== main thread stack using the --main-stacksize= flag. -==16783== The main thread stack size used in this run was 8388608. -==16783== -==16783== HEAP SUMMARY: -==16783== in use at exit: 624 bytes in 4 blocks -==16783== total heap usage: 687 allocs, 683 frees, 1,839,659 bytes allocated -==16783== -==16783== Searching for pointers to 4 not-freed blocks -==16783== Checked 16,863,520 bytes -==16783== -==16783== 40 bytes in 1 blocks are still reachable in loss record 1 of 4 -==16783== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==16783== by 0x10AA21: initTimer (aesdsocket.c:183) -==16783== by 0x10B8C8: main (aesdsocket.c:591) -==16783== -==16783== 40 bytes in 1 blocks are still reachable in loss record 2 of 4 -==16783== at 0x483B7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==16783== by 0x10B952: main (aesdsocket.c:609) -==16783== -==16783== 272 bytes in 1 blocks are possibly lost in loss record 3 of 4 -==16783== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==16783== by 0x40149DA: allocate_dtv (dl-tls.c:286) -==16783== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) -==16783== by 0x4870322: allocate_stack (allocatestack.c:622) -==16783== by 0x4870322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) -==16783== by 0x10AA6F: initTimer (aesdsocket.c:193) -==16783== by 0x10B8C8: main (aesdsocket.c:591) -==16783== -==16783== 272 bytes in 1 blocks are possibly lost in loss record 4 of 4 -==16783== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==16783== by 0x40149DA: allocate_dtv (dl-tls.c:286) -==16783== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) -==16783== by 0x4870322: allocate_stack (allocatestack.c:622) -==16783== by 0x4870322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) -==16783== by 0x10BA23: main (aesdsocket.c:632) -==16783== -==16783== LEAK SUMMARY: -==16783== definitely lost: 0 bytes in 0 blocks -==16783== indirectly lost: 0 bytes in 0 blocks -==16783== possibly lost: 544 bytes in 2 blocks -==16783== still reachable: 80 bytes in 2 blocks -==16783== suppressed: 0 bytes in 0 blocks -==16783== -==16783== ERROR SUMMARY: 18 errors from 2 contexts (suppressed: 0 from 0) -==16783== -==16783== 1 errors in context 1 of 2: -==16783== Invalid read of size 4 -==16783== at 0x4861BC3: timer_delete@@GLIBC_2.3.3 (timer_delete.c:38) -==16783== by 0x10AB7D: closeAll (aesdsocket.c:218) -==16783== by 0x10BD2D: main (aesdsocket.c:704) -==16783== Address 0x4 is not stack'd, malloc'd or (recently) free'd -==16783== -==16783== -==16783== 17 errors in context 2 of 2: -==16783== Thread 3: -==16783== Syscall param read(buf) points to unaddressable byte(s) -==16783== at 0x487A3CC: __libc_read (read.c:26) -==16783== by 0x487A3CC: read (read.c:24) -==16783== by 0x10B506: threadfunc (aesdsocket.c:457) -==16783== by 0x486F608: start_thread (pthread_create.c:477) -==16783== by 0x49A9352: clone (clone.S:95) -==16783== Address 0x0 is not stack'd, malloc'd or (recently) free'd -==16783== -==16783== ERROR SUMMARY: 18 errors from 2 contexts (suppressed: 0 from 0) +==26717== Memcheck, a memory error detector +==26717== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. +==26717== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info +==26717== Command: ./aesdsocket +==26717== Parent PID: 26716 +==26717== +--26717-- +--26717-- Valgrind options: +--26717-- --error-exitcode=1 +--26717-- --leak-check=full +--26717-- --show-leak-kinds=all +--26717-- --track-origins=yes +--26717-- --errors-for-leak-kinds=definite +--26717-- --verbose +--26717-- --log-file=valgrind-out.txt +--26717-- Contents of /proc/version: +--26717-- Linux version 5.15.0-122-generic (buildd@lcy02-amd64-106) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #132~20.04.1-Ubuntu SMP Fri Aug 30 15:50:07 UTC 2024 +--26717-- +--26717-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3 +--26717-- Page sizes: currently 4096, max supported 4096 +--26717-- Valgrind library directory: /usr/lib/x86_64-linux-gnu/valgrind +--26717-- Reading syms from /home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocket +--26717-- Reading syms from /usr/lib/x86_64-linux-gnu/ld-2.31.so +--26717-- Considering /usr/lib/debug/.build-id/db/0420f708b806cf03260aadb916c330049580b7.debug .. +--26717-- .. build-id is valid +--26717-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-linux +--26717-- object doesn't have a symbol table +--26717-- object doesn't have a dynamic symbol table +--26717-- Scheduler: using generic scheduler lock implementation. +--26717-- Reading suppressions file: /usr/lib/x86_64-linux-gnu/valgrind/default.supp +==26717== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-26717-by-stamrakar-on-??? +==26717== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-26717-by-stamrakar-on-??? +==26717== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-26717-by-stamrakar-on-??? +==26717== +==26717== TO CONTROL THIS PROCESS USING vgdb (which you probably +==26717== don't want to do, unless you know exactly what you're doing, +==26717== or are doing some strange experiment): +==26717== /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=26717 ...command... +==26717== +==26717== TO DEBUG THIS PROCESS USING GDB: start GDB like this +==26717== /path/to/gdb ./aesdsocket +==26717== and then give GDB the following command +==26717== target remote | /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=26717 +==26717== --pid is optional if only one valgrind process is running +==26717== +--26717-- REDIR: 0x4022e20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9ce2 (???) +--26717-- REDIR: 0x4022bf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c9cfc (???) +--26717-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_core-amd64-linux.so +--26717-- object doesn't have a symbol table +--26717-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so +--26717-- object doesn't have a symbol table +==26717== WARNING: new redirection conflicts with existing -- ignoring it +--26717-- old: 0x04022e20 (strlen ) R-> (0000.0) 0x580c9ce2 ??? +--26717-- new: 0x04022e20 (strlen ) R-> (2007.0) 0x0483f060 strlen +--26717-- REDIR: 0x401f600 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ffd0 (strcmp) +--26717-- REDIR: 0x4023380 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4843a20 (mempcpy) +--26717-- Reading syms from /usr/lib/x86_64-linux-gnu/libpthread-2.31.so +--26717-- Considering /usr/lib/debug/.build-id/9a/65bb469e45a1c6fbcffae5b82a2fd7a69eb479.debug .. +--26717-- .. build-id is valid +--26717-- Reading syms from /usr/lib/x86_64-linux-gnu/libc-2.31.so +--26717-- Considering /usr/lib/debug/.build-id/07/02430aef5fa3dda43986563e9ffcc47efbd75e.debug .. +--26717-- .. build-id is valid +--26717-- REDIR: 0x4920480 (libc.so.6:memmove) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x491f780 (libc.so.6:strncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x49207b0 (libc.so.6:strcasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x491f0a0 (libc.so.6:strcat) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x491f7e0 (libc.so.6:rindex) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x4921c50 (libc.so.6:rawmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x493cce0 (libc.so.6:wmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x493c820 (libc.so.6:wcscmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x49205e0 (libc.so.6:mempcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x4920410 (libc.so.6:bcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x491f710 (libc.so.6:strncmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x491f150 (libc.so.6:strcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x4920540 (libc.so.6:memset) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x493c7e0 (libc.so.6:wcschr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x491f670 (libc.so.6:strnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x491f230 (libc.so.6:strcspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x4920800 (libc.so.6:strncasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x491f1d0 (libc.so.6:strcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x4920950 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x493df50 (libc.so.6:wcsnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x493c860 (libc.so.6:wcscpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x491f820 (libc.so.6:strpbrk) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x491f100 (libc.so.6:index) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x491f630 (libc.so.6:strlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x4928bb0 (libc.so.6:memrchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x4920850 (libc.so.6:strcasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x49203d0 (libc.so.6:memchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x493c930 (libc.so.6:wcslen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x491fae0 (libc.so.6:strspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x4920750 (libc.so.6:stpncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x49206f0 (libc.so.6:stpcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x4921c90 (libc.so.6:strchrnul) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x49208a0 (libc.so.6:strncasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--26717-- REDIR: 0x49318c0 (libc.so.6:__strrchr_sse2) redirected to 0x483ea70 (__strrchr_sse2) +--26717-- REDIR: 0x491a0e0 (libc.so.6:malloc) redirected to 0x483b780 (malloc) +--26717-- REDIR: 0x491bb10 (libc.so.6:calloc) redirected to 0x483dce0 (calloc) +--26717-- REDIR: 0x49316b0 (libc.so.6:__strchrnul_sse2) redirected to 0x4843540 (strchrnul) +--26717-- REDIR: 0x4931bc0 (libc.so.6:__strlen_sse2) redirected to 0x483efa0 (__strlen_sse2) +--26717-- REDIR: 0x491a6d0 (libc.so.6:free) redirected to 0x483c9d0 (free) +--26717-- REDIR: 0x493bad0 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4840100 (memcpy@GLIBC_2.2.5) +--26717-- REDIR: 0x491ffa0 (libc.so.6:__GI_strstr) redirected to 0x4843ca0 (__strstr_sse2) +--26717-- REDIR: 0x4a0d790 (libc.so.6:__memcmp_sse4_1) redirected to 0x4842150 (__memcmp_sse4_1) +--26717-- REDIR: 0x492a3b0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x483fed0 (strcmp) +--26717-- REDIR: 0x493bab0 (libc.so.6:__mempcpy_sse2_unaligned) redirected to 0x4843660 (mempcpy) +--26717-- REDIR: 0x491ae80 (libc.so.6:realloc) redirected to 0x483df30 (realloc) +--26717-- REDIR: 0x493bf00 (libc.so.6:__memset_sse2_unaligned) redirected to 0x48428e0 (memset) +--26717-- REDIR: 0x492bec0 (libc.so.6:__memchr_sse2) redirected to 0x4840050 (memchr) +--26717-- REDIR: 0x4931480 (libc.so.6:__strchr_sse2) redirected to 0x483eb90 (__strchr_sse2) +--26717-- REDIR: 0x4936b00 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x483f090 (strcpy) +==26717== Thread 3: +==26717== Syscall param read(buf) points to unaddressable byte(s) +==26717== at 0x48703CC: __libc_read (read.c:26) +==26717== by 0x48703CC: read (read.c:24) +==26717== by 0x10B53D: threadfunc (aesdsocket.c:480) +==26717== by 0x4865608: start_thread (pthread_create.c:477) +==26717== by 0x499F352: clone (clone.S:95) +==26717== Address 0x0 is not stack'd, malloc'd or (recently) free'd +==26717== +--26717-- REDIR: 0x4938140 (libc.so.6:__stpcpy_sse2_unaligned) redirected to 0x4842570 (__stpcpy_sse2_unaligned) +==26717== +==26717== HEAP SUMMARY: +==26717== in use at exit: 272 bytes in 1 blocks +==26717== total heap usage: 698 allocs, 697 frees, 1,878,493 bytes allocated +==26717== +==26717== Searching for pointers to 1 not-freed blocks +==26717== Checked 8,477,304 bytes +==26717== +==26717== Thread 1: +==26717== 272 bytes in 1 blocks are possibly lost in loss record 1 of 1 +==26717== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==26717== by 0x40149DA: allocate_dtv (dl-tls.c:286) +==26717== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) +==26717== by 0x4866322: allocate_stack (allocatestack.c:622) +==26717== by 0x4866322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) +==26717== by 0x10AA74: initTimer (aesdsocket.c:195) +==26717== by 0x10B8FF: main (aesdsocket.c:614) +==26717== +==26717== LEAK SUMMARY: +==26717== definitely lost: 0 bytes in 0 blocks +==26717== indirectly lost: 0 bytes in 0 blocks +==26717== possibly lost: 272 bytes in 1 blocks +==26717== still reachable: 0 bytes in 0 blocks +==26717== suppressed: 0 bytes in 0 blocks +==26717== +==26717== ERROR SUMMARY: 17 errors from 1 contexts (suppressed: 0 from 0) +==26717== +==26717== 17 errors in context 1 of 1: +==26717== Thread 3: +==26717== Syscall param read(buf) points to unaddressable byte(s) +==26717== at 0x48703CC: __libc_read (read.c:26) +==26717== by 0x48703CC: read (read.c:24) +==26717== by 0x10B53D: threadfunc (aesdsocket.c:480) +==26717== by 0x4865608: start_thread (pthread_create.c:477) +==26717== by 0x499F352: clone (clone.S:95) +==26717== Address 0x0 is not stack'd, malloc'd or (recently) free'd +==26717== +==26717== ERROR SUMMARY: 17 errors from 1 contexts (suppressed: 0 from 0) From fc1e1bcc5d52de050fc18d006a697edc0b08cb4f Mon Sep 17 00:00:00 2001 From: stamrakar Date: Mon, 14 Oct 2024 19:18:56 -0600 Subject: [PATCH 12/17] actions2 --- server/aesdsocket.c | 65 ++++---- server/valgrind-out.txt | 318 ++++++++++++++++++++-------------------- 2 files changed, 193 insertions(+), 190 deletions(-) diff --git a/server/aesdsocket.c b/server/aesdsocket.c index df53564..6733c50 100644 --- a/server/aesdsocket.c +++ b/server/aesdsocket.c @@ -48,22 +48,20 @@ //optional #define BACKLOG (10) // pending connections -#define BUF_SIZE 1024 +#define BUF_SIZE 1500 #define TSTAMP_INTERVAL (10) #define TIMESTAMP_INTERVAL (10) typedef struct thread_info_s thread_info_t; typedef struct slist_data_s my_threads; -//static timer_t timerid; pthread_mutex_t writeSocket = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t size_val = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t ll_lock = PTHREAD_MUTEX_INITIALIZER; -//pthread_mutex_t timer_mutex; + struct thread_info_s{ pthread_t threadid; - //int write_file_fd; int afd; //accepted fd psot accept() connection. bool thread_complete_success; char ip4[INET_ADDRSTRLEN]; //space to hold the IPv4 string @@ -89,8 +87,8 @@ int recvfile_fd = -1; static ssize_t total_size = 0; pid_t pid; -//const char *recvfile = "/var/tmp/aesdsocketdata"; -const char *recvfile = "/home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocketdata"; +const char *recvfile = "/var/tmp/aesdsocketdata"; +//const char *recvfile = "/home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocketdata"; static void closeAll(int exit_flag); static void initTimer(void); static void init_sigHandler(void); @@ -179,26 +177,13 @@ static int create_daemon() static void initTimer(void) { - //pthread_t timertid; - //my_threads *timer_thread = (my_threads *)malloc(sizeof(my_threads)); - //if (timer_thread == NULL) - //{ - // syslog(LOG_ERR, "server: timer thread allocation"); - // perror("server: timer thread allocation"); - //should I be exiting everything here or just keep trying - //} - //else - //{ - // timer_thread->thread_info.thread_complete_success = false; - int timer_rc; - pthread_t timertid; - if((timer_rc = pthread_create(&timertid, NULL, threadtimerfunc, NULL)) != 0) - { - syslog(LOG_ERR, "Failed to pthread_create() timer_thread, error was %d", timer_rc); - perror("Failed to pthread_create() timer_thread"); - //free(timer_thread); - } - //} + int timer_rc; + pthread_t timertid; + if((timer_rc = pthread_create(&timertid, NULL, threadtimerfunc, NULL)) != 0) + { + syslog(LOG_ERR, "Failed to pthread_create() timer_thread, error was %d", timer_rc); + perror("Failed to pthread_create() timer_thread"); + } syslog(LOG_DEBUG, "Timer thread created successfully"); return; } @@ -255,7 +240,7 @@ void *threadtimerfunc(void *args) ts.tv_sec += 10; // ts.tv_sec = 525; syslog(LOG_DEBUG, "Starting sleep at %ld\n", start); - printf("Starting sleep at %ld", start); + printf("Starting sleep at %ld\n", start); nanosleep_rc = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, NULL); if (nanosleep_rc != 0) @@ -473,17 +458,33 @@ void *threadfunc(void *args) } - //syslog(LOG_DEBUG, "lseek pass"); + rc = pthread_mutex_lock(&size_val); + if (rc != 0) + { + syslog(LOG_ERR, "pthread_mutex_lock failed on total size, error was %d", rc); + perror("pthread mutex_lock failed"); + } + + int temp_total_size = total_size; + + rc = pthread_mutex_unlock(&size_val); + if (rc != 0) + { + syslog(LOG_ERR, "pthread_mutex_unlock failed on total size, error was %d", rc); + perror("pthread mutex_lock failed"); + } + int errnum9 = 0; - while ((bytes_read = read(recvfile_fd, send_my_buffer, total_size)) > 0) { + printf("total size here is %ld\n", total_size); + while ((bytes_read = read(recvfile_fd, send_my_buffer, temp_total_size)) > 0) { syslog(LOG_DEBUG, "bytes_read is %ld", bytes_read); //syslog(LOG_DEBUG, "Sending: %s",send_my_buffer); if (send(thread_func_args->thread_info.afd, send_my_buffer, bytes_read, 0) != bytes_read) { errnum9 = errno; - syslog(LOG_DEBUG,"HEREEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"); + syslog(LOG_DEBUG,"HERE"); syslog(LOG_ERR, "server: send, errno is %d", errnum9); syslog(LOG_ERR, "error string is %s", strerror(errno)); perror("server: send"); @@ -612,7 +613,8 @@ int main(int argc, char *argv[]) initTimer(); - //initTimer2(); + + printf("Timer thread has been set\n"); while(!sig){ @@ -757,6 +759,7 @@ int main(int argc, char *argv[]) else { printf("List still populated.\n"); } syslog(LOG_DEBUG, "Do I reach here?"); + printf("Do I reach here?\n"); closeAll(EXIT_SUCCESS); return 0; } \ No newline at end of file diff --git a/server/valgrind-out.txt b/server/valgrind-out.txt index 59a4e54..3c0daa9 100644 --- a/server/valgrind-out.txt +++ b/server/valgrind-out.txt @@ -1,159 +1,159 @@ -==26717== Memcheck, a memory error detector -==26717== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. -==26717== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info -==26717== Command: ./aesdsocket -==26717== Parent PID: 26716 -==26717== ---26717-- ---26717-- Valgrind options: ---26717-- --error-exitcode=1 ---26717-- --leak-check=full ---26717-- --show-leak-kinds=all ---26717-- --track-origins=yes ---26717-- --errors-for-leak-kinds=definite ---26717-- --verbose ---26717-- --log-file=valgrind-out.txt ---26717-- Contents of /proc/version: ---26717-- Linux version 5.15.0-122-generic (buildd@lcy02-amd64-106) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #132~20.04.1-Ubuntu SMP Fri Aug 30 15:50:07 UTC 2024 ---26717-- ---26717-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3 ---26717-- Page sizes: currently 4096, max supported 4096 ---26717-- Valgrind library directory: /usr/lib/x86_64-linux-gnu/valgrind ---26717-- Reading syms from /home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocket ---26717-- Reading syms from /usr/lib/x86_64-linux-gnu/ld-2.31.so ---26717-- Considering /usr/lib/debug/.build-id/db/0420f708b806cf03260aadb916c330049580b7.debug .. ---26717-- .. build-id is valid ---26717-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-linux ---26717-- object doesn't have a symbol table ---26717-- object doesn't have a dynamic symbol table ---26717-- Scheduler: using generic scheduler lock implementation. ---26717-- Reading suppressions file: /usr/lib/x86_64-linux-gnu/valgrind/default.supp -==26717== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-26717-by-stamrakar-on-??? -==26717== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-26717-by-stamrakar-on-??? -==26717== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-26717-by-stamrakar-on-??? -==26717== -==26717== TO CONTROL THIS PROCESS USING vgdb (which you probably -==26717== don't want to do, unless you know exactly what you're doing, -==26717== or are doing some strange experiment): -==26717== /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=26717 ...command... -==26717== -==26717== TO DEBUG THIS PROCESS USING GDB: start GDB like this -==26717== /path/to/gdb ./aesdsocket -==26717== and then give GDB the following command -==26717== target remote | /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=26717 -==26717== --pid is optional if only one valgrind process is running -==26717== ---26717-- REDIR: 0x4022e20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9ce2 (???) ---26717-- REDIR: 0x4022bf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c9cfc (???) ---26717-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_core-amd64-linux.so ---26717-- object doesn't have a symbol table ---26717-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so ---26717-- object doesn't have a symbol table -==26717== WARNING: new redirection conflicts with existing -- ignoring it ---26717-- old: 0x04022e20 (strlen ) R-> (0000.0) 0x580c9ce2 ??? ---26717-- new: 0x04022e20 (strlen ) R-> (2007.0) 0x0483f060 strlen ---26717-- REDIR: 0x401f600 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ffd0 (strcmp) ---26717-- REDIR: 0x4023380 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4843a20 (mempcpy) ---26717-- Reading syms from /usr/lib/x86_64-linux-gnu/libpthread-2.31.so ---26717-- Considering /usr/lib/debug/.build-id/9a/65bb469e45a1c6fbcffae5b82a2fd7a69eb479.debug .. ---26717-- .. build-id is valid ---26717-- Reading syms from /usr/lib/x86_64-linux-gnu/libc-2.31.so ---26717-- Considering /usr/lib/debug/.build-id/07/02430aef5fa3dda43986563e9ffcc47efbd75e.debug .. ---26717-- .. build-id is valid ---26717-- REDIR: 0x4920480 (libc.so.6:memmove) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x491f780 (libc.so.6:strncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x49207b0 (libc.so.6:strcasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x491f0a0 (libc.so.6:strcat) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x491f7e0 (libc.so.6:rindex) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x4921c50 (libc.so.6:rawmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x493cce0 (libc.so.6:wmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x493c820 (libc.so.6:wcscmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x49205e0 (libc.so.6:mempcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x4920410 (libc.so.6:bcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x491f710 (libc.so.6:strncmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x491f150 (libc.so.6:strcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x4920540 (libc.so.6:memset) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x493c7e0 (libc.so.6:wcschr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x491f670 (libc.so.6:strnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x491f230 (libc.so.6:strcspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x4920800 (libc.so.6:strncasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x491f1d0 (libc.so.6:strcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x4920950 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x493df50 (libc.so.6:wcsnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x493c860 (libc.so.6:wcscpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x491f820 (libc.so.6:strpbrk) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x491f100 (libc.so.6:index) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x491f630 (libc.so.6:strlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x4928bb0 (libc.so.6:memrchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x4920850 (libc.so.6:strcasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x49203d0 (libc.so.6:memchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x493c930 (libc.so.6:wcslen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x491fae0 (libc.so.6:strspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x4920750 (libc.so.6:stpncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x49206f0 (libc.so.6:stpcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x4921c90 (libc.so.6:strchrnul) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x49208a0 (libc.so.6:strncasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---26717-- REDIR: 0x49318c0 (libc.so.6:__strrchr_sse2) redirected to 0x483ea70 (__strrchr_sse2) ---26717-- REDIR: 0x491a0e0 (libc.so.6:malloc) redirected to 0x483b780 (malloc) ---26717-- REDIR: 0x491bb10 (libc.so.6:calloc) redirected to 0x483dce0 (calloc) ---26717-- REDIR: 0x49316b0 (libc.so.6:__strchrnul_sse2) redirected to 0x4843540 (strchrnul) ---26717-- REDIR: 0x4931bc0 (libc.so.6:__strlen_sse2) redirected to 0x483efa0 (__strlen_sse2) ---26717-- REDIR: 0x491a6d0 (libc.so.6:free) redirected to 0x483c9d0 (free) ---26717-- REDIR: 0x493bad0 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4840100 (memcpy@GLIBC_2.2.5) ---26717-- REDIR: 0x491ffa0 (libc.so.6:__GI_strstr) redirected to 0x4843ca0 (__strstr_sse2) ---26717-- REDIR: 0x4a0d790 (libc.so.6:__memcmp_sse4_1) redirected to 0x4842150 (__memcmp_sse4_1) ---26717-- REDIR: 0x492a3b0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x483fed0 (strcmp) ---26717-- REDIR: 0x493bab0 (libc.so.6:__mempcpy_sse2_unaligned) redirected to 0x4843660 (mempcpy) ---26717-- REDIR: 0x491ae80 (libc.so.6:realloc) redirected to 0x483df30 (realloc) ---26717-- REDIR: 0x493bf00 (libc.so.6:__memset_sse2_unaligned) redirected to 0x48428e0 (memset) ---26717-- REDIR: 0x492bec0 (libc.so.6:__memchr_sse2) redirected to 0x4840050 (memchr) ---26717-- REDIR: 0x4931480 (libc.so.6:__strchr_sse2) redirected to 0x483eb90 (__strchr_sse2) ---26717-- REDIR: 0x4936b00 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x483f090 (strcpy) -==26717== Thread 3: -==26717== Syscall param read(buf) points to unaddressable byte(s) -==26717== at 0x48703CC: __libc_read (read.c:26) -==26717== by 0x48703CC: read (read.c:24) -==26717== by 0x10B53D: threadfunc (aesdsocket.c:480) -==26717== by 0x4865608: start_thread (pthread_create.c:477) -==26717== by 0x499F352: clone (clone.S:95) -==26717== Address 0x0 is not stack'd, malloc'd or (recently) free'd -==26717== ---26717-- REDIR: 0x4938140 (libc.so.6:__stpcpy_sse2_unaligned) redirected to 0x4842570 (__stpcpy_sse2_unaligned) -==26717== -==26717== HEAP SUMMARY: -==26717== in use at exit: 272 bytes in 1 blocks -==26717== total heap usage: 698 allocs, 697 frees, 1,878,493 bytes allocated -==26717== -==26717== Searching for pointers to 1 not-freed blocks -==26717== Checked 8,477,304 bytes -==26717== -==26717== Thread 1: -==26717== 272 bytes in 1 blocks are possibly lost in loss record 1 of 1 -==26717== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==26717== by 0x40149DA: allocate_dtv (dl-tls.c:286) -==26717== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) -==26717== by 0x4866322: allocate_stack (allocatestack.c:622) -==26717== by 0x4866322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) -==26717== by 0x10AA74: initTimer (aesdsocket.c:195) -==26717== by 0x10B8FF: main (aesdsocket.c:614) -==26717== -==26717== LEAK SUMMARY: -==26717== definitely lost: 0 bytes in 0 blocks -==26717== indirectly lost: 0 bytes in 0 blocks -==26717== possibly lost: 272 bytes in 1 blocks -==26717== still reachable: 0 bytes in 0 blocks -==26717== suppressed: 0 bytes in 0 blocks -==26717== -==26717== ERROR SUMMARY: 17 errors from 1 contexts (suppressed: 0 from 0) -==26717== -==26717== 17 errors in context 1 of 1: -==26717== Thread 3: -==26717== Syscall param read(buf) points to unaddressable byte(s) -==26717== at 0x48703CC: __libc_read (read.c:26) -==26717== by 0x48703CC: read (read.c:24) -==26717== by 0x10B53D: threadfunc (aesdsocket.c:480) -==26717== by 0x4865608: start_thread (pthread_create.c:477) -==26717== by 0x499F352: clone (clone.S:95) -==26717== Address 0x0 is not stack'd, malloc'd or (recently) free'd -==26717== -==26717== ERROR SUMMARY: 17 errors from 1 contexts (suppressed: 0 from 0) +==5018== Memcheck, a memory error detector +==5018== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. +==5018== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info +==5018== Command: ./aesdsocket +==5018== Parent PID: 5017 +==5018== +--5018-- +--5018-- Valgrind options: +--5018-- --error-exitcode=1 +--5018-- --leak-check=full +--5018-- --show-leak-kinds=all +--5018-- --track-origins=yes +--5018-- --errors-for-leak-kinds=definite +--5018-- --verbose +--5018-- --log-file=valgrind-out.txt +--5018-- Contents of /proc/version: +--5018-- Linux version 5.15.0-122-generic (buildd@lcy02-amd64-106) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #132~20.04.1-Ubuntu SMP Fri Aug 30 15:50:07 UTC 2024 +--5018-- +--5018-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3 +--5018-- Page sizes: currently 4096, max supported 4096 +--5018-- Valgrind library directory: /usr/lib/x86_64-linux-gnu/valgrind +--5018-- Reading syms from /home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocket +--5018-- Reading syms from /usr/lib/x86_64-linux-gnu/ld-2.31.so +--5018-- Considering /usr/lib/debug/.build-id/db/0420f708b806cf03260aadb916c330049580b7.debug .. +--5018-- .. build-id is valid +--5018-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-linux +--5018-- object doesn't have a symbol table +--5018-- object doesn't have a dynamic symbol table +--5018-- Scheduler: using generic scheduler lock implementation. +--5018-- Reading suppressions file: /usr/lib/x86_64-linux-gnu/valgrind/default.supp +==5018== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-5018-by-stamrakar-on-??? +==5018== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-5018-by-stamrakar-on-??? +==5018== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-5018-by-stamrakar-on-??? +==5018== +==5018== TO CONTROL THIS PROCESS USING vgdb (which you probably +==5018== don't want to do, unless you know exactly what you're doing, +==5018== or are doing some strange experiment): +==5018== /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=5018 ...command... +==5018== +==5018== TO DEBUG THIS PROCESS USING GDB: start GDB like this +==5018== /path/to/gdb ./aesdsocket +==5018== and then give GDB the following command +==5018== target remote | /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=5018 +==5018== --pid is optional if only one valgrind process is running +==5018== +--5018-- REDIR: 0x4022e20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9ce2 (???) +--5018-- REDIR: 0x4022bf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c9cfc (???) +--5018-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_core-amd64-linux.so +--5018-- object doesn't have a symbol table +--5018-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so +--5018-- object doesn't have a symbol table +==5018== WARNING: new redirection conflicts with existing -- ignoring it +--5018-- old: 0x04022e20 (strlen ) R-> (0000.0) 0x580c9ce2 ??? +--5018-- new: 0x04022e20 (strlen ) R-> (2007.0) 0x0483f060 strlen +--5018-- REDIR: 0x401f600 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ffd0 (strcmp) +--5018-- REDIR: 0x4023380 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4843a20 (mempcpy) +--5018-- Reading syms from /usr/lib/x86_64-linux-gnu/libpthread-2.31.so +--5018-- Considering /usr/lib/debug/.build-id/9a/65bb469e45a1c6fbcffae5b82a2fd7a69eb479.debug .. +--5018-- .. build-id is valid +--5018-- Reading syms from /usr/lib/x86_64-linux-gnu/libc-2.31.so +--5018-- Considering /usr/lib/debug/.build-id/07/02430aef5fa3dda43986563e9ffcc47efbd75e.debug .. +--5018-- .. build-id is valid +--5018-- REDIR: 0x4920480 (libc.so.6:memmove) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x491f780 (libc.so.6:strncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x49207b0 (libc.so.6:strcasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x491f0a0 (libc.so.6:strcat) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x491f7e0 (libc.so.6:rindex) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x4921c50 (libc.so.6:rawmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x493cce0 (libc.so.6:wmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x493c820 (libc.so.6:wcscmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x49205e0 (libc.so.6:mempcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x4920410 (libc.so.6:bcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x491f710 (libc.so.6:strncmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x491f150 (libc.so.6:strcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x4920540 (libc.so.6:memset) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x493c7e0 (libc.so.6:wcschr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x491f670 (libc.so.6:strnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x491f230 (libc.so.6:strcspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x4920800 (libc.so.6:strncasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x491f1d0 (libc.so.6:strcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x4920950 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x493df50 (libc.so.6:wcsnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x493c860 (libc.so.6:wcscpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x491f820 (libc.so.6:strpbrk) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x491f100 (libc.so.6:index) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x491f630 (libc.so.6:strlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x4928bb0 (libc.so.6:memrchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x4920850 (libc.so.6:strcasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x49203d0 (libc.so.6:memchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x493c930 (libc.so.6:wcslen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x491fae0 (libc.so.6:strspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x4920750 (libc.so.6:stpncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x49206f0 (libc.so.6:stpcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x4921c90 (libc.so.6:strchrnul) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x49208a0 (libc.so.6:strncasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5018-- REDIR: 0x49318c0 (libc.so.6:__strrchr_sse2) redirected to 0x483ea70 (__strrchr_sse2) +--5018-- REDIR: 0x491a0e0 (libc.so.6:malloc) redirected to 0x483b780 (malloc) +--5018-- REDIR: 0x491bb10 (libc.so.6:calloc) redirected to 0x483dce0 (calloc) +--5018-- REDIR: 0x49316b0 (libc.so.6:__strchrnul_sse2) redirected to 0x4843540 (strchrnul) +--5018-- REDIR: 0x4931bc0 (libc.so.6:__strlen_sse2) redirected to 0x483efa0 (__strlen_sse2) +--5018-- REDIR: 0x491a6d0 (libc.so.6:free) redirected to 0x483c9d0 (free) +--5018-- REDIR: 0x493bad0 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4840100 (memcpy@GLIBC_2.2.5) +--5018-- REDIR: 0x491ffa0 (libc.so.6:__GI_strstr) redirected to 0x4843ca0 (__strstr_sse2) +--5018-- REDIR: 0x4a0d790 (libc.so.6:__memcmp_sse4_1) redirected to 0x4842150 (__memcmp_sse4_1) +--5018-- REDIR: 0x492a3b0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x483fed0 (strcmp) +--5018-- REDIR: 0x493bf00 (libc.so.6:__memset_sse2_unaligned) redirected to 0x48428e0 (memset) +--5018-- REDIR: 0x493bab0 (libc.so.6:__mempcpy_sse2_unaligned) redirected to 0x4843660 (mempcpy) +--5018-- REDIR: 0x491ae80 (libc.so.6:realloc) redirected to 0x483df30 (realloc) +--5018-- REDIR: 0x492bec0 (libc.so.6:__memchr_sse2) redirected to 0x4840050 (memchr) +--5018-- REDIR: 0x4931480 (libc.so.6:__strchr_sse2) redirected to 0x483eb90 (__strchr_sse2) +--5018-- REDIR: 0x4936b00 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x483f090 (strcpy) +==5018== Thread 3: +==5018== Syscall param read(buf) points to unaddressable byte(s) +==5018== at 0x48703CC: __libc_read (read.c:26) +==5018== by 0x48703CC: read (read.c:24) +==5018== by 0x10B684: threadfunc (aesdsocket.c:481) +==5018== by 0x4865608: start_thread (pthread_create.c:477) +==5018== by 0x499F352: clone (clone.S:95) +==5018== Address 0x0 is not stack'd, malloc'd or (recently) free'd +==5018== +--5018-- REDIR: 0x4938140 (libc.so.6:__stpcpy_sse2_unaligned) redirected to 0x4842570 (__stpcpy_sse2_unaligned) +==5018== +==5018== HEAP SUMMARY: +==5018== in use at exit: 272 bytes in 1 blocks +==5018== total heap usage: 699 allocs, 698 frees, 1,894,753 bytes allocated +==5018== +==5018== Searching for pointers to 1 not-freed blocks +==5018== Checked 8,477,224 bytes +==5018== +==5018== Thread 1: +==5018== 272 bytes in 1 blocks are possibly lost in loss record 1 of 1 +==5018== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==5018== by 0x40149DA: allocate_dtv (dl-tls.c:286) +==5018== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) +==5018== by 0x4866322: allocate_stack (allocatestack.c:622) +==5018== by 0x4866322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) +==5018== by 0x10AA74: initTimer (aesdsocket.c:182) +==5018== by 0x10BA46: main (aesdsocket.c:615) +==5018== +==5018== LEAK SUMMARY: +==5018== definitely lost: 0 bytes in 0 blocks +==5018== indirectly lost: 0 bytes in 0 blocks +==5018== possibly lost: 272 bytes in 1 blocks +==5018== still reachable: 0 bytes in 0 blocks +==5018== suppressed: 0 bytes in 0 blocks +==5018== +==5018== ERROR SUMMARY: 17 errors from 1 contexts (suppressed: 0 from 0) +==5018== +==5018== 17 errors in context 1 of 1: +==5018== Thread 3: +==5018== Syscall param read(buf) points to unaddressable byte(s) +==5018== at 0x48703CC: __libc_read (read.c:26) +==5018== by 0x48703CC: read (read.c:24) +==5018== by 0x10B684: threadfunc (aesdsocket.c:481) +==5018== by 0x4865608: start_thread (pthread_create.c:477) +==5018== by 0x499F352: clone (clone.S:95) +==5018== Address 0x0 is not stack'd, malloc'd or (recently) free'd +==5018== +==5018== ERROR SUMMARY: 17 errors from 1 contexts (suppressed: 0 from 0) From 95acc41c9446e576441834f75b9512cbd4870b63 Mon Sep 17 00:00:00 2001 From: stamrakar Date: Mon, 14 Oct 2024 20:37:15 -0600 Subject: [PATCH 13/17] fixed seg faulting I think? --- server/aesdsocket.c | 30 ++-- server/valgrind-out.txt | 296 +++++++++++++++++++--------------------- 2 files changed, 153 insertions(+), 173 deletions(-) diff --git a/server/aesdsocket.c b/server/aesdsocket.c index 6733c50..efe0fb7 100644 --- a/server/aesdsocket.c +++ b/server/aesdsocket.c @@ -240,7 +240,7 @@ void *threadtimerfunc(void *args) ts.tv_sec += 10; // ts.tv_sec = 525; syslog(LOG_DEBUG, "Starting sleep at %ld\n", start); - printf("Starting sleep at %ld\n", start); + //printf("Starting sleep at %ld\n", start); nanosleep_rc = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, NULL); if (nanosleep_rc != 0) @@ -248,11 +248,11 @@ void *threadtimerfunc(void *args) printf("nanosleep failed.\n"); } - printf("nanosleep_rc is %d\n", nanosleep_rc); + //printf("nanosleep_rc is %d\n", nanosleep_rc); end = time(NULL); syslog(LOG_DEBUG, "Ending sleep at %ld, slept for %ld seconds", end, end-start); - printf("Ending sleep at %ld, slept for %ld seconds\n", end, end-start); + //printf("Ending sleep at %ld, slept for %ld seconds\n", end, end-start); now = time(NULL); @@ -465,7 +465,7 @@ void *threadfunc(void *args) perror("pthread mutex_lock failed"); } - int temp_total_size = total_size; + ssize_t remaining = total_size; rc = pthread_mutex_unlock(&size_val); if (rc != 0) @@ -477,8 +477,9 @@ void *threadfunc(void *args) int errnum9 = 0; - printf("total size here is %ld\n", total_size); - while ((bytes_read = read(recvfile_fd, send_my_buffer, temp_total_size)) > 0) { + //printf("total size here is %ld, \n", total_size); + syslog(LOG_DEBUG, "total size here is %ld", remaining); + while (remaining > 0 && (bytes_read = read(recvfile_fd, send_my_buffer, (remaining < BUF_SIZE) ? remaining : BUF_SIZE)) > 0) { syslog(LOG_DEBUG, "bytes_read is %ld", bytes_read); //syslog(LOG_DEBUG, "Sending: %s",send_my_buffer); if (send(thread_func_args->thread_info.afd, send_my_buffer, bytes_read, 0) != bytes_read) @@ -496,8 +497,9 @@ void *threadfunc(void *args) free(send_my_buffer); send_my_buffer = NULL; } + remaining -= bytes_read; } - + thread_func_args->thread_info.thread_complete_success = true; syslog(LOG_DEBUG, "About to exit thread ID = %lu", thread_func_args->thread_info.threadid); @@ -752,14 +754,14 @@ int main(int argc, char *argv[]) } } - if(SLIST_EMPTY(&head)) - { - printf("List now empty.\n"); - } - else { printf("List still populated.\n"); - } + // if(SLIST_EMPTY(&head)) + // { + // printf("List now empty.\n"); + // } + // else { printf("List still populated.\n"); + // } syslog(LOG_DEBUG, "Do I reach here?"); - printf("Do I reach here?\n"); + //printf("Do I reach here?\n"); closeAll(EXIT_SUCCESS); return 0; } \ No newline at end of file diff --git a/server/valgrind-out.txt b/server/valgrind-out.txt index 3c0daa9..598c7e5 100644 --- a/server/valgrind-out.txt +++ b/server/valgrind-out.txt @@ -1,159 +1,137 @@ -==5018== Memcheck, a memory error detector -==5018== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. -==5018== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info -==5018== Command: ./aesdsocket -==5018== Parent PID: 5017 -==5018== ---5018-- ---5018-- Valgrind options: ---5018-- --error-exitcode=1 ---5018-- --leak-check=full ---5018-- --show-leak-kinds=all ---5018-- --track-origins=yes ---5018-- --errors-for-leak-kinds=definite ---5018-- --verbose ---5018-- --log-file=valgrind-out.txt ---5018-- Contents of /proc/version: ---5018-- Linux version 5.15.0-122-generic (buildd@lcy02-amd64-106) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #132~20.04.1-Ubuntu SMP Fri Aug 30 15:50:07 UTC 2024 ---5018-- ---5018-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3 ---5018-- Page sizes: currently 4096, max supported 4096 ---5018-- Valgrind library directory: /usr/lib/x86_64-linux-gnu/valgrind ---5018-- Reading syms from /home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocket ---5018-- Reading syms from /usr/lib/x86_64-linux-gnu/ld-2.31.so ---5018-- Considering /usr/lib/debug/.build-id/db/0420f708b806cf03260aadb916c330049580b7.debug .. ---5018-- .. build-id is valid ---5018-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-linux ---5018-- object doesn't have a symbol table ---5018-- object doesn't have a dynamic symbol table ---5018-- Scheduler: using generic scheduler lock implementation. ---5018-- Reading suppressions file: /usr/lib/x86_64-linux-gnu/valgrind/default.supp -==5018== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-5018-by-stamrakar-on-??? -==5018== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-5018-by-stamrakar-on-??? -==5018== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-5018-by-stamrakar-on-??? -==5018== -==5018== TO CONTROL THIS PROCESS USING vgdb (which you probably -==5018== don't want to do, unless you know exactly what you're doing, -==5018== or are doing some strange experiment): -==5018== /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=5018 ...command... -==5018== -==5018== TO DEBUG THIS PROCESS USING GDB: start GDB like this -==5018== /path/to/gdb ./aesdsocket -==5018== and then give GDB the following command -==5018== target remote | /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=5018 -==5018== --pid is optional if only one valgrind process is running -==5018== ---5018-- REDIR: 0x4022e20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9ce2 (???) ---5018-- REDIR: 0x4022bf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c9cfc (???) ---5018-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_core-amd64-linux.so ---5018-- object doesn't have a symbol table ---5018-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so ---5018-- object doesn't have a symbol table -==5018== WARNING: new redirection conflicts with existing -- ignoring it ---5018-- old: 0x04022e20 (strlen ) R-> (0000.0) 0x580c9ce2 ??? ---5018-- new: 0x04022e20 (strlen ) R-> (2007.0) 0x0483f060 strlen ---5018-- REDIR: 0x401f600 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ffd0 (strcmp) ---5018-- REDIR: 0x4023380 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4843a20 (mempcpy) ---5018-- Reading syms from /usr/lib/x86_64-linux-gnu/libpthread-2.31.so ---5018-- Considering /usr/lib/debug/.build-id/9a/65bb469e45a1c6fbcffae5b82a2fd7a69eb479.debug .. ---5018-- .. build-id is valid ---5018-- Reading syms from /usr/lib/x86_64-linux-gnu/libc-2.31.so ---5018-- Considering /usr/lib/debug/.build-id/07/02430aef5fa3dda43986563e9ffcc47efbd75e.debug .. ---5018-- .. build-id is valid ---5018-- REDIR: 0x4920480 (libc.so.6:memmove) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x491f780 (libc.so.6:strncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x49207b0 (libc.so.6:strcasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x491f0a0 (libc.so.6:strcat) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x491f7e0 (libc.so.6:rindex) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x4921c50 (libc.so.6:rawmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x493cce0 (libc.so.6:wmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x493c820 (libc.so.6:wcscmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x49205e0 (libc.so.6:mempcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x4920410 (libc.so.6:bcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x491f710 (libc.so.6:strncmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x491f150 (libc.so.6:strcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x4920540 (libc.so.6:memset) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x493c7e0 (libc.so.6:wcschr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x491f670 (libc.so.6:strnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x491f230 (libc.so.6:strcspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x4920800 (libc.so.6:strncasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x491f1d0 (libc.so.6:strcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x4920950 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x493df50 (libc.so.6:wcsnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x493c860 (libc.so.6:wcscpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x491f820 (libc.so.6:strpbrk) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x491f100 (libc.so.6:index) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x491f630 (libc.so.6:strlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x4928bb0 (libc.so.6:memrchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x4920850 (libc.so.6:strcasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x49203d0 (libc.so.6:memchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x493c930 (libc.so.6:wcslen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x491fae0 (libc.so.6:strspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x4920750 (libc.so.6:stpncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x49206f0 (libc.so.6:stpcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x4921c90 (libc.so.6:strchrnul) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x49208a0 (libc.so.6:strncasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5018-- REDIR: 0x49318c0 (libc.so.6:__strrchr_sse2) redirected to 0x483ea70 (__strrchr_sse2) ---5018-- REDIR: 0x491a0e0 (libc.so.6:malloc) redirected to 0x483b780 (malloc) ---5018-- REDIR: 0x491bb10 (libc.so.6:calloc) redirected to 0x483dce0 (calloc) ---5018-- REDIR: 0x49316b0 (libc.so.6:__strchrnul_sse2) redirected to 0x4843540 (strchrnul) ---5018-- REDIR: 0x4931bc0 (libc.so.6:__strlen_sse2) redirected to 0x483efa0 (__strlen_sse2) ---5018-- REDIR: 0x491a6d0 (libc.so.6:free) redirected to 0x483c9d0 (free) ---5018-- REDIR: 0x493bad0 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4840100 (memcpy@GLIBC_2.2.5) ---5018-- REDIR: 0x491ffa0 (libc.so.6:__GI_strstr) redirected to 0x4843ca0 (__strstr_sse2) ---5018-- REDIR: 0x4a0d790 (libc.so.6:__memcmp_sse4_1) redirected to 0x4842150 (__memcmp_sse4_1) ---5018-- REDIR: 0x492a3b0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x483fed0 (strcmp) ---5018-- REDIR: 0x493bf00 (libc.so.6:__memset_sse2_unaligned) redirected to 0x48428e0 (memset) ---5018-- REDIR: 0x493bab0 (libc.so.6:__mempcpy_sse2_unaligned) redirected to 0x4843660 (mempcpy) ---5018-- REDIR: 0x491ae80 (libc.so.6:realloc) redirected to 0x483df30 (realloc) ---5018-- REDIR: 0x492bec0 (libc.so.6:__memchr_sse2) redirected to 0x4840050 (memchr) ---5018-- REDIR: 0x4931480 (libc.so.6:__strchr_sse2) redirected to 0x483eb90 (__strchr_sse2) ---5018-- REDIR: 0x4936b00 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x483f090 (strcpy) -==5018== Thread 3: -==5018== Syscall param read(buf) points to unaddressable byte(s) -==5018== at 0x48703CC: __libc_read (read.c:26) -==5018== by 0x48703CC: read (read.c:24) -==5018== by 0x10B684: threadfunc (aesdsocket.c:481) -==5018== by 0x4865608: start_thread (pthread_create.c:477) -==5018== by 0x499F352: clone (clone.S:95) -==5018== Address 0x0 is not stack'd, malloc'd or (recently) free'd -==5018== ---5018-- REDIR: 0x4938140 (libc.so.6:__stpcpy_sse2_unaligned) redirected to 0x4842570 (__stpcpy_sse2_unaligned) -==5018== -==5018== HEAP SUMMARY: -==5018== in use at exit: 272 bytes in 1 blocks -==5018== total heap usage: 699 allocs, 698 frees, 1,894,753 bytes allocated -==5018== -==5018== Searching for pointers to 1 not-freed blocks -==5018== Checked 8,477,224 bytes -==5018== -==5018== Thread 1: -==5018== 272 bytes in 1 blocks are possibly lost in loss record 1 of 1 -==5018== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==5018== by 0x40149DA: allocate_dtv (dl-tls.c:286) -==5018== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) -==5018== by 0x4866322: allocate_stack (allocatestack.c:622) -==5018== by 0x4866322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) -==5018== by 0x10AA74: initTimer (aesdsocket.c:182) -==5018== by 0x10BA46: main (aesdsocket.c:615) -==5018== -==5018== LEAK SUMMARY: -==5018== definitely lost: 0 bytes in 0 blocks -==5018== indirectly lost: 0 bytes in 0 blocks -==5018== possibly lost: 272 bytes in 1 blocks -==5018== still reachable: 0 bytes in 0 blocks -==5018== suppressed: 0 bytes in 0 blocks -==5018== -==5018== ERROR SUMMARY: 17 errors from 1 contexts (suppressed: 0 from 0) -==5018== -==5018== 17 errors in context 1 of 1: -==5018== Thread 3: -==5018== Syscall param read(buf) points to unaddressable byte(s) -==5018== at 0x48703CC: __libc_read (read.c:26) -==5018== by 0x48703CC: read (read.c:24) -==5018== by 0x10B684: threadfunc (aesdsocket.c:481) -==5018== by 0x4865608: start_thread (pthread_create.c:477) -==5018== by 0x499F352: clone (clone.S:95) -==5018== Address 0x0 is not stack'd, malloc'd or (recently) free'd -==5018== -==5018== ERROR SUMMARY: 17 errors from 1 contexts (suppressed: 0 from 0) +==8317== Memcheck, a memory error detector +==8317== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. +==8317== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info +==8317== Command: ./aesdsocket +==8317== Parent PID: 8314 +==8317== +--8317-- +--8317-- Valgrind options: +--8317-- --error-exitcode=1 +--8317-- --leak-check=full +--8317-- --show-leak-kinds=all +--8317-- --track-origins=yes +--8317-- --errors-for-leak-kinds=definite +--8317-- --verbose +--8317-- --log-file=valgrind-out.txt +--8317-- Contents of /proc/version: +--8317-- Linux version 5.15.0-122-generic (buildd@lcy02-amd64-106) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #132~20.04.1-Ubuntu SMP Fri Aug 30 15:50:07 UTC 2024 +--8317-- +--8317-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3 +--8317-- Page sizes: currently 4096, max supported 4096 +--8317-- Valgrind library directory: /usr/lib/x86_64-linux-gnu/valgrind +--8317-- Reading syms from /home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocket +--8317-- Reading syms from /usr/lib/x86_64-linux-gnu/ld-2.31.so +--8317-- Considering /usr/lib/debug/.build-id/db/0420f708b806cf03260aadb916c330049580b7.debug .. +--8317-- .. build-id is valid +--8317-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-linux +--8317-- object doesn't have a symbol table +--8317-- object doesn't have a dynamic symbol table +--8317-- Scheduler: using generic scheduler lock implementation. +--8317-- Reading suppressions file: /usr/lib/x86_64-linux-gnu/valgrind/default.supp +==8317== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-8317-by-stamrakar-on-??? +==8317== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-8317-by-stamrakar-on-??? +==8317== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-8317-by-stamrakar-on-??? +==8317== +==8317== TO CONTROL THIS PROCESS USING vgdb (which you probably +==8317== don't want to do, unless you know exactly what you're doing, +==8317== or are doing some strange experiment): +==8317== /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=8317 ...command... +==8317== +==8317== TO DEBUG THIS PROCESS USING GDB: start GDB like this +==8317== /path/to/gdb ./aesdsocket +==8317== and then give GDB the following command +==8317== target remote | /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=8317 +==8317== --pid is optional if only one valgrind process is running +==8317== +--8317-- REDIR: 0x4022e20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9ce2 (???) +--8317-- REDIR: 0x4022bf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c9cfc (???) +--8317-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_core-amd64-linux.so +--8317-- object doesn't have a symbol table +--8317-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so +--8317-- object doesn't have a symbol table +==8317== WARNING: new redirection conflicts with existing -- ignoring it +--8317-- old: 0x04022e20 (strlen ) R-> (0000.0) 0x580c9ce2 ??? +--8317-- new: 0x04022e20 (strlen ) R-> (2007.0) 0x0483f060 strlen +--8317-- REDIR: 0x401f600 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ffd0 (strcmp) +--8317-- REDIR: 0x4023380 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4843a20 (mempcpy) +--8317-- Reading syms from /usr/lib/x86_64-linux-gnu/libpthread-2.31.so +--8317-- Considering /usr/lib/debug/.build-id/9a/65bb469e45a1c6fbcffae5b82a2fd7a69eb479.debug .. +--8317-- .. build-id is valid +--8317-- Reading syms from /usr/lib/x86_64-linux-gnu/libc-2.31.so +--8317-- Considering /usr/lib/debug/.build-id/07/02430aef5fa3dda43986563e9ffcc47efbd75e.debug .. +--8317-- .. build-id is valid +--8317-- REDIR: 0x4920480 (libc.so.6:memmove) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x491f780 (libc.so.6:strncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x49207b0 (libc.so.6:strcasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x491f0a0 (libc.so.6:strcat) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x491f7e0 (libc.so.6:rindex) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x4921c50 (libc.so.6:rawmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x493cce0 (libc.so.6:wmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x493c820 (libc.so.6:wcscmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x49205e0 (libc.so.6:mempcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x4920410 (libc.so.6:bcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x491f710 (libc.so.6:strncmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x491f150 (libc.so.6:strcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x4920540 (libc.so.6:memset) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x493c7e0 (libc.so.6:wcschr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x491f670 (libc.so.6:strnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x491f230 (libc.so.6:strcspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x4920800 (libc.so.6:strncasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x491f1d0 (libc.so.6:strcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x4920950 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x493df50 (libc.so.6:wcsnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x493c860 (libc.so.6:wcscpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x491f820 (libc.so.6:strpbrk) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x491f100 (libc.so.6:index) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x491f630 (libc.so.6:strlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x4928bb0 (libc.so.6:memrchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x4920850 (libc.so.6:strcasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x49203d0 (libc.so.6:memchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x493c930 (libc.so.6:wcslen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x491fae0 (libc.so.6:strspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x4920750 (libc.so.6:stpncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x49206f0 (libc.so.6:stpcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x4921c90 (libc.so.6:strchrnul) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x49208a0 (libc.so.6:strncasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--8317-- REDIR: 0x49318c0 (libc.so.6:__strrchr_sse2) redirected to 0x483ea70 (__strrchr_sse2) +--8317-- REDIR: 0x491a0e0 (libc.so.6:malloc) redirected to 0x483b780 (malloc) +--8317-- REDIR: 0x491bb10 (libc.so.6:calloc) redirected to 0x483dce0 (calloc) +--8317-- REDIR: 0x49316b0 (libc.so.6:__strchrnul_sse2) redirected to 0x4843540 (strchrnul) +--8317-- REDIR: 0x4931bc0 (libc.so.6:__strlen_sse2) redirected to 0x483efa0 (__strlen_sse2) +--8317-- REDIR: 0x491a6d0 (libc.so.6:free) redirected to 0x483c9d0 (free) +--8317-- REDIR: 0x493bad0 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4840100 (memcpy@GLIBC_2.2.5) +--8317-- REDIR: 0x491ffa0 (libc.so.6:__GI_strstr) redirected to 0x4843ca0 (__strstr_sse2) +--8317-- REDIR: 0x4a0d790 (libc.so.6:__memcmp_sse4_1) redirected to 0x4842150 (__memcmp_sse4_1) +--8317-- REDIR: 0x492a3b0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x483fed0 (strcmp) +--8317-- REDIR: 0x493bab0 (libc.so.6:__mempcpy_sse2_unaligned) redirected to 0x4843660 (mempcpy) +--8317-- REDIR: 0x491ae80 (libc.so.6:realloc) redirected to 0x483df30 (realloc) +--8317-- REDIR: 0x493bf00 (libc.so.6:__memset_sse2_unaligned) redirected to 0x48428e0 (memset) +--8317-- REDIR: 0x492bec0 (libc.so.6:__memchr_sse2) redirected to 0x4840050 (memchr) +--8317-- REDIR: 0x4931480 (libc.so.6:__strchr_sse2) redirected to 0x483eb90 (__strchr_sse2) +--8317-- REDIR: 0x4936b00 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x483f090 (strcpy) +--8317-- REDIR: 0x4938140 (libc.so.6:__stpcpy_sse2_unaligned) redirected to 0x4842570 (__stpcpy_sse2_unaligned) +==8317== +==8317== HEAP SUMMARY: +==8317== in use at exit: 272 bytes in 1 blocks +==8317== total heap usage: 750 allocs, 749 frees, 2,043,732 bytes allocated +==8317== +==8317== Searching for pointers to 1 not-freed blocks +==8317== Checked 8,477,224 bytes +==8317== +==8317== 272 bytes in 1 blocks are possibly lost in loss record 1 of 1 +==8317== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==8317== by 0x40149DA: allocate_dtv (dl-tls.c:286) +==8317== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) +==8317== by 0x4866322: allocate_stack (allocatestack.c:622) +==8317== by 0x4866322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) +==8317== by 0x10AA74: initTimer (aesdsocket.c:182) +==8317== by 0x10BA07: main (aesdsocket.c:617) +==8317== +==8317== LEAK SUMMARY: +==8317== definitely lost: 0 bytes in 0 blocks +==8317== indirectly lost: 0 bytes in 0 blocks +==8317== possibly lost: 272 bytes in 1 blocks +==8317== still reachable: 0 bytes in 0 blocks +==8317== suppressed: 0 bytes in 0 blocks +==8317== +==8317== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) From 6edbe79d58e6dc37f4425efbb908b7258c30d744 Mon Sep 17 00:00:00 2001 From: stamrakar Date: Tue, 15 Oct 2024 09:54:45 -0600 Subject: [PATCH 14/17] fixed Makefile A6 --- server/Makefile | 40 ++---- server/aesdsocket.c | 9 +- server/valgrind-out.txt | 296 +++++++++++++++++++++------------------- 3 files changed, 174 insertions(+), 171 deletions(-) diff --git a/server/Makefile b/server/Makefile index c4d91ae..7e3b2f3 100644 --- a/server/Makefile +++ b/server/Makefile @@ -5,36 +5,24 @@ # https://math.uaa.alaska.edu/~ssiewert/a335_code/EXAMPLES/POSIX/ # Date: 10/06/2024 -INCLUDE_FLAGS= -Wall -Werror -LIB_DIRS = +CC ?= $(CROSS_COMPILE)gcc +CFLAGS ?= -g -Wall -Werror +LDFLAGS ?= -pthread -lrt +TARGET ?= aesdsocket +CFILES ?= aesdsocket.c +OBJS = $(CFILES:.c=.o) -CC = gcc +all: $(TARGET) +default: all +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ -CDEFS= -CFLAGS= -O0 -g $(INCLUDE_FLAGS) $(CDEFS) -LIBS= - -PRODUCT=aesdsocket - -HFILES= -CFILES=aesdsocket.c - -SRCS= ${HFILES} ${CFILES} -OBJS= ${CFILES:.c=.o} - -all: ${PRODUCT} +aesdsocket: $(OBJS) + $(CC) $(OBJS) -o $@ $(LDFLAGS) clean: - -rm -f *.o *.d - -rm -f aesdsocket - -aesdsocket: ${OBJS} - $(CROSS_COMPILE)$(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBS) -pthread -lrt - -depend: - -.c.o: - $(CROSS_COMPILE)$(CC) $(CFLAGS) -c $< \ No newline at end of file + rm -f *.o *.d + rm -f aesdsocket \ No newline at end of file diff --git a/server/aesdsocket.c b/server/aesdsocket.c index efe0fb7..10f46c5 100644 --- a/server/aesdsocket.c +++ b/server/aesdsocket.c @@ -479,7 +479,7 @@ void *threadfunc(void *args) //printf("total size here is %ld, \n", total_size); syslog(LOG_DEBUG, "total size here is %ld", remaining); - while (remaining > 0 && (bytes_read = read(recvfile_fd, send_my_buffer, (remaining < BUF_SIZE) ? remaining : BUF_SIZE)) > 0) { + while ((bytes_read = read(recvfile_fd, send_my_buffer, remaining)) > 0) { syslog(LOG_DEBUG, "bytes_read is %ld", bytes_read); //syslog(LOG_DEBUG, "Sending: %s",send_my_buffer); if (send(thread_func_args->thread_info.afd, send_my_buffer, bytes_read, 0) != bytes_read) @@ -497,7 +497,6 @@ void *threadfunc(void *args) free(send_my_buffer); send_my_buffer = NULL; } - remaining -= bytes_read; } @@ -754,12 +753,6 @@ int main(int argc, char *argv[]) } } - // if(SLIST_EMPTY(&head)) - // { - // printf("List now empty.\n"); - // } - // else { printf("List still populated.\n"); - // } syslog(LOG_DEBUG, "Do I reach here?"); //printf("Do I reach here?\n"); closeAll(EXIT_SUCCESS); diff --git a/server/valgrind-out.txt b/server/valgrind-out.txt index 598c7e5..c0cb9e0 100644 --- a/server/valgrind-out.txt +++ b/server/valgrind-out.txt @@ -1,137 +1,159 @@ -==8317== Memcheck, a memory error detector -==8317== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. -==8317== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info -==8317== Command: ./aesdsocket -==8317== Parent PID: 8314 -==8317== ---8317-- ---8317-- Valgrind options: ---8317-- --error-exitcode=1 ---8317-- --leak-check=full ---8317-- --show-leak-kinds=all ---8317-- --track-origins=yes ---8317-- --errors-for-leak-kinds=definite ---8317-- --verbose ---8317-- --log-file=valgrind-out.txt ---8317-- Contents of /proc/version: ---8317-- Linux version 5.15.0-122-generic (buildd@lcy02-amd64-106) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #132~20.04.1-Ubuntu SMP Fri Aug 30 15:50:07 UTC 2024 ---8317-- ---8317-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3 ---8317-- Page sizes: currently 4096, max supported 4096 ---8317-- Valgrind library directory: /usr/lib/x86_64-linux-gnu/valgrind ---8317-- Reading syms from /home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocket ---8317-- Reading syms from /usr/lib/x86_64-linux-gnu/ld-2.31.so ---8317-- Considering /usr/lib/debug/.build-id/db/0420f708b806cf03260aadb916c330049580b7.debug .. ---8317-- .. build-id is valid ---8317-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-linux ---8317-- object doesn't have a symbol table ---8317-- object doesn't have a dynamic symbol table ---8317-- Scheduler: using generic scheduler lock implementation. ---8317-- Reading suppressions file: /usr/lib/x86_64-linux-gnu/valgrind/default.supp -==8317== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-8317-by-stamrakar-on-??? -==8317== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-8317-by-stamrakar-on-??? -==8317== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-8317-by-stamrakar-on-??? -==8317== -==8317== TO CONTROL THIS PROCESS USING vgdb (which you probably -==8317== don't want to do, unless you know exactly what you're doing, -==8317== or are doing some strange experiment): -==8317== /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=8317 ...command... -==8317== -==8317== TO DEBUG THIS PROCESS USING GDB: start GDB like this -==8317== /path/to/gdb ./aesdsocket -==8317== and then give GDB the following command -==8317== target remote | /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=8317 -==8317== --pid is optional if only one valgrind process is running -==8317== ---8317-- REDIR: 0x4022e20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9ce2 (???) ---8317-- REDIR: 0x4022bf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c9cfc (???) ---8317-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_core-amd64-linux.so ---8317-- object doesn't have a symbol table ---8317-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so ---8317-- object doesn't have a symbol table -==8317== WARNING: new redirection conflicts with existing -- ignoring it ---8317-- old: 0x04022e20 (strlen ) R-> (0000.0) 0x580c9ce2 ??? ---8317-- new: 0x04022e20 (strlen ) R-> (2007.0) 0x0483f060 strlen ---8317-- REDIR: 0x401f600 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ffd0 (strcmp) ---8317-- REDIR: 0x4023380 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4843a20 (mempcpy) ---8317-- Reading syms from /usr/lib/x86_64-linux-gnu/libpthread-2.31.so ---8317-- Considering /usr/lib/debug/.build-id/9a/65bb469e45a1c6fbcffae5b82a2fd7a69eb479.debug .. ---8317-- .. build-id is valid ---8317-- Reading syms from /usr/lib/x86_64-linux-gnu/libc-2.31.so ---8317-- Considering /usr/lib/debug/.build-id/07/02430aef5fa3dda43986563e9ffcc47efbd75e.debug .. ---8317-- .. build-id is valid ---8317-- REDIR: 0x4920480 (libc.so.6:memmove) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x491f780 (libc.so.6:strncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x49207b0 (libc.so.6:strcasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x491f0a0 (libc.so.6:strcat) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x491f7e0 (libc.so.6:rindex) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x4921c50 (libc.so.6:rawmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x493cce0 (libc.so.6:wmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x493c820 (libc.so.6:wcscmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x49205e0 (libc.so.6:mempcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x4920410 (libc.so.6:bcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x491f710 (libc.so.6:strncmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x491f150 (libc.so.6:strcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x4920540 (libc.so.6:memset) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x493c7e0 (libc.so.6:wcschr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x491f670 (libc.so.6:strnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x491f230 (libc.so.6:strcspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x4920800 (libc.so.6:strncasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x491f1d0 (libc.so.6:strcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x4920950 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x493df50 (libc.so.6:wcsnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x493c860 (libc.so.6:wcscpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x491f820 (libc.so.6:strpbrk) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x491f100 (libc.so.6:index) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x491f630 (libc.so.6:strlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x4928bb0 (libc.so.6:memrchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x4920850 (libc.so.6:strcasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x49203d0 (libc.so.6:memchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x493c930 (libc.so.6:wcslen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x491fae0 (libc.so.6:strspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x4920750 (libc.so.6:stpncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x49206f0 (libc.so.6:stpcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x4921c90 (libc.so.6:strchrnul) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x49208a0 (libc.so.6:strncasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---8317-- REDIR: 0x49318c0 (libc.so.6:__strrchr_sse2) redirected to 0x483ea70 (__strrchr_sse2) ---8317-- REDIR: 0x491a0e0 (libc.so.6:malloc) redirected to 0x483b780 (malloc) ---8317-- REDIR: 0x491bb10 (libc.so.6:calloc) redirected to 0x483dce0 (calloc) ---8317-- REDIR: 0x49316b0 (libc.so.6:__strchrnul_sse2) redirected to 0x4843540 (strchrnul) ---8317-- REDIR: 0x4931bc0 (libc.so.6:__strlen_sse2) redirected to 0x483efa0 (__strlen_sse2) ---8317-- REDIR: 0x491a6d0 (libc.so.6:free) redirected to 0x483c9d0 (free) ---8317-- REDIR: 0x493bad0 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4840100 (memcpy@GLIBC_2.2.5) ---8317-- REDIR: 0x491ffa0 (libc.so.6:__GI_strstr) redirected to 0x4843ca0 (__strstr_sse2) ---8317-- REDIR: 0x4a0d790 (libc.so.6:__memcmp_sse4_1) redirected to 0x4842150 (__memcmp_sse4_1) ---8317-- REDIR: 0x492a3b0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x483fed0 (strcmp) ---8317-- REDIR: 0x493bab0 (libc.so.6:__mempcpy_sse2_unaligned) redirected to 0x4843660 (mempcpy) ---8317-- REDIR: 0x491ae80 (libc.so.6:realloc) redirected to 0x483df30 (realloc) ---8317-- REDIR: 0x493bf00 (libc.so.6:__memset_sse2_unaligned) redirected to 0x48428e0 (memset) ---8317-- REDIR: 0x492bec0 (libc.so.6:__memchr_sse2) redirected to 0x4840050 (memchr) ---8317-- REDIR: 0x4931480 (libc.so.6:__strchr_sse2) redirected to 0x483eb90 (__strchr_sse2) ---8317-- REDIR: 0x4936b00 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x483f090 (strcpy) ---8317-- REDIR: 0x4938140 (libc.so.6:__stpcpy_sse2_unaligned) redirected to 0x4842570 (__stpcpy_sse2_unaligned) -==8317== -==8317== HEAP SUMMARY: -==8317== in use at exit: 272 bytes in 1 blocks -==8317== total heap usage: 750 allocs, 749 frees, 2,043,732 bytes allocated -==8317== -==8317== Searching for pointers to 1 not-freed blocks -==8317== Checked 8,477,224 bytes -==8317== -==8317== 272 bytes in 1 blocks are possibly lost in loss record 1 of 1 -==8317== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==8317== by 0x40149DA: allocate_dtv (dl-tls.c:286) -==8317== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) -==8317== by 0x4866322: allocate_stack (allocatestack.c:622) -==8317== by 0x4866322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) -==8317== by 0x10AA74: initTimer (aesdsocket.c:182) -==8317== by 0x10BA07: main (aesdsocket.c:617) -==8317== -==8317== LEAK SUMMARY: -==8317== definitely lost: 0 bytes in 0 blocks -==8317== indirectly lost: 0 bytes in 0 blocks -==8317== possibly lost: 272 bytes in 1 blocks -==8317== still reachable: 0 bytes in 0 blocks -==8317== suppressed: 0 bytes in 0 blocks -==8317== -==8317== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) +==9742== Memcheck, a memory error detector +==9742== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. +==9742== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info +==9742== Command: ./aesdsocket +==9742== Parent PID: 9740 +==9742== +--9742-- +--9742-- Valgrind options: +--9742-- --error-exitcode=1 +--9742-- --leak-check=full +--9742-- --show-leak-kinds=all +--9742-- --track-origins=yes +--9742-- --errors-for-leak-kinds=definite +--9742-- --verbose +--9742-- --log-file=valgrind-out.txt +--9742-- Contents of /proc/version: +--9742-- Linux version 5.15.0-122-generic (buildd@lcy02-amd64-106) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #132~20.04.1-Ubuntu SMP Fri Aug 30 15:50:07 UTC 2024 +--9742-- +--9742-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3 +--9742-- Page sizes: currently 4096, max supported 4096 +--9742-- Valgrind library directory: /usr/lib/x86_64-linux-gnu/valgrind +--9742-- Reading syms from /home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocket +--9742-- Reading syms from /usr/lib/x86_64-linux-gnu/ld-2.31.so +--9742-- Considering /usr/lib/debug/.build-id/db/0420f708b806cf03260aadb916c330049580b7.debug .. +--9742-- .. build-id is valid +--9742-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-linux +--9742-- object doesn't have a symbol table +--9742-- object doesn't have a dynamic symbol table +--9742-- Scheduler: using generic scheduler lock implementation. +--9742-- Reading suppressions file: /usr/lib/x86_64-linux-gnu/valgrind/default.supp +==9742== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-9742-by-stamrakar-on-??? +==9742== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-9742-by-stamrakar-on-??? +==9742== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-9742-by-stamrakar-on-??? +==9742== +==9742== TO CONTROL THIS PROCESS USING vgdb (which you probably +==9742== don't want to do, unless you know exactly what you're doing, +==9742== or are doing some strange experiment): +==9742== /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=9742 ...command... +==9742== +==9742== TO DEBUG THIS PROCESS USING GDB: start GDB like this +==9742== /path/to/gdb ./aesdsocket +==9742== and then give GDB the following command +==9742== target remote | /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=9742 +==9742== --pid is optional if only one valgrind process is running +==9742== +--9742-- REDIR: 0x4022e20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9ce2 (???) +--9742-- REDIR: 0x4022bf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c9cfc (???) +--9742-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_core-amd64-linux.so +--9742-- object doesn't have a symbol table +--9742-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so +--9742-- object doesn't have a symbol table +==9742== WARNING: new redirection conflicts with existing -- ignoring it +--9742-- old: 0x04022e20 (strlen ) R-> (0000.0) 0x580c9ce2 ??? +--9742-- new: 0x04022e20 (strlen ) R-> (2007.0) 0x0483f060 strlen +--9742-- REDIR: 0x401f600 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ffd0 (strcmp) +--9742-- REDIR: 0x4023380 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4843a20 (mempcpy) +--9742-- Reading syms from /usr/lib/x86_64-linux-gnu/libpthread-2.31.so +--9742-- Considering /usr/lib/debug/.build-id/9a/65bb469e45a1c6fbcffae5b82a2fd7a69eb479.debug .. +--9742-- .. build-id is valid +--9742-- Reading syms from /usr/lib/x86_64-linux-gnu/libc-2.31.so +--9742-- Considering /usr/lib/debug/.build-id/07/02430aef5fa3dda43986563e9ffcc47efbd75e.debug .. +--9742-- .. build-id is valid +--9742-- REDIR: 0x4920480 (libc.so.6:memmove) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x491f780 (libc.so.6:strncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x49207b0 (libc.so.6:strcasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x491f0a0 (libc.so.6:strcat) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x491f7e0 (libc.so.6:rindex) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x4921c50 (libc.so.6:rawmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x493cce0 (libc.so.6:wmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x493c820 (libc.so.6:wcscmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x49205e0 (libc.so.6:mempcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x4920410 (libc.so.6:bcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x491f710 (libc.so.6:strncmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x491f150 (libc.so.6:strcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x4920540 (libc.so.6:memset) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x493c7e0 (libc.so.6:wcschr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x491f670 (libc.so.6:strnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x491f230 (libc.so.6:strcspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x4920800 (libc.so.6:strncasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x491f1d0 (libc.so.6:strcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x4920950 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x493df50 (libc.so.6:wcsnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x493c860 (libc.so.6:wcscpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x491f820 (libc.so.6:strpbrk) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x491f100 (libc.so.6:index) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x491f630 (libc.so.6:strlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x4928bb0 (libc.so.6:memrchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x4920850 (libc.so.6:strcasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x49203d0 (libc.so.6:memchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x493c930 (libc.so.6:wcslen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x491fae0 (libc.so.6:strspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x4920750 (libc.so.6:stpncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x49206f0 (libc.so.6:stpcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x4921c90 (libc.so.6:strchrnul) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x49208a0 (libc.so.6:strncasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--9742-- REDIR: 0x49318c0 (libc.so.6:__strrchr_sse2) redirected to 0x483ea70 (__strrchr_sse2) +--9742-- REDIR: 0x491a0e0 (libc.so.6:malloc) redirected to 0x483b780 (malloc) +--9742-- REDIR: 0x491bb10 (libc.so.6:calloc) redirected to 0x483dce0 (calloc) +--9742-- REDIR: 0x49316b0 (libc.so.6:__strchrnul_sse2) redirected to 0x4843540 (strchrnul) +--9742-- REDIR: 0x4931bc0 (libc.so.6:__strlen_sse2) redirected to 0x483efa0 (__strlen_sse2) +--9742-- REDIR: 0x491a6d0 (libc.so.6:free) redirected to 0x483c9d0 (free) +--9742-- REDIR: 0x493bad0 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4840100 (memcpy@GLIBC_2.2.5) +--9742-- REDIR: 0x491ffa0 (libc.so.6:__GI_strstr) redirected to 0x4843ca0 (__strstr_sse2) +--9742-- REDIR: 0x4a0d790 (libc.so.6:__memcmp_sse4_1) redirected to 0x4842150 (__memcmp_sse4_1) +--9742-- REDIR: 0x492a3b0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x483fed0 (strcmp) +--9742-- REDIR: 0x493bab0 (libc.so.6:__mempcpy_sse2_unaligned) redirected to 0x4843660 (mempcpy) +--9742-- REDIR: 0x491ae80 (libc.so.6:realloc) redirected to 0x483df30 (realloc) +--9742-- REDIR: 0x493bf00 (libc.so.6:__memset_sse2_unaligned) redirected to 0x48428e0 (memset) +--9742-- REDIR: 0x492bec0 (libc.so.6:__memchr_sse2) redirected to 0x4840050 (memchr) +--9742-- REDIR: 0x4931480 (libc.so.6:__strchr_sse2) redirected to 0x483eb90 (__strchr_sse2) +--9742-- REDIR: 0x4936b00 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x483f090 (strcpy) +==9742== Thread 3: +==9742== Syscall param read(buf) points to unaddressable byte(s) +==9742== at 0x48703CC: __libc_read (read.c:26) +==9742== by 0x48703CC: read (read.c:24) +==9742== by 0x10B625: threadfunc (aesdsocket.c:482) +==9742== by 0x4865608: start_thread (pthread_create.c:477) +==9742== by 0x499F352: clone (clone.S:95) +==9742== Address 0x0 is not stack'd, malloc'd or (recently) free'd +==9742== +--9742-- REDIR: 0x4938140 (libc.so.6:__stpcpy_sse2_unaligned) redirected to 0x4842570 (__stpcpy_sse2_unaligned) +==9742== +==9742== HEAP SUMMARY: +==9742== in use at exit: 272 bytes in 1 blocks +==9742== total heap usage: 750 allocs, 749 frees, 2,043,732 bytes allocated +==9742== +==9742== Searching for pointers to 1 not-freed blocks +==9742== Checked 8,477,224 bytes +==9742== +==9742== Thread 1: +==9742== 272 bytes in 1 blocks are possibly lost in loss record 1 of 1 +==9742== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==9742== by 0x40149DA: allocate_dtv (dl-tls.c:286) +==9742== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) +==9742== by 0x4866322: allocate_stack (allocatestack.c:622) +==9742== by 0x4866322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) +==9742== by 0x10AA74: initTimer (aesdsocket.c:182) +==9742== by 0x10B9E7: main (aesdsocket.c:616) +==9742== +==9742== LEAK SUMMARY: +==9742== definitely lost: 0 bytes in 0 blocks +==9742== indirectly lost: 0 bytes in 0 blocks +==9742== possibly lost: 272 bytes in 1 blocks +==9742== still reachable: 0 bytes in 0 blocks +==9742== suppressed: 0 bytes in 0 blocks +==9742== +==9742== ERROR SUMMARY: 17 errors from 1 contexts (suppressed: 0 from 0) +==9742== +==9742== 17 errors in context 1 of 1: +==9742== Thread 3: +==9742== Syscall param read(buf) points to unaddressable byte(s) +==9742== at 0x48703CC: __libc_read (read.c:26) +==9742== by 0x48703CC: read (read.c:24) +==9742== by 0x10B625: threadfunc (aesdsocket.c:482) +==9742== by 0x4865608: start_thread (pthread_create.c:477) +==9742== by 0x499F352: clone (clone.S:95) +==9742== Address 0x0 is not stack'd, malloc'd or (recently) free'd +==9742== +==9742== ERROR SUMMARY: 17 errors from 1 contexts (suppressed: 0 from 0) From 7afa43f7eafbe2b736db91268c3950b25048f8ae Mon Sep 17 00:00:00 2001 From: stamrakar Date: Tue, 15 Oct 2024 18:21:27 -0600 Subject: [PATCH 15/17] Valgrind 17 errors fixed --- server/aesdsocket.c | 25 ++-- server/valgrind-out.txt | 296 +++++++++++++++++++--------------------- 2 files changed, 151 insertions(+), 170 deletions(-) diff --git a/server/aesdsocket.c b/server/aesdsocket.c index 10f46c5..e2cce11 100644 --- a/server/aesdsocket.c +++ b/server/aesdsocket.c @@ -359,12 +359,14 @@ void *threadfunc(void *args) else { - my_buffer = realloc(my_buffer, supplementSize+BUF_SIZE); - if(my_buffer == NULL) + char* temp_buffer = realloc(my_buffer, supplementSize+BUF_SIZE); + if(temp_buffer == NULL) { syslog(LOG_ERR, "Failed to realloc."); + free(my_buffer); // free previously allocated buffer closeAll(EXIT_FAILURE); } + my_buffer=temp_buffer; supplementSize += BUF_SIZE; memset(my_buffer+supplementBuf, 0 , supplementSize-supplementBuf); } @@ -428,12 +430,7 @@ void *threadfunc(void *args) my_buffer = NULL; - send_my_buffer = (char *) malloc(BUF_SIZE); - if (send_my_buffer == NULL) - { - syslog(LOG_ERR, "Failed to malloc sending buffer."); - closeAll(EXIT_FAILURE); - } + rc = pthread_mutex_lock(&writeSocket); @@ -474,6 +471,12 @@ void *threadfunc(void *args) perror("pthread mutex_lock failed"); } + send_my_buffer = (char *) malloc(BUF_SIZE); + if (send_my_buffer == NULL) + { + syslog(LOG_ERR, "Failed to malloc sending buffer."); + closeAll(EXIT_FAILURE); + } int errnum9 = 0; @@ -494,12 +497,12 @@ void *threadfunc(void *args) else { syslog(LOG_DEBUG, "send passed"); - free(send_my_buffer); - send_my_buffer = NULL; } } - + + free(send_my_buffer); + send_my_buffer = NULL; thread_func_args->thread_info.thread_complete_success = true; syslog(LOG_DEBUG, "About to exit thread ID = %lu", thread_func_args->thread_info.threadid); syslog(LOG_DEBUG, "_________________________________________________________"); diff --git a/server/valgrind-out.txt b/server/valgrind-out.txt index c0cb9e0..0ce85a3 100644 --- a/server/valgrind-out.txt +++ b/server/valgrind-out.txt @@ -1,159 +1,137 @@ -==9742== Memcheck, a memory error detector -==9742== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. -==9742== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info -==9742== Command: ./aesdsocket -==9742== Parent PID: 9740 -==9742== ---9742-- ---9742-- Valgrind options: ---9742-- --error-exitcode=1 ---9742-- --leak-check=full ---9742-- --show-leak-kinds=all ---9742-- --track-origins=yes ---9742-- --errors-for-leak-kinds=definite ---9742-- --verbose ---9742-- --log-file=valgrind-out.txt ---9742-- Contents of /proc/version: ---9742-- Linux version 5.15.0-122-generic (buildd@lcy02-amd64-106) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #132~20.04.1-Ubuntu SMP Fri Aug 30 15:50:07 UTC 2024 ---9742-- ---9742-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3 ---9742-- Page sizes: currently 4096, max supported 4096 ---9742-- Valgrind library directory: /usr/lib/x86_64-linux-gnu/valgrind ---9742-- Reading syms from /home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocket ---9742-- Reading syms from /usr/lib/x86_64-linux-gnu/ld-2.31.so ---9742-- Considering /usr/lib/debug/.build-id/db/0420f708b806cf03260aadb916c330049580b7.debug .. ---9742-- .. build-id is valid ---9742-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-linux ---9742-- object doesn't have a symbol table ---9742-- object doesn't have a dynamic symbol table ---9742-- Scheduler: using generic scheduler lock implementation. ---9742-- Reading suppressions file: /usr/lib/x86_64-linux-gnu/valgrind/default.supp -==9742== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-9742-by-stamrakar-on-??? -==9742== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-9742-by-stamrakar-on-??? -==9742== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-9742-by-stamrakar-on-??? -==9742== -==9742== TO CONTROL THIS PROCESS USING vgdb (which you probably -==9742== don't want to do, unless you know exactly what you're doing, -==9742== or are doing some strange experiment): -==9742== /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=9742 ...command... -==9742== -==9742== TO DEBUG THIS PROCESS USING GDB: start GDB like this -==9742== /path/to/gdb ./aesdsocket -==9742== and then give GDB the following command -==9742== target remote | /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=9742 -==9742== --pid is optional if only one valgrind process is running -==9742== ---9742-- REDIR: 0x4022e20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9ce2 (???) ---9742-- REDIR: 0x4022bf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c9cfc (???) ---9742-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_core-amd64-linux.so ---9742-- object doesn't have a symbol table ---9742-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so ---9742-- object doesn't have a symbol table -==9742== WARNING: new redirection conflicts with existing -- ignoring it ---9742-- old: 0x04022e20 (strlen ) R-> (0000.0) 0x580c9ce2 ??? ---9742-- new: 0x04022e20 (strlen ) R-> (2007.0) 0x0483f060 strlen ---9742-- REDIR: 0x401f600 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ffd0 (strcmp) ---9742-- REDIR: 0x4023380 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4843a20 (mempcpy) ---9742-- Reading syms from /usr/lib/x86_64-linux-gnu/libpthread-2.31.so ---9742-- Considering /usr/lib/debug/.build-id/9a/65bb469e45a1c6fbcffae5b82a2fd7a69eb479.debug .. ---9742-- .. build-id is valid ---9742-- Reading syms from /usr/lib/x86_64-linux-gnu/libc-2.31.so ---9742-- Considering /usr/lib/debug/.build-id/07/02430aef5fa3dda43986563e9ffcc47efbd75e.debug .. ---9742-- .. build-id is valid ---9742-- REDIR: 0x4920480 (libc.so.6:memmove) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x491f780 (libc.so.6:strncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x49207b0 (libc.so.6:strcasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x491f0a0 (libc.so.6:strcat) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x491f7e0 (libc.so.6:rindex) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x4921c50 (libc.so.6:rawmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x493cce0 (libc.so.6:wmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x493c820 (libc.so.6:wcscmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x49205e0 (libc.so.6:mempcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x4920410 (libc.so.6:bcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x491f710 (libc.so.6:strncmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x491f150 (libc.so.6:strcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x4920540 (libc.so.6:memset) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x493c7e0 (libc.so.6:wcschr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x491f670 (libc.so.6:strnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x491f230 (libc.so.6:strcspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x4920800 (libc.so.6:strncasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x491f1d0 (libc.so.6:strcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x4920950 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x493df50 (libc.so.6:wcsnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x493c860 (libc.so.6:wcscpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x491f820 (libc.so.6:strpbrk) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x491f100 (libc.so.6:index) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x491f630 (libc.so.6:strlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x4928bb0 (libc.so.6:memrchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x4920850 (libc.so.6:strcasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x49203d0 (libc.so.6:memchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x493c930 (libc.so.6:wcslen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x491fae0 (libc.so.6:strspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x4920750 (libc.so.6:stpncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x49206f0 (libc.so.6:stpcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x4921c90 (libc.so.6:strchrnul) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x49208a0 (libc.so.6:strncasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---9742-- REDIR: 0x49318c0 (libc.so.6:__strrchr_sse2) redirected to 0x483ea70 (__strrchr_sse2) ---9742-- REDIR: 0x491a0e0 (libc.so.6:malloc) redirected to 0x483b780 (malloc) ---9742-- REDIR: 0x491bb10 (libc.so.6:calloc) redirected to 0x483dce0 (calloc) ---9742-- REDIR: 0x49316b0 (libc.so.6:__strchrnul_sse2) redirected to 0x4843540 (strchrnul) ---9742-- REDIR: 0x4931bc0 (libc.so.6:__strlen_sse2) redirected to 0x483efa0 (__strlen_sse2) ---9742-- REDIR: 0x491a6d0 (libc.so.6:free) redirected to 0x483c9d0 (free) ---9742-- REDIR: 0x493bad0 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4840100 (memcpy@GLIBC_2.2.5) ---9742-- REDIR: 0x491ffa0 (libc.so.6:__GI_strstr) redirected to 0x4843ca0 (__strstr_sse2) ---9742-- REDIR: 0x4a0d790 (libc.so.6:__memcmp_sse4_1) redirected to 0x4842150 (__memcmp_sse4_1) ---9742-- REDIR: 0x492a3b0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x483fed0 (strcmp) ---9742-- REDIR: 0x493bab0 (libc.so.6:__mempcpy_sse2_unaligned) redirected to 0x4843660 (mempcpy) ---9742-- REDIR: 0x491ae80 (libc.so.6:realloc) redirected to 0x483df30 (realloc) ---9742-- REDIR: 0x493bf00 (libc.so.6:__memset_sse2_unaligned) redirected to 0x48428e0 (memset) ---9742-- REDIR: 0x492bec0 (libc.so.6:__memchr_sse2) redirected to 0x4840050 (memchr) ---9742-- REDIR: 0x4931480 (libc.so.6:__strchr_sse2) redirected to 0x483eb90 (__strchr_sse2) ---9742-- REDIR: 0x4936b00 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x483f090 (strcpy) -==9742== Thread 3: -==9742== Syscall param read(buf) points to unaddressable byte(s) -==9742== at 0x48703CC: __libc_read (read.c:26) -==9742== by 0x48703CC: read (read.c:24) -==9742== by 0x10B625: threadfunc (aesdsocket.c:482) -==9742== by 0x4865608: start_thread (pthread_create.c:477) -==9742== by 0x499F352: clone (clone.S:95) -==9742== Address 0x0 is not stack'd, malloc'd or (recently) free'd -==9742== ---9742-- REDIR: 0x4938140 (libc.so.6:__stpcpy_sse2_unaligned) redirected to 0x4842570 (__stpcpy_sse2_unaligned) -==9742== -==9742== HEAP SUMMARY: -==9742== in use at exit: 272 bytes in 1 blocks -==9742== total heap usage: 750 allocs, 749 frees, 2,043,732 bytes allocated -==9742== -==9742== Searching for pointers to 1 not-freed blocks -==9742== Checked 8,477,224 bytes -==9742== -==9742== Thread 1: -==9742== 272 bytes in 1 blocks are possibly lost in loss record 1 of 1 -==9742== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==9742== by 0x40149DA: allocate_dtv (dl-tls.c:286) -==9742== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) -==9742== by 0x4866322: allocate_stack (allocatestack.c:622) -==9742== by 0x4866322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) -==9742== by 0x10AA74: initTimer (aesdsocket.c:182) -==9742== by 0x10B9E7: main (aesdsocket.c:616) -==9742== -==9742== LEAK SUMMARY: -==9742== definitely lost: 0 bytes in 0 blocks -==9742== indirectly lost: 0 bytes in 0 blocks -==9742== possibly lost: 272 bytes in 1 blocks -==9742== still reachable: 0 bytes in 0 blocks -==9742== suppressed: 0 bytes in 0 blocks -==9742== -==9742== ERROR SUMMARY: 17 errors from 1 contexts (suppressed: 0 from 0) -==9742== -==9742== 17 errors in context 1 of 1: -==9742== Thread 3: -==9742== Syscall param read(buf) points to unaddressable byte(s) -==9742== at 0x48703CC: __libc_read (read.c:26) -==9742== by 0x48703CC: read (read.c:24) -==9742== by 0x10B625: threadfunc (aesdsocket.c:482) -==9742== by 0x4865608: start_thread (pthread_create.c:477) -==9742== by 0x499F352: clone (clone.S:95) -==9742== Address 0x0 is not stack'd, malloc'd or (recently) free'd -==9742== -==9742== ERROR SUMMARY: 17 errors from 1 contexts (suppressed: 0 from 0) +==4591== Memcheck, a memory error detector +==4591== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. +==4591== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info +==4591== Command: ./aesdsocket +==4591== Parent PID: 4589 +==4591== +--4591-- +--4591-- Valgrind options: +--4591-- --error-exitcode=1 +--4591-- --leak-check=full +--4591-- --show-leak-kinds=all +--4591-- --track-origins=yes +--4591-- --errors-for-leak-kinds=definite +--4591-- --verbose +--4591-- --log-file=valgrind-out.txt +--4591-- Contents of /proc/version: +--4591-- Linux version 5.15.0-122-generic (buildd@lcy02-amd64-106) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #132~20.04.1-Ubuntu SMP Fri Aug 30 15:50:07 UTC 2024 +--4591-- +--4591-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3 +--4591-- Page sizes: currently 4096, max supported 4096 +--4591-- Valgrind library directory: /usr/lib/x86_64-linux-gnu/valgrind +--4591-- Reading syms from /home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocket +--4591-- Reading syms from /usr/lib/x86_64-linux-gnu/ld-2.31.so +--4591-- Considering /usr/lib/debug/.build-id/db/0420f708b806cf03260aadb916c330049580b7.debug .. +--4591-- .. build-id is valid +--4591-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-linux +--4591-- object doesn't have a symbol table +--4591-- object doesn't have a dynamic symbol table +--4591-- Scheduler: using generic scheduler lock implementation. +--4591-- Reading suppressions file: /usr/lib/x86_64-linux-gnu/valgrind/default.supp +==4591== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-4591-by-stamrakar-on-??? +==4591== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-4591-by-stamrakar-on-??? +==4591== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-4591-by-stamrakar-on-??? +==4591== +==4591== TO CONTROL THIS PROCESS USING vgdb (which you probably +==4591== don't want to do, unless you know exactly what you're doing, +==4591== or are doing some strange experiment): +==4591== /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=4591 ...command... +==4591== +==4591== TO DEBUG THIS PROCESS USING GDB: start GDB like this +==4591== /path/to/gdb ./aesdsocket +==4591== and then give GDB the following command +==4591== target remote | /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=4591 +==4591== --pid is optional if only one valgrind process is running +==4591== +--4591-- REDIR: 0x4022e20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9ce2 (???) +--4591-- REDIR: 0x4022bf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c9cfc (???) +--4591-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_core-amd64-linux.so +--4591-- object doesn't have a symbol table +--4591-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so +--4591-- object doesn't have a symbol table +==4591== WARNING: new redirection conflicts with existing -- ignoring it +--4591-- old: 0x04022e20 (strlen ) R-> (0000.0) 0x580c9ce2 ??? +--4591-- new: 0x04022e20 (strlen ) R-> (2007.0) 0x0483f060 strlen +--4591-- REDIR: 0x401f600 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ffd0 (strcmp) +--4591-- REDIR: 0x4023380 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4843a20 (mempcpy) +--4591-- Reading syms from /usr/lib/x86_64-linux-gnu/libpthread-2.31.so +--4591-- Considering /usr/lib/debug/.build-id/9a/65bb469e45a1c6fbcffae5b82a2fd7a69eb479.debug .. +--4591-- .. build-id is valid +--4591-- Reading syms from /usr/lib/x86_64-linux-gnu/libc-2.31.so +--4591-- Considering /usr/lib/debug/.build-id/07/02430aef5fa3dda43986563e9ffcc47efbd75e.debug .. +--4591-- .. build-id is valid +--4591-- REDIR: 0x4920480 (libc.so.6:memmove) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x491f780 (libc.so.6:strncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x49207b0 (libc.so.6:strcasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x491f0a0 (libc.so.6:strcat) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x491f7e0 (libc.so.6:rindex) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x4921c50 (libc.so.6:rawmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x493cce0 (libc.so.6:wmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x493c820 (libc.so.6:wcscmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x49205e0 (libc.so.6:mempcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x4920410 (libc.so.6:bcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x491f710 (libc.so.6:strncmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x491f150 (libc.so.6:strcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x4920540 (libc.so.6:memset) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x493c7e0 (libc.so.6:wcschr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x491f670 (libc.so.6:strnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x491f230 (libc.so.6:strcspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x4920800 (libc.so.6:strncasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x491f1d0 (libc.so.6:strcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x4920950 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x493df50 (libc.so.6:wcsnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x493c860 (libc.so.6:wcscpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x491f820 (libc.so.6:strpbrk) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x491f100 (libc.so.6:index) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x491f630 (libc.so.6:strlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x4928bb0 (libc.so.6:memrchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x4920850 (libc.so.6:strcasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x49203d0 (libc.so.6:memchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x493c930 (libc.so.6:wcslen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x491fae0 (libc.so.6:strspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x4920750 (libc.so.6:stpncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x49206f0 (libc.so.6:stpcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x4921c90 (libc.so.6:strchrnul) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x49208a0 (libc.so.6:strncasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--4591-- REDIR: 0x49318c0 (libc.so.6:__strrchr_sse2) redirected to 0x483ea70 (__strrchr_sse2) +--4591-- REDIR: 0x491a0e0 (libc.so.6:malloc) redirected to 0x483b780 (malloc) +--4591-- REDIR: 0x491bb10 (libc.so.6:calloc) redirected to 0x483dce0 (calloc) +--4591-- REDIR: 0x49316b0 (libc.so.6:__strchrnul_sse2) redirected to 0x4843540 (strchrnul) +--4591-- REDIR: 0x4931bc0 (libc.so.6:__strlen_sse2) redirected to 0x483efa0 (__strlen_sse2) +--4591-- REDIR: 0x491a6d0 (libc.so.6:free) redirected to 0x483c9d0 (free) +--4591-- REDIR: 0x493bad0 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4840100 (memcpy@GLIBC_2.2.5) +--4591-- REDIR: 0x491ffa0 (libc.so.6:__GI_strstr) redirected to 0x4843ca0 (__strstr_sse2) +--4591-- REDIR: 0x4a0d790 (libc.so.6:__memcmp_sse4_1) redirected to 0x4842150 (__memcmp_sse4_1) +--4591-- REDIR: 0x492a3b0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x483fed0 (strcmp) +--4591-- REDIR: 0x493bab0 (libc.so.6:__mempcpy_sse2_unaligned) redirected to 0x4843660 (mempcpy) +--4591-- REDIR: 0x491ae80 (libc.so.6:realloc) redirected to 0x483df30 (realloc) +--4591-- REDIR: 0x493bf00 (libc.so.6:__memset_sse2_unaligned) redirected to 0x48428e0 (memset) +--4591-- REDIR: 0x492bec0 (libc.so.6:__memchr_sse2) redirected to 0x4840050 (memchr) +--4591-- REDIR: 0x4931480 (libc.so.6:__strchr_sse2) redirected to 0x483eb90 (__strchr_sse2) +--4591-- REDIR: 0x4936b00 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x483f090 (strcpy) +--4591-- REDIR: 0x4938140 (libc.so.6:__stpcpy_sse2_unaligned) redirected to 0x4842570 (__stpcpy_sse2_unaligned) +==4591== +==4591== HEAP SUMMARY: +==4591== in use at exit: 272 bytes in 1 blocks +==4591== total heap usage: 750 allocs, 749 frees, 2,043,728 bytes allocated +==4591== +==4591== Searching for pointers to 1 not-freed blocks +==4591== Checked 8,477,224 bytes +==4591== +==4591== 272 bytes in 1 blocks are possibly lost in loss record 1 of 1 +==4591== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==4591== by 0x40149DA: allocate_dtv (dl-tls.c:286) +==4591== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) +==4591== by 0x4866322: allocate_stack (allocatestack.c:622) +==4591== by 0x4866322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) +==4591== by 0x10AA74: initTimer (aesdsocket.c:182) +==4591== by 0x10B9FE: main (aesdsocket.c:619) +==4591== +==4591== LEAK SUMMARY: +==4591== definitely lost: 0 bytes in 0 blocks +==4591== indirectly lost: 0 bytes in 0 blocks +==4591== possibly lost: 272 bytes in 1 blocks +==4591== still reachable: 0 bytes in 0 blocks +==4591== suppressed: 0 bytes in 0 blocks +==4591== +==4591== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) From 28921e2434fefd62adfbbecc74c87cc8b1331849 Mon Sep 17 00:00:00 2001 From: stamrakar Date: Tue, 15 Oct 2024 18:33:35 -0600 Subject: [PATCH 16/17] valgrind fix --- server/aesdsocket.c | 6 +- server/valgrind-out.txt | 274 ++++++++++++++++++++-------------------- 2 files changed, 140 insertions(+), 140 deletions(-) diff --git a/server/aesdsocket.c b/server/aesdsocket.c index e2cce11..d2b993a 100644 --- a/server/aesdsocket.c +++ b/server/aesdsocket.c @@ -306,7 +306,7 @@ void *threadtimerfunc(void *args) perror("pthread mutex_unlock failed"); } } - printf("Thread should be completed here.\n"); + //printf("Thread should be completed here.\n"); //thread_func_args->thread_info.thread_complete_success = true; return NULL; } @@ -618,7 +618,7 @@ int main(int argc, char *argv[]) initTimer(); - printf("Timer thread has been set\n"); + //printf("Timer thread has been set\n"); while(!sig){ @@ -739,7 +739,7 @@ int main(int argc, char *argv[]) } else { - printf("\nThe list is not empty. About to join every threads\n"); + //printf("\nThe list is not empty. About to join every threads\n"); SLIST_FOREACH_SAFE(datap1, &head, nextThread, temp1) { join_rc1 = pthread_join(datap1->thread_info.threadid, NULL); diff --git a/server/valgrind-out.txt b/server/valgrind-out.txt index 0ce85a3..6ca3e6c 100644 --- a/server/valgrind-out.txt +++ b/server/valgrind-out.txt @@ -1,137 +1,137 @@ -==4591== Memcheck, a memory error detector -==4591== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. -==4591== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info -==4591== Command: ./aesdsocket -==4591== Parent PID: 4589 -==4591== ---4591-- ---4591-- Valgrind options: ---4591-- --error-exitcode=1 ---4591-- --leak-check=full ---4591-- --show-leak-kinds=all ---4591-- --track-origins=yes ---4591-- --errors-for-leak-kinds=definite ---4591-- --verbose ---4591-- --log-file=valgrind-out.txt ---4591-- Contents of /proc/version: ---4591-- Linux version 5.15.0-122-generic (buildd@lcy02-amd64-106) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #132~20.04.1-Ubuntu SMP Fri Aug 30 15:50:07 UTC 2024 ---4591-- ---4591-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3 ---4591-- Page sizes: currently 4096, max supported 4096 ---4591-- Valgrind library directory: /usr/lib/x86_64-linux-gnu/valgrind ---4591-- Reading syms from /home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocket ---4591-- Reading syms from /usr/lib/x86_64-linux-gnu/ld-2.31.so ---4591-- Considering /usr/lib/debug/.build-id/db/0420f708b806cf03260aadb916c330049580b7.debug .. ---4591-- .. build-id is valid ---4591-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-linux ---4591-- object doesn't have a symbol table ---4591-- object doesn't have a dynamic symbol table ---4591-- Scheduler: using generic scheduler lock implementation. ---4591-- Reading suppressions file: /usr/lib/x86_64-linux-gnu/valgrind/default.supp -==4591== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-4591-by-stamrakar-on-??? -==4591== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-4591-by-stamrakar-on-??? -==4591== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-4591-by-stamrakar-on-??? -==4591== -==4591== TO CONTROL THIS PROCESS USING vgdb (which you probably -==4591== don't want to do, unless you know exactly what you're doing, -==4591== or are doing some strange experiment): -==4591== /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=4591 ...command... -==4591== -==4591== TO DEBUG THIS PROCESS USING GDB: start GDB like this -==4591== /path/to/gdb ./aesdsocket -==4591== and then give GDB the following command -==4591== target remote | /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=4591 -==4591== --pid is optional if only one valgrind process is running -==4591== ---4591-- REDIR: 0x4022e20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9ce2 (???) ---4591-- REDIR: 0x4022bf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c9cfc (???) ---4591-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_core-amd64-linux.so ---4591-- object doesn't have a symbol table ---4591-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so ---4591-- object doesn't have a symbol table -==4591== WARNING: new redirection conflicts with existing -- ignoring it ---4591-- old: 0x04022e20 (strlen ) R-> (0000.0) 0x580c9ce2 ??? ---4591-- new: 0x04022e20 (strlen ) R-> (2007.0) 0x0483f060 strlen ---4591-- REDIR: 0x401f600 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ffd0 (strcmp) ---4591-- REDIR: 0x4023380 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4843a20 (mempcpy) ---4591-- Reading syms from /usr/lib/x86_64-linux-gnu/libpthread-2.31.so ---4591-- Considering /usr/lib/debug/.build-id/9a/65bb469e45a1c6fbcffae5b82a2fd7a69eb479.debug .. ---4591-- .. build-id is valid ---4591-- Reading syms from /usr/lib/x86_64-linux-gnu/libc-2.31.so ---4591-- Considering /usr/lib/debug/.build-id/07/02430aef5fa3dda43986563e9ffcc47efbd75e.debug .. ---4591-- .. build-id is valid ---4591-- REDIR: 0x4920480 (libc.so.6:memmove) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x491f780 (libc.so.6:strncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x49207b0 (libc.so.6:strcasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x491f0a0 (libc.so.6:strcat) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x491f7e0 (libc.so.6:rindex) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x4921c50 (libc.so.6:rawmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x493cce0 (libc.so.6:wmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x493c820 (libc.so.6:wcscmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x49205e0 (libc.so.6:mempcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x4920410 (libc.so.6:bcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x491f710 (libc.so.6:strncmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x491f150 (libc.so.6:strcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x4920540 (libc.so.6:memset) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x493c7e0 (libc.so.6:wcschr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x491f670 (libc.so.6:strnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x491f230 (libc.so.6:strcspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x4920800 (libc.so.6:strncasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x491f1d0 (libc.so.6:strcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x4920950 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x493df50 (libc.so.6:wcsnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x493c860 (libc.so.6:wcscpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x491f820 (libc.so.6:strpbrk) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x491f100 (libc.so.6:index) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x491f630 (libc.so.6:strlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x4928bb0 (libc.so.6:memrchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x4920850 (libc.so.6:strcasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x49203d0 (libc.so.6:memchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x493c930 (libc.so.6:wcslen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x491fae0 (libc.so.6:strspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x4920750 (libc.so.6:stpncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x49206f0 (libc.so.6:stpcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x4921c90 (libc.so.6:strchrnul) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x49208a0 (libc.so.6:strncasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---4591-- REDIR: 0x49318c0 (libc.so.6:__strrchr_sse2) redirected to 0x483ea70 (__strrchr_sse2) ---4591-- REDIR: 0x491a0e0 (libc.so.6:malloc) redirected to 0x483b780 (malloc) ---4591-- REDIR: 0x491bb10 (libc.so.6:calloc) redirected to 0x483dce0 (calloc) ---4591-- REDIR: 0x49316b0 (libc.so.6:__strchrnul_sse2) redirected to 0x4843540 (strchrnul) ---4591-- REDIR: 0x4931bc0 (libc.so.6:__strlen_sse2) redirected to 0x483efa0 (__strlen_sse2) ---4591-- REDIR: 0x491a6d0 (libc.so.6:free) redirected to 0x483c9d0 (free) ---4591-- REDIR: 0x493bad0 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4840100 (memcpy@GLIBC_2.2.5) ---4591-- REDIR: 0x491ffa0 (libc.so.6:__GI_strstr) redirected to 0x4843ca0 (__strstr_sse2) ---4591-- REDIR: 0x4a0d790 (libc.so.6:__memcmp_sse4_1) redirected to 0x4842150 (__memcmp_sse4_1) ---4591-- REDIR: 0x492a3b0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x483fed0 (strcmp) ---4591-- REDIR: 0x493bab0 (libc.so.6:__mempcpy_sse2_unaligned) redirected to 0x4843660 (mempcpy) ---4591-- REDIR: 0x491ae80 (libc.so.6:realloc) redirected to 0x483df30 (realloc) ---4591-- REDIR: 0x493bf00 (libc.so.6:__memset_sse2_unaligned) redirected to 0x48428e0 (memset) ---4591-- REDIR: 0x492bec0 (libc.so.6:__memchr_sse2) redirected to 0x4840050 (memchr) ---4591-- REDIR: 0x4931480 (libc.so.6:__strchr_sse2) redirected to 0x483eb90 (__strchr_sse2) ---4591-- REDIR: 0x4936b00 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x483f090 (strcpy) ---4591-- REDIR: 0x4938140 (libc.so.6:__stpcpy_sse2_unaligned) redirected to 0x4842570 (__stpcpy_sse2_unaligned) -==4591== -==4591== HEAP SUMMARY: -==4591== in use at exit: 272 bytes in 1 blocks -==4591== total heap usage: 750 allocs, 749 frees, 2,043,728 bytes allocated -==4591== -==4591== Searching for pointers to 1 not-freed blocks -==4591== Checked 8,477,224 bytes -==4591== -==4591== 272 bytes in 1 blocks are possibly lost in loss record 1 of 1 -==4591== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==4591== by 0x40149DA: allocate_dtv (dl-tls.c:286) -==4591== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) -==4591== by 0x4866322: allocate_stack (allocatestack.c:622) -==4591== by 0x4866322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) -==4591== by 0x10AA74: initTimer (aesdsocket.c:182) -==4591== by 0x10B9FE: main (aesdsocket.c:619) -==4591== -==4591== LEAK SUMMARY: -==4591== definitely lost: 0 bytes in 0 blocks -==4591== indirectly lost: 0 bytes in 0 blocks -==4591== possibly lost: 272 bytes in 1 blocks -==4591== still reachable: 0 bytes in 0 blocks -==4591== suppressed: 0 bytes in 0 blocks -==4591== -==4591== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) +==5517== Memcheck, a memory error detector +==5517== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. +==5517== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info +==5517== Command: ./aesdsocket +==5517== Parent PID: 5513 +==5517== +--5517-- +--5517-- Valgrind options: +--5517-- --error-exitcode=1 +--5517-- --leak-check=full +--5517-- --show-leak-kinds=all +--5517-- --track-origins=yes +--5517-- --errors-for-leak-kinds=definite +--5517-- --verbose +--5517-- --log-file=valgrind-out.txt +--5517-- Contents of /proc/version: +--5517-- Linux version 5.15.0-122-generic (buildd@lcy02-amd64-106) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #132~20.04.1-Ubuntu SMP Fri Aug 30 15:50:07 UTC 2024 +--5517-- +--5517-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3 +--5517-- Page sizes: currently 4096, max supported 4096 +--5517-- Valgrind library directory: /usr/lib/x86_64-linux-gnu/valgrind +--5517-- Reading syms from /home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocket +--5517-- Reading syms from /usr/lib/x86_64-linux-gnu/ld-2.31.so +--5517-- Considering /usr/lib/debug/.build-id/db/0420f708b806cf03260aadb916c330049580b7.debug .. +--5517-- .. build-id is valid +--5517-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-linux +--5517-- object doesn't have a symbol table +--5517-- object doesn't have a dynamic symbol table +--5517-- Scheduler: using generic scheduler lock implementation. +--5517-- Reading suppressions file: /usr/lib/x86_64-linux-gnu/valgrind/default.supp +==5517== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-5517-by-stamrakar-on-??? +==5517== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-5517-by-stamrakar-on-??? +==5517== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-5517-by-stamrakar-on-??? +==5517== +==5517== TO CONTROL THIS PROCESS USING vgdb (which you probably +==5517== don't want to do, unless you know exactly what you're doing, +==5517== or are doing some strange experiment): +==5517== /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=5517 ...command... +==5517== +==5517== TO DEBUG THIS PROCESS USING GDB: start GDB like this +==5517== /path/to/gdb ./aesdsocket +==5517== and then give GDB the following command +==5517== target remote | /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=5517 +==5517== --pid is optional if only one valgrind process is running +==5517== +--5517-- REDIR: 0x4022e20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9ce2 (???) +--5517-- REDIR: 0x4022bf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c9cfc (???) +--5517-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_core-amd64-linux.so +--5517-- object doesn't have a symbol table +--5517-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so +--5517-- object doesn't have a symbol table +==5517== WARNING: new redirection conflicts with existing -- ignoring it +--5517-- old: 0x04022e20 (strlen ) R-> (0000.0) 0x580c9ce2 ??? +--5517-- new: 0x04022e20 (strlen ) R-> (2007.0) 0x0483f060 strlen +--5517-- REDIR: 0x401f600 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ffd0 (strcmp) +--5517-- REDIR: 0x4023380 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4843a20 (mempcpy) +--5517-- Reading syms from /usr/lib/x86_64-linux-gnu/libpthread-2.31.so +--5517-- Considering /usr/lib/debug/.build-id/9a/65bb469e45a1c6fbcffae5b82a2fd7a69eb479.debug .. +--5517-- .. build-id is valid +--5517-- Reading syms from /usr/lib/x86_64-linux-gnu/libc-2.31.so +--5517-- Considering /usr/lib/debug/.build-id/07/02430aef5fa3dda43986563e9ffcc47efbd75e.debug .. +--5517-- .. build-id is valid +--5517-- REDIR: 0x4920480 (libc.so.6:memmove) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x491f780 (libc.so.6:strncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x49207b0 (libc.so.6:strcasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x491f0a0 (libc.so.6:strcat) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x491f7e0 (libc.so.6:rindex) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x4921c50 (libc.so.6:rawmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x493cce0 (libc.so.6:wmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x493c820 (libc.so.6:wcscmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x49205e0 (libc.so.6:mempcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x4920410 (libc.so.6:bcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x491f710 (libc.so.6:strncmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x491f150 (libc.so.6:strcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x4920540 (libc.so.6:memset) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x493c7e0 (libc.so.6:wcschr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x491f670 (libc.so.6:strnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x491f230 (libc.so.6:strcspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x4920800 (libc.so.6:strncasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x491f1d0 (libc.so.6:strcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x4920950 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x493df50 (libc.so.6:wcsnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x493c860 (libc.so.6:wcscpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x491f820 (libc.so.6:strpbrk) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x491f100 (libc.so.6:index) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x491f630 (libc.so.6:strlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x4928bb0 (libc.so.6:memrchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x4920850 (libc.so.6:strcasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x49203d0 (libc.so.6:memchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x493c930 (libc.so.6:wcslen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x491fae0 (libc.so.6:strspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x4920750 (libc.so.6:stpncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x49206f0 (libc.so.6:stpcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x4921c90 (libc.so.6:strchrnul) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x49208a0 (libc.so.6:strncasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--5517-- REDIR: 0x49318c0 (libc.so.6:__strrchr_sse2) redirected to 0x483ea70 (__strrchr_sse2) +--5517-- REDIR: 0x491a0e0 (libc.so.6:malloc) redirected to 0x483b780 (malloc) +--5517-- REDIR: 0x491bb10 (libc.so.6:calloc) redirected to 0x483dce0 (calloc) +--5517-- REDIR: 0x49316b0 (libc.so.6:__strchrnul_sse2) redirected to 0x4843540 (strchrnul) +--5517-- REDIR: 0x4931bc0 (libc.so.6:__strlen_sse2) redirected to 0x483efa0 (__strlen_sse2) +--5517-- REDIR: 0x491a6d0 (libc.so.6:free) redirected to 0x483c9d0 (free) +--5517-- REDIR: 0x493bad0 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4840100 (memcpy@GLIBC_2.2.5) +--5517-- REDIR: 0x491ffa0 (libc.so.6:__GI_strstr) redirected to 0x4843ca0 (__strstr_sse2) +--5517-- REDIR: 0x4a0d790 (libc.so.6:__memcmp_sse4_1) redirected to 0x4842150 (__memcmp_sse4_1) +--5517-- REDIR: 0x492a3b0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x483fed0 (strcmp) +--5517-- REDIR: 0x493bab0 (libc.so.6:__mempcpy_sse2_unaligned) redirected to 0x4843660 (mempcpy) +--5517-- REDIR: 0x491ae80 (libc.so.6:realloc) redirected to 0x483df30 (realloc) +--5517-- REDIR: 0x493bf00 (libc.so.6:__memset_sse2_unaligned) redirected to 0x48428e0 (memset) +--5517-- REDIR: 0x492bec0 (libc.so.6:__memchr_sse2) redirected to 0x4840050 (memchr) +--5517-- REDIR: 0x4931480 (libc.so.6:__strchr_sse2) redirected to 0x483eb90 (__strchr_sse2) +--5517-- REDIR: 0x4936b00 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x483f090 (strcpy) +--5517-- REDIR: 0x4938140 (libc.so.6:__stpcpy_sse2_unaligned) redirected to 0x4842570 (__stpcpy_sse2_unaligned) +==5517== +==5517== HEAP SUMMARY: +==5517== in use at exit: 272 bytes in 1 blocks +==5517== total heap usage: 749 allocs, 748 frees, 2,039,640 bytes allocated +==5517== +==5517== Searching for pointers to 1 not-freed blocks +==5517== Checked 8,477,224 bytes +==5517== +==5517== 272 bytes in 1 blocks are possibly lost in loss record 1 of 1 +==5517== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==5517== by 0x40149DA: allocate_dtv (dl-tls.c:286) +==5517== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) +==5517== by 0x4866322: allocate_stack (allocatestack.c:622) +==5517== by 0x4866322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) +==5517== by 0x10AA74: initTimer (aesdsocket.c:182) +==5517== by 0x10B9F2: main (aesdsocket.c:619) +==5517== +==5517== LEAK SUMMARY: +==5517== definitely lost: 0 bytes in 0 blocks +==5517== indirectly lost: 0 bytes in 0 blocks +==5517== possibly lost: 272 bytes in 1 blocks +==5517== still reachable: 0 bytes in 0 blocks +==5517== suppressed: 0 bytes in 0 blocks +==5517== +==5517== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) From 48ae4d424eabc7b5f7785f5fced8e273b06e1388 Mon Sep 17 00:00:00 2001 From: stamrakar Date: Tue, 15 Oct 2024 19:03:43 -0600 Subject: [PATCH 17/17] more changes --- server/aesdsocket.c | 77 ++--------- server/valgrind-out.txt | 274 ++++++++++++++++++++-------------------- 2 files changed, 150 insertions(+), 201 deletions(-) diff --git a/server/aesdsocket.c b/server/aesdsocket.c index d2b993a..db7c8ae 100644 --- a/server/aesdsocket.c +++ b/server/aesdsocket.c @@ -55,7 +55,6 @@ typedef struct thread_info_s thread_info_t; typedef struct slist_data_s my_threads; pthread_mutex_t writeSocket = PTHREAD_MUTEX_INITIALIZER; -pthread_mutex_t size_val = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t ll_lock = PTHREAD_MUTEX_INITIALIZER; @@ -206,7 +205,6 @@ void closeAll(int exit_flag) pthread_mutex_destroy(&writeSocket); pthread_mutex_destroy(&ll_lock); syslog(LOG_DEBUG, "PERFORMING CLEANUP2"); - pthread_mutex_destroy(&size_val); syslog(LOG_DEBUG, "CLEANUP COMPLETED."); closelog(); exit(exit_flag); @@ -282,23 +280,8 @@ void *threadtimerfunc(void *args) } continue; } - - rc = pthread_mutex_lock(&size_val); - if (rc != 0) - { - syslog(LOG_ERR, "pthread_mutex_lock failed on total size, error was %d", rc); - perror("pthread mutex_lock failed"); - } - total_size += strlen(timestamp); - rc = pthread_mutex_unlock(&size_val); - if (rc != 0) - { - syslog(LOG_ERR, "pthread_mutex_unlock failed on total size, error was %d", rc); - perror("pthread mutex_lock failed"); - } - rc = pthread_mutex_unlock(&writeSocket); if (rc != 0) { @@ -389,6 +372,8 @@ void *threadfunc(void *args) nr = write(recvfile_fd, my_buffer, supplementBuf); + total_size += supplementBuf; + rc = pthread_mutex_unlock(&writeSocket); if (rc != 0) { @@ -410,29 +395,11 @@ void *threadfunc(void *args) } - rc = pthread_mutex_lock(&size_val); - if (rc != 0) - { - syslog(LOG_ERR, "pthread_mutex_lock failed on total size, error was %d", rc); - perror("pthread mutex_lock failed"); - } - - total_size += supplementBuf; - - rc = pthread_mutex_unlock(&size_val); - if (rc != 0) - { - syslog(LOG_ERR, "pthread_mutex_unlock failed on total size, error was %d", rc); - perror("pthread mutex_lock failed"); - } free(my_buffer); my_buffer = NULL; - - - rc = pthread_mutex_lock(&writeSocket); if (rc != 0) { @@ -447,30 +414,6 @@ void *threadfunc(void *args) closeAll(EXIT_FAILURE); } - rc = pthread_mutex_unlock(&writeSocket); - if (rc != 0) - { - syslog(LOG_ERR, "pthread_mutex_unlock failed, error was %d", rc); - perror("pthread mutex_unlock failed"); - } - - - rc = pthread_mutex_lock(&size_val); - if (rc != 0) - { - syslog(LOG_ERR, "pthread_mutex_lock failed on total size, error was %d", rc); - perror("pthread mutex_lock failed"); - } - - ssize_t remaining = total_size; - - rc = pthread_mutex_unlock(&size_val); - if (rc != 0) - { - syslog(LOG_ERR, "pthread_mutex_unlock failed on total size, error was %d", rc); - perror("pthread mutex_lock failed"); - } - send_my_buffer = (char *) malloc(BUF_SIZE); if (send_my_buffer == NULL) { @@ -481,8 +424,8 @@ void *threadfunc(void *args) int errnum9 = 0; //printf("total size here is %ld, \n", total_size); - syslog(LOG_DEBUG, "total size here is %ld", remaining); - while ((bytes_read = read(recvfile_fd, send_my_buffer, remaining)) > 0) { + syslog(LOG_DEBUG, "total size here is %ld", total_size); + while ((bytes_read = read(recvfile_fd, send_my_buffer, total_size)) > 0) { syslog(LOG_DEBUG, "bytes_read is %ld", bytes_read); //syslog(LOG_DEBUG, "Sending: %s",send_my_buffer); if (send(thread_func_args->thread_info.afd, send_my_buffer, bytes_read, 0) != bytes_read) @@ -500,6 +443,13 @@ void *threadfunc(void *args) } } + rc = pthread_mutex_unlock(&writeSocket); + if (rc != 0) + { + syslog(LOG_ERR, "pthread_mutex_unlock failed, error was %d", rc); + perror("pthread mutex_unlock failed"); + } + free(send_my_buffer); send_my_buffer = NULL; @@ -625,8 +575,8 @@ int main(int argc, char *argv[]) peer_addrlen = sizeof(peer_addr); if((new_fd = accept(sockfd, (struct sockaddr *)&peer_addr, &peer_addrlen)) == -1 ) { - syslog(LOG_ERR, "server: accept"); - perror("server: accept"); + syslog(LOG_ERR, "server: acceptHERE?:"); + perror("server: acceptHERE?:"); continue; } @@ -757,7 +707,6 @@ int main(int argc, char *argv[]) } syslog(LOG_DEBUG, "Do I reach here?"); - //printf("Do I reach here?\n"); closeAll(EXIT_SUCCESS); return 0; } \ No newline at end of file diff --git a/server/valgrind-out.txt b/server/valgrind-out.txt index 6ca3e6c..805411b 100644 --- a/server/valgrind-out.txt +++ b/server/valgrind-out.txt @@ -1,137 +1,137 @@ -==5517== Memcheck, a memory error detector -==5517== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. -==5517== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info -==5517== Command: ./aesdsocket -==5517== Parent PID: 5513 -==5517== ---5517-- ---5517-- Valgrind options: ---5517-- --error-exitcode=1 ---5517-- --leak-check=full ---5517-- --show-leak-kinds=all ---5517-- --track-origins=yes ---5517-- --errors-for-leak-kinds=definite ---5517-- --verbose ---5517-- --log-file=valgrind-out.txt ---5517-- Contents of /proc/version: ---5517-- Linux version 5.15.0-122-generic (buildd@lcy02-amd64-106) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #132~20.04.1-Ubuntu SMP Fri Aug 30 15:50:07 UTC 2024 ---5517-- ---5517-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3 ---5517-- Page sizes: currently 4096, max supported 4096 ---5517-- Valgrind library directory: /usr/lib/x86_64-linux-gnu/valgrind ---5517-- Reading syms from /home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocket ---5517-- Reading syms from /usr/lib/x86_64-linux-gnu/ld-2.31.so ---5517-- Considering /usr/lib/debug/.build-id/db/0420f708b806cf03260aadb916c330049580b7.debug .. ---5517-- .. build-id is valid ---5517-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-linux ---5517-- object doesn't have a symbol table ---5517-- object doesn't have a dynamic symbol table ---5517-- Scheduler: using generic scheduler lock implementation. ---5517-- Reading suppressions file: /usr/lib/x86_64-linux-gnu/valgrind/default.supp -==5517== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-5517-by-stamrakar-on-??? -==5517== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-5517-by-stamrakar-on-??? -==5517== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-5517-by-stamrakar-on-??? -==5517== -==5517== TO CONTROL THIS PROCESS USING vgdb (which you probably -==5517== don't want to do, unless you know exactly what you're doing, -==5517== or are doing some strange experiment): -==5517== /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=5517 ...command... -==5517== -==5517== TO DEBUG THIS PROCESS USING GDB: start GDB like this -==5517== /path/to/gdb ./aesdsocket -==5517== and then give GDB the following command -==5517== target remote | /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=5517 -==5517== --pid is optional if only one valgrind process is running -==5517== ---5517-- REDIR: 0x4022e20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9ce2 (???) ---5517-- REDIR: 0x4022bf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c9cfc (???) ---5517-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_core-amd64-linux.so ---5517-- object doesn't have a symbol table ---5517-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so ---5517-- object doesn't have a symbol table -==5517== WARNING: new redirection conflicts with existing -- ignoring it ---5517-- old: 0x04022e20 (strlen ) R-> (0000.0) 0x580c9ce2 ??? ---5517-- new: 0x04022e20 (strlen ) R-> (2007.0) 0x0483f060 strlen ---5517-- REDIR: 0x401f600 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ffd0 (strcmp) ---5517-- REDIR: 0x4023380 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4843a20 (mempcpy) ---5517-- Reading syms from /usr/lib/x86_64-linux-gnu/libpthread-2.31.so ---5517-- Considering /usr/lib/debug/.build-id/9a/65bb469e45a1c6fbcffae5b82a2fd7a69eb479.debug .. ---5517-- .. build-id is valid ---5517-- Reading syms from /usr/lib/x86_64-linux-gnu/libc-2.31.so ---5517-- Considering /usr/lib/debug/.build-id/07/02430aef5fa3dda43986563e9ffcc47efbd75e.debug .. ---5517-- .. build-id is valid ---5517-- REDIR: 0x4920480 (libc.so.6:memmove) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x491f780 (libc.so.6:strncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x49207b0 (libc.so.6:strcasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x491f0a0 (libc.so.6:strcat) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x491f7e0 (libc.so.6:rindex) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x4921c50 (libc.so.6:rawmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x493cce0 (libc.so.6:wmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x493c820 (libc.so.6:wcscmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x49205e0 (libc.so.6:mempcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x4920410 (libc.so.6:bcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x491f710 (libc.so.6:strncmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x491f150 (libc.so.6:strcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x4920540 (libc.so.6:memset) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x493c7e0 (libc.so.6:wcschr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x491f670 (libc.so.6:strnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x491f230 (libc.so.6:strcspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x4920800 (libc.so.6:strncasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x491f1d0 (libc.so.6:strcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x4920950 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x493df50 (libc.so.6:wcsnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x493c860 (libc.so.6:wcscpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x491f820 (libc.so.6:strpbrk) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x491f100 (libc.so.6:index) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x491f630 (libc.so.6:strlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x4928bb0 (libc.so.6:memrchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x4920850 (libc.so.6:strcasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x49203d0 (libc.so.6:memchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x493c930 (libc.so.6:wcslen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x491fae0 (libc.so.6:strspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x4920750 (libc.so.6:stpncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x49206f0 (libc.so.6:stpcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x4921c90 (libc.so.6:strchrnul) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x49208a0 (libc.so.6:strncasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) ---5517-- REDIR: 0x49318c0 (libc.so.6:__strrchr_sse2) redirected to 0x483ea70 (__strrchr_sse2) ---5517-- REDIR: 0x491a0e0 (libc.so.6:malloc) redirected to 0x483b780 (malloc) ---5517-- REDIR: 0x491bb10 (libc.so.6:calloc) redirected to 0x483dce0 (calloc) ---5517-- REDIR: 0x49316b0 (libc.so.6:__strchrnul_sse2) redirected to 0x4843540 (strchrnul) ---5517-- REDIR: 0x4931bc0 (libc.so.6:__strlen_sse2) redirected to 0x483efa0 (__strlen_sse2) ---5517-- REDIR: 0x491a6d0 (libc.so.6:free) redirected to 0x483c9d0 (free) ---5517-- REDIR: 0x493bad0 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4840100 (memcpy@GLIBC_2.2.5) ---5517-- REDIR: 0x491ffa0 (libc.so.6:__GI_strstr) redirected to 0x4843ca0 (__strstr_sse2) ---5517-- REDIR: 0x4a0d790 (libc.so.6:__memcmp_sse4_1) redirected to 0x4842150 (__memcmp_sse4_1) ---5517-- REDIR: 0x492a3b0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x483fed0 (strcmp) ---5517-- REDIR: 0x493bab0 (libc.so.6:__mempcpy_sse2_unaligned) redirected to 0x4843660 (mempcpy) ---5517-- REDIR: 0x491ae80 (libc.so.6:realloc) redirected to 0x483df30 (realloc) ---5517-- REDIR: 0x493bf00 (libc.so.6:__memset_sse2_unaligned) redirected to 0x48428e0 (memset) ---5517-- REDIR: 0x492bec0 (libc.so.6:__memchr_sse2) redirected to 0x4840050 (memchr) ---5517-- REDIR: 0x4931480 (libc.so.6:__strchr_sse2) redirected to 0x483eb90 (__strchr_sse2) ---5517-- REDIR: 0x4936b00 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x483f090 (strcpy) ---5517-- REDIR: 0x4938140 (libc.so.6:__stpcpy_sse2_unaligned) redirected to 0x4842570 (__stpcpy_sse2_unaligned) -==5517== -==5517== HEAP SUMMARY: -==5517== in use at exit: 272 bytes in 1 blocks -==5517== total heap usage: 749 allocs, 748 frees, 2,039,640 bytes allocated -==5517== -==5517== Searching for pointers to 1 not-freed blocks -==5517== Checked 8,477,224 bytes -==5517== -==5517== 272 bytes in 1 blocks are possibly lost in loss record 1 of 1 -==5517== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) -==5517== by 0x40149DA: allocate_dtv (dl-tls.c:286) -==5517== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) -==5517== by 0x4866322: allocate_stack (allocatestack.c:622) -==5517== by 0x4866322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) -==5517== by 0x10AA74: initTimer (aesdsocket.c:182) -==5517== by 0x10B9F2: main (aesdsocket.c:619) -==5517== -==5517== LEAK SUMMARY: -==5517== definitely lost: 0 bytes in 0 blocks -==5517== indirectly lost: 0 bytes in 0 blocks -==5517== possibly lost: 272 bytes in 1 blocks -==5517== still reachable: 0 bytes in 0 blocks -==5517== suppressed: 0 bytes in 0 blocks -==5517== -==5517== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) +==7744== Memcheck, a memory error detector +==7744== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. +==7744== Using Valgrind-3.15.0-608cb11914-20190413 and LibVEX; rerun with -h for copyright info +==7744== Command: ./aesdsocket +==7744== Parent PID: 7742 +==7744== +--7744-- +--7744-- Valgrind options: +--7744-- --error-exitcode=1 +--7744-- --leak-check=full +--7744-- --show-leak-kinds=all +--7744-- --track-origins=yes +--7744-- --errors-for-leak-kinds=definite +--7744-- --verbose +--7744-- --log-file=valgrind-out.txt +--7744-- Contents of /proc/version: +--7744-- Linux version 5.15.0-122-generic (buildd@lcy02-amd64-106) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #132~20.04.1-Ubuntu SMP Fri Aug 30 15:50:07 UTC 2024 +--7744-- +--7744-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3 +--7744-- Page sizes: currently 4096, max supported 4096 +--7744-- Valgrind library directory: /usr/lib/x86_64-linux-gnu/valgrind +--7744-- Reading syms from /home/stamrakar/AESD/assignment-1-sota6640/server/aesdsocket +--7744-- Reading syms from /usr/lib/x86_64-linux-gnu/ld-2.31.so +--7744-- Considering /usr/lib/debug/.build-id/db/0420f708b806cf03260aadb916c330049580b7.debug .. +--7744-- .. build-id is valid +--7744-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/memcheck-amd64-linux +--7744-- object doesn't have a symbol table +--7744-- object doesn't have a dynamic symbol table +--7744-- Scheduler: using generic scheduler lock implementation. +--7744-- Reading suppressions file: /usr/lib/x86_64-linux-gnu/valgrind/default.supp +==7744== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-7744-by-stamrakar-on-??? +==7744== embedded gdbserver: writing to /tmp/vgdb-pipe-to-vgdb-from-7744-by-stamrakar-on-??? +==7744== embedded gdbserver: shared mem /tmp/vgdb-pipe-shared-mem-vgdb-7744-by-stamrakar-on-??? +==7744== +==7744== TO CONTROL THIS PROCESS USING vgdb (which you probably +==7744== don't want to do, unless you know exactly what you're doing, +==7744== or are doing some strange experiment): +==7744== /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=7744 ...command... +==7744== +==7744== TO DEBUG THIS PROCESS USING GDB: start GDB like this +==7744== /path/to/gdb ./aesdsocket +==7744== and then give GDB the following command +==7744== target remote | /usr/lib/x86_64-linux-gnu/valgrind/../../bin/vgdb --pid=7744 +==7744== --pid is optional if only one valgrind process is running +==7744== +--7744-- REDIR: 0x4022e20 (ld-linux-x86-64.so.2:strlen) redirected to 0x580c9ce2 (???) +--7744-- REDIR: 0x4022bf0 (ld-linux-x86-64.so.2:index) redirected to 0x580c9cfc (???) +--7744-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_core-amd64-linux.so +--7744-- object doesn't have a symbol table +--7744-- Reading syms from /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so +--7744-- object doesn't have a symbol table +==7744== WARNING: new redirection conflicts with existing -- ignoring it +--7744-- old: 0x04022e20 (strlen ) R-> (0000.0) 0x580c9ce2 ??? +--7744-- new: 0x04022e20 (strlen ) R-> (2007.0) 0x0483f060 strlen +--7744-- REDIR: 0x401f600 (ld-linux-x86-64.so.2:strcmp) redirected to 0x483ffd0 (strcmp) +--7744-- REDIR: 0x4023380 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4843a20 (mempcpy) +--7744-- Reading syms from /usr/lib/x86_64-linux-gnu/libpthread-2.31.so +--7744-- Considering /usr/lib/debug/.build-id/9a/65bb469e45a1c6fbcffae5b82a2fd7a69eb479.debug .. +--7744-- .. build-id is valid +--7744-- Reading syms from /usr/lib/x86_64-linux-gnu/libc-2.31.so +--7744-- Considering /usr/lib/debug/.build-id/07/02430aef5fa3dda43986563e9ffcc47efbd75e.debug .. +--7744-- .. build-id is valid +--7744-- REDIR: 0x4920480 (libc.so.6:memmove) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x491f780 (libc.so.6:strncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x49207b0 (libc.so.6:strcasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x491f0a0 (libc.so.6:strcat) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x491f7e0 (libc.so.6:rindex) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x4921c50 (libc.so.6:rawmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x493cce0 (libc.so.6:wmemchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x493c820 (libc.so.6:wcscmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x49205e0 (libc.so.6:mempcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x4920410 (libc.so.6:bcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x491f710 (libc.so.6:strncmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x491f150 (libc.so.6:strcmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x4920540 (libc.so.6:memset) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x493c7e0 (libc.so.6:wcschr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x491f670 (libc.so.6:strnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x491f230 (libc.so.6:strcspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x4920800 (libc.so.6:strncasecmp) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x491f1d0 (libc.so.6:strcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x4920950 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x493df50 (libc.so.6:wcsnlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x493c860 (libc.so.6:wcscpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x491f820 (libc.so.6:strpbrk) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x491f100 (libc.so.6:index) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x491f630 (libc.so.6:strlen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x4928bb0 (libc.so.6:memrchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x4920850 (libc.so.6:strcasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x49203d0 (libc.so.6:memchr) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x493c930 (libc.so.6:wcslen) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x491fae0 (libc.so.6:strspn) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x4920750 (libc.so.6:stpncpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x49206f0 (libc.so.6:stpcpy) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x4921c90 (libc.so.6:strchrnul) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x49208a0 (libc.so.6:strncasecmp_l) redirected to 0x48311d0 (_vgnU_ifunc_wrapper) +--7744-- REDIR: 0x49318c0 (libc.so.6:__strrchr_sse2) redirected to 0x483ea70 (__strrchr_sse2) +--7744-- REDIR: 0x491a0e0 (libc.so.6:malloc) redirected to 0x483b780 (malloc) +--7744-- REDIR: 0x491bb10 (libc.so.6:calloc) redirected to 0x483dce0 (calloc) +--7744-- REDIR: 0x49316b0 (libc.so.6:__strchrnul_sse2) redirected to 0x4843540 (strchrnul) +--7744-- REDIR: 0x4931bc0 (libc.so.6:__strlen_sse2) redirected to 0x483efa0 (__strlen_sse2) +--7744-- REDIR: 0x491a6d0 (libc.so.6:free) redirected to 0x483c9d0 (free) +--7744-- REDIR: 0x493bad0 (libc.so.6:memcpy@GLIBC_2.2.5) redirected to 0x4840100 (memcpy@GLIBC_2.2.5) +--7744-- REDIR: 0x491ffa0 (libc.so.6:__GI_strstr) redirected to 0x4843ca0 (__strstr_sse2) +--7744-- REDIR: 0x4a0d790 (libc.so.6:__memcmp_sse4_1) redirected to 0x4842150 (__memcmp_sse4_1) +--7744-- REDIR: 0x492a3b0 (libc.so.6:__strcmp_sse2_unaligned) redirected to 0x483fed0 (strcmp) +--7744-- REDIR: 0x493bab0 (libc.so.6:__mempcpy_sse2_unaligned) redirected to 0x4843660 (mempcpy) +--7744-- REDIR: 0x491ae80 (libc.so.6:realloc) redirected to 0x483df30 (realloc) +--7744-- REDIR: 0x493bf00 (libc.so.6:__memset_sse2_unaligned) redirected to 0x48428e0 (memset) +--7744-- REDIR: 0x492bec0 (libc.so.6:__memchr_sse2) redirected to 0x4840050 (memchr) +--7744-- REDIR: 0x4931480 (libc.so.6:__strchr_sse2) redirected to 0x483eb90 (__strchr_sse2) +--7744-- REDIR: 0x4936b00 (libc.so.6:__strcpy_sse2_unaligned) redirected to 0x483f090 (strcpy) +--7744-- REDIR: 0x4938140 (libc.so.6:__stpcpy_sse2_unaligned) redirected to 0x4842570 (__stpcpy_sse2_unaligned) +==7744== +==7744== HEAP SUMMARY: +==7744== in use at exit: 272 bytes in 1 blocks +==7744== total heap usage: 749 allocs, 748 frees, 2,039,642 bytes allocated +==7744== +==7744== Searching for pointers to 1 not-freed blocks +==7744== Checked 8,477,224 bytes +==7744== +==7744== 272 bytes in 1 blocks are possibly lost in loss record 1 of 1 +==7744== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) +==7744== by 0x40149DA: allocate_dtv (dl-tls.c:286) +==7744== by 0x40149DA: _dl_allocate_tls (dl-tls.c:532) +==7744== by 0x4866322: allocate_stack (allocatestack.c:622) +==7744== by 0x4866322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660) +==7744== by 0x10AA74: initTimer (aesdsocket.c:181) +==7744== by 0x10B867: main (aesdsocket.c:569) +==7744== +==7744== LEAK SUMMARY: +==7744== definitely lost: 0 bytes in 0 blocks +==7744== indirectly lost: 0 bytes in 0 blocks +==7744== possibly lost: 272 bytes in 1 blocks +==7744== still reachable: 0 bytes in 0 blocks +==7744== suppressed: 0 bytes in 0 blocks +==7744== +==7744== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)