Skip to content

Commit

Permalink
NO LEAKS, WORKS. changed socklen_t * to socklen_t
Browse files Browse the repository at this point in the history
  • Loading branch information
skjdbg committed Oct 18, 2019
1 parent 7b443bf commit 5f0a334
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 19 deletions.
5 changes: 3 additions & 2 deletions headers/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#endif


typedef struct client {
/**
* Is the client actively exchanging data?
Expand All @@ -42,7 +43,7 @@ typedef struct client {
struct sockaddr_in6 *address;

/** Client address length */
socklen_t *addr_len;
socklen_t addr_len;

/** Current client receive window */
buf_t *window;
Expand All @@ -52,7 +53,7 @@ typedef struct client {

GETSET(client_t, FILE *, out_file);
GETSET(client_t, struct sockaddr_in6 *, address);
GETSET(client_t, socklen_t *, addr_len);
GETSET(client_t, socklen_t, addr_len);
GETSET(client_t, buf_t *, window);
GETSET(client_t, uint32_t, id);

Expand Down
2 changes: 1 addition & 1 deletion headers/receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ typedef struct receive_thread_config {
/** Socket file descriptor */
int sockfd;

socklen_t *addr_len;
socklen_t addr_len;

/** Maximum number of clients */
int max_clients;
Expand Down
17 changes: 4 additions & 13 deletions src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ GETSET_IMPL(client_t, FILE *, out_file);

GETSET_IMPL(client_t, struct sockaddr_in6 *, address);

GETSET_IMPL(client_t, socklen_t *, addr_len);
GETSET_IMPL(client_t, socklen_t, addr_len);

GETSET_IMPL(client_t, uint32_t, id);

#define SIZE_SOCKADDR_IN6 sizeof(struct sockaddr_in6)

pthread_mutex_t *client_get_lock(client_t *self) {
return self->lock;
Expand Down Expand Up @@ -77,19 +78,11 @@ int initialize_client(client_t *client, uint32_t id, char *format) {
return -1;
}

client->addr_len = (socklen_t *) malloc(sizeof(socklen_t));
if(client->addr_len == NULL) {
free(client->address);
pthread_mutex_destroy(client->lock);
free(client->lock);
free(client);
errno = FAILED_TO_ALLOCATE;
return -1;
}
//TODO
client->addr_len = SIZE_SOCKADDR_IN6;

client->window = (buf_t *) malloc(sizeof(buf_t));
if(client->window == NULL){
free(client->addr_len);
free(client->address);
pthread_mutex_destroy(client->lock);
free(client->lock);
Expand All @@ -99,7 +92,6 @@ int initialize_client(client_t *client, uint32_t id, char *format) {
}

if(initialize_buffer(client->window, &allocate_packet) != 0) {
free(client->addr_len);
free(client->address);
pthread_mutex_destroy(client->lock);
free(client->lock);
Expand All @@ -126,7 +118,6 @@ void deallocate_client(client_t *client, bool dealloc_addr, bool close_file) {

if (dealloc_addr) {
free(client->address);
free(client->addr_len);
}

if (close_file) {
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ int main(int argc, char *argv[]) {
rx_config->stop = false;
rx_config->rx = hd_to_rx;
rx_config->tx = rx_to_hd;
rx_config->addr_len = &config.addr_info->ai_addrlen;
rx_config->addr_len = sizeof(struct sockaddr_in6);

tx_config->send_rx = hd_to_tx;
tx_config->send_tx = tx_to_hd;
Expand Down
3 changes: 1 addition & 2 deletions src/receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void *receive_thread(void *receive_config) {
req = (hd_req_t *) node->content;
}

req->length = recvfrom(rcv_cfg->sockfd, req->buffer, buf_size, 0, (struct sockaddr *) &sockaddr, rcv_cfg->addr_len);
req->length = recvfrom(rcv_cfg->sockfd, req->buffer, buf_size, 0, (struct sockaddr *) &sockaddr, &rcv_cfg->addr_len);
if(req->length == -1) {
switch(errno) {
case EAGAIN:
Expand Down Expand Up @@ -76,7 +76,6 @@ void *receive_thread(void *receive_config) {
break;
}
*contained->address = sockaddr;
*contained->addr_len = addr_len;

ht_put(rcv_cfg->clients, port, ip, (void *) contained);

Expand Down

0 comments on commit 5f0a334

Please sign in to comment.