<commit_before>#include <pthread.h>
#include <semaphore.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include "traffic-shared.h"
#define LISTEN_MAX 8
#define MAXLINE 256

/* cleans up the zombie processes */
void* clean(void* v)
{
  sem_t* count = v;
  int pid, status;
  while(1)
  {
    /* waits for a new process to be spawned */
    sem_wait(count);
    /* waits for that process to finish */
    pid = wait(&status);
    /* a child process has finished, rinse and repeat */
    printf("server: connection of %d closed with status %d\n", pid, status);
  }
}

struct request_node {
  size_t seq;
  uint64_t read_start, read_end;
  struct request_node *next;
};

struct request_list {
  struct request_node *head, *tail;
} NEW_LIST = {NULL, NULL};

struct request_list remove_request(struct request_list list) {
  list.head = list.head->next;
  if (!list.head) {
    list.tail = NULL;
  }
  return list;
}

struct request_list append_request(struct request_list list, size_t seq, uint64_t readStart, uint64_t readEnd) {
  struct request_node *node = malloc(sizeof(struct request_node));
  node->seq = seq;
  node->read_start = readStart;
  node->read_end = readEnd;
  node->next = NULL;

  if (list.tail) {
    list.tail->next = node;
    list.tail = node;
  } else {
    list.head = list.tail = node;
  }
  return list;
}

int respond(int connfd, size_t port)
{
  struct setup_header setupBuffer;
  struct request_list requests = NEW_LIST;
  size_t  bytesRead = 0, requestCount = 0, bytesWritten = 0, responseCount = 0;
  ssize_t n;
  uint64_t readStart = 0, readEnd, writeStart = 0, writeEnd;
  struct request_header * requestBuffer;
  struct response_header * responseBuffer;
  fd_set rfds, wfds;
<commit_msg>Fixed memory leak<commit_after>#include <pthread.h>
#include <semaphore.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include "traffic-shared.h"
#define LISTEN_MAX 8
#define MAXLINE 256

/* cleans up the zombie processes */
void* clean(void* v)
{
  sem_t* count = v;
  int pid, status;
  while(1)
  {
    /* waits for a new process to be spawned */
    sem_wait(count);
    /* waits for that process to finish */
    pid = wait(&status);
    /* a child process has finished, rinse and repeat */
    printf("server: connection of %d closed with status %d\n", pid, status);
  }
}

struct request_node {
  size_t seq;
  uint64_t read_start, read_end;
  struct request_node *next;
};

struct request_list {
  struct request_node *head, *tail;
} NEW_LIST = {NULL, NULL};

struct request_list remove_request(struct request_list list) {
  struct request_node * oldHead = list.head;
  list.head = list.head->next;
  if (!list.head) {
    list.tail = NULL;
  }
  free(oldHead);
  return list;
}

struct request_list append_request(struct request_list list, size_t seq, uint64_t readStart, uint64_t readEnd) {
  struct request_node *node = malloc(sizeof(struct request_node));
  node->seq = seq;
  node->read_start = readStart;
  node->read_end = readEnd;
  node->next = NULL;

  if (list.tail) {
    list.tail->next = node;
    list.tail = node;
  } else {
    list.head = list.tail = node;
  }
  return list;
}

int respond(int connfd, size_t port)
{
  struct setup_header setupBuffer;
  struct request_list requests = NEW_LIST;
  size_t  bytesRead = 0, requestCount = 0, bytesWritten = 0, responseCount = 0;
  ssize_t n;
  uint64_t readStart = 0, readEnd, writeStart = 0, writeEnd;
  struct request_header * requestBuffer;
  struct response_header * responseBuffer;
  fd_set rfds, wfds;

{'fraction_non_alphanumeric': 0.12157172995780591, 'fraction_numerical': 0.010021097046413503, 'mean_word_length': 3.8195679796696314, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6671452', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1347, 'n_words': 381}