diff --git a/Makefile b/Makefile index d069ff1..b978a24 100644 --- a/Makefile +++ b/Makefile @@ -100,7 +100,7 @@ print-%: ; @echo $* = $($*) # -TESTS------------------------------------------------------------------------ test1: all - @echo "[threadpool]\n\nquantity = 1\npending = 10\n\n[files]\n\nMaxFiles = 10000\nMaxSize = 128000\n\n[log]\n\nlogFile = ./logs/l.log\n\n[socket]\n\nname = ./socket\nbacklog = 100\n" > build/confix.txt + @echo "[threadpool]\n\nquantity = 1\npending = 10\n\n[files]\n\nMaxFiles = 10000\nMaxSize = 128000000\n\n[log]\n\nlogFile = ./logs/l.log\n\n[socket]\n\nname = ./socket\nbacklog = 100\n" > build/confix.txt valgrind --leak-check=full --track-origins=yes $(BUILD_DIR)/server & bash scripts/test1.sh pkill -1 memcheck-amd64 diff --git a/lib/api/api.c b/lib/api/api.c index bc1a00c..aa8eb10 100644 --- a/lib/api/api.c +++ b/lib/api/api.c @@ -1147,7 +1147,8 @@ int removeFile(const char* pathname) { } else { openedFiles->numOfFiles--; } - + freeResponse(res); + free(res); free(cmd); return 0; } diff --git a/lib/threadpool/apiFile.c b/lib/threadpool/apiFile.c index 7ac2176..c5610f2 100644 --- a/lib/threadpool/apiFile.c +++ b/lib/threadpool/apiFile.c @@ -733,7 +733,7 @@ void removeFile(char *filepath, queueT *q, long fd_c, taglia_t *taglia, pthread_ } if (removeFileFromQueue(q, filepath, fd_c) == -1) { - n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una removeFile sul file \"%s\" e' terminata con errore.\n", fd_c, filepath); + n += snprintf(tmp_buf+n, m-n, "Client %ld ha richiesto una removeFile sul file \"%s\" e' terminata con errore del server.\n", fd_c, filepath); serror(MENT, fd_c, taglia, tmp_buf); return; } diff --git a/lib/threadpool/fileQueue.c b/lib/threadpool/fileQueue.c index bba91db..76ae637 100644 --- a/lib/threadpool/fileQueue.c +++ b/lib/threadpool/fileQueue.c @@ -682,8 +682,8 @@ int removeFileFromQueue(queueT *q, char *filepath, int owner) { goto _end_remove_file_queue; } - if ((tmp->data)->open != 0 || ((tmp->data)->O_LOCK && (tmp->data)->owner != owner)) { - // if file è aperto o la lock non è del owner + if (((tmp->data)->O_LOCK) && ((tmp->data)->owner != owner)) { + // if lock non è del owner errno = EPERM; goto _end_remove_file_queue; } diff --git a/scripts/test1.sh b/scripts/test1.sh index 6ab29d0..88060c4 100644 --- a/scripts/test1.sh +++ b/scripts/test1.sh @@ -1,5 +1,5 @@ #!/bin/sh -./client -t 200 -f socket -w testFiles/1 -D Wdir -W testFiles/1/file1 -r testFiles/1/file1 -d Rdir -R n=3 -p +./build/client -t 200 -f socket -w testFiles/1 -D Wdir -W testFiles/1/file1 -r testFiles/1/file1 -d Rdir -R n=3 -p exit 0 diff --git a/src/client.c b/src/client.c index d087b15..6f4984a 100644 --- a/src/client.c +++ b/src/client.c @@ -838,9 +838,9 @@ int cmd_u(char *filelist, int print) { } // we copy filelist because we are nice - char *tofree = malloc(strnlen(filelist, MAXARGLENGTH)+1); + char *tofree = calloc(strnlen(filelist, MAXARGLENGTH)+1, sizeof(char)); if(!tofree) { - perror("malloc"); + perror("calloc"); return -1; } strncpy(tofree, filelist, strnlen(filelist, MAXARGLENGTH)); @@ -884,9 +884,9 @@ int cmd_c(char *filelist, int print) { } // we copy filelist because we are nice - char *tofree = malloc(strnlen(filelist, MAXARGLENGTH)+1); + char *tofree = calloc(strnlen(filelist, MAXARGLENGTH)+1, sizeof(char)); if(!tofree) { - perror("malloc"); + perror("calloc"); return -1; } strncpy(tofree, filelist, strnlen(filelist, MAXARGLENGTH));