Merge pull request #5 from cozis/claude/fix-valgrind-errors-011CUj8DsxsRQ3Udnyj8Vfv6

Fixes for Valgrind errors by Claude
This commit is contained in:
Francesco Cozzuto
2025-11-02 14:35:25 +01:00
committed by GitHub
3 changed files with 27 additions and 1 deletions
+15
View File
@@ -91,6 +91,9 @@ struct TinyDFS {
Operation operations[MAX_OPERATIONS]; Operation operations[MAX_OPERATIONS];
}; };
// Forward declaration
static void request_queue_init(RequestQueue *reqs);
TinyDFS *tinydfs_init(char *addr, uint16_t port) TinyDFS *tinydfs_init(char *addr, uint16_t port)
{ {
TinyDFS *tdfs = sys_malloc(sizeof(TinyDFS)); TinyDFS *tdfs = sys_malloc(sizeof(TinyDFS));
@@ -118,6 +121,18 @@ TinyDFS *tinydfs_init(char *addr, uint16_t port)
for (int i = 0; i < MAX_OPERATIONS; i++) for (int i = 0; i < MAX_OPERATIONS; i++)
tdfs->operations[i].type = OPERATION_TYPE_FREE; tdfs->operations[i].type = OPERATION_TYPE_FREE;
// Initialize metadata server (connected during init)
tdfs->metadata_server.used = true;
tdfs->metadata_server.addr = addr2;
request_queue_init(&tdfs->metadata_server.reqs);
// Initialize chunk servers array (connections created on demand)
tdfs->num_chunk_servers = 0;
for (int i = 0; i < MAX_CHUNK_SERVERS; i++) {
tdfs->chunk_servers[i].used = false;
// Note: RequestQueue initialized in get_chunk_server_connection()
}
return tdfs; return tdfs;
} }
+3 -1
View File
@@ -319,8 +319,10 @@ int spawn_simulated_process(char *args)
process->num_desc = 0; process->num_desc = 0;
process->num_allocs = 0; process->num_allocs = 0;
for (int i = 0; i < MAX_DESCRIPTORS; i++) for (int i = 0; i < MAX_DESCRIPTORS; i++) {
process->desc[i].type = DESC_EMPTY; process->desc[i].type = DESC_EMPTY;
process->desc[i].generation = 0;
}
void *contexts[MAX_CONNS+1]; void *contexts[MAX_CONNS+1];
struct pollfd polled[MAX_CONNS+1]; struct pollfd polled[MAX_CONNS+1];
+9
View File
@@ -90,6 +90,14 @@ void tcp_context_init(TCP *tcp)
void tcp_context_free(TCP *tcp) void tcp_context_free(TCP *tcp)
{ {
// Free all connection byte queues without closing sockets
// (sockets are managed by the simulation and will be cleaned up separately)
for (int i = 0; i < tcp->num_conns; i++) {
byte_queue_free(&tcp->conns[i].input);
byte_queue_free(&tcp->conns[i].output);
}
tcp->num_conns = 0;
if (tcp->listen_fd != INVALID_SOCKET) if (tcp->listen_fd != INVALID_SOCKET)
CLOSE_SOCKET(tcp->listen_fd); CLOSE_SOCKET(tcp->listen_fd);
} }
@@ -177,6 +185,7 @@ int tcp_register_events(TCP *tcp, void **contexts, struct pollfd *polled)
int tcp_translate_events(TCP *tcp, Event *events, void **contexts, struct pollfd *polled, int num_polled) int tcp_translate_events(TCP *tcp, Event *events, void **contexts, struct pollfd *polled, int num_polled)
{ {
bool removed[MAX_CONNS+1]; bool removed[MAX_CONNS+1];
memset(removed, 0, sizeof(removed));
int num_events = 0; int num_events = 0;
for (int i = 0; i < num_polled; i++) { for (int i = 0; i < num_polled; i++) {