Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 6 additions & 28 deletions fiche.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ static void dispatch_connection(int socket, Fiche_Settings *settings) {


static void *handle_connection(void *args) {
char *slug = NULL;

// Cast args to it's previous type
struct fiche_connection *c = (struct fiche_connection *) args;
Expand Down Expand Up @@ -569,14 +570,7 @@ static void *handle_connection(void *args) {
print_error("No data received from the client!");
print_separator();

// Close the socket
close(c->socket);

// Cleanup
free(c);
pthread_exit(NULL);

return 0;
goto exit;
}

// - Check if request was performed with a known protocol
Expand All @@ -589,7 +583,6 @@ static void *handle_connection(void *args) {
// TODO

// Generate slug and use it to create an url
char *slug;
uint8_t extra = 0;

do {
Expand All @@ -613,12 +606,7 @@ static void *handle_connection(void *args) {
print_error("Couldn't generate a valid slug!");
print_separator();

// Cleanup
free(c);
free(slug);
close(c->socket);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: This was broken before moving the cleanup to the exit label because it called free(c) before dereferencing c.

pthread_exit(NULL);
return NULL;
goto exit;
}

}
Expand All @@ -630,12 +618,7 @@ static void *handle_connection(void *args) {
print_error("Couldn't generate a slug!");
print_separator();

close(c->socket);

// Cleanup
free(c);
pthread_exit(NULL);
return NULL;
goto exit;
}


Expand All @@ -644,13 +627,7 @@ static void *handle_connection(void *args) {
print_error("Couldn't save a file!");
print_separator();

close(c->socket);

// Cleanup
free(c);
free(slug);
pthread_exit(NULL);
return NULL;
goto exit;
}

// Write a response to the user
Expand All @@ -672,6 +649,7 @@ static void *handle_connection(void *args) {
// TODO: log unsuccessful and rejected connections
log_entry(c->settings, ip, hostname, slug);

exit:
// Close the connection
close(c->socket);

Expand Down