From d791913a7f38e1ccb5bb86459feb9bc19b60a82b6199c2fdf9edb88ccc177908 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Sat, 10 Jan 2026 00:06:54 -0500 Subject: [PATCH] Properly manage lifecycle for ClientInfo. --- dpi/file.cc | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/dpi/file.cc b/dpi/file.cc index 6ea9ad3..5f9e752 100644 --- a/dpi/file.cc +++ b/dpi/file.cc @@ -66,14 +66,15 @@ #define FILE_ERR 16 /* Operation error */ -typedef enum { +enum FileState +{ st_start = 10, st_dpip, st_http, st_content, st_done, st_err -} FileState; +}; struct FileInfo { std::string full_path; @@ -891,9 +892,7 @@ static void termination_handler(int signum) */ static ClientInfo *File_add_client(int sock_fd) { - ClientInfo *new_client; - - new_client = new ClientInfo; + auto new_client = std::make_unique< ClientInfo >(); new_client->sh = a_Dpip_dsh_new(sock_fd, sock_fd, 8*1024); new_client->orig_url = NULL; new_client->filename = NULL; @@ -905,9 +904,9 @@ static ClientInfo *File_add_client(int sock_fd) new_client->flags = FILE_READ; new_client->old_style = OLD_STYLE; - dList_append(Clients, new_client); + dList_append(Clients, new_client.get()); - return new_client; + return new_client.release(); } /* @@ -925,7 +924,7 @@ static void File_remove_client(ClientInfo *client) dFree(client->filename); File_dillodir_free(client->d_dir); - dFree(client); + delete client; } /*