<commit_before>#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>

#include "vm.h"
#include "syscall_net.h"


void net_io_close_handler(vm_t* vm, vm_fd_t* fd)
{
    vm->io.n_io_events -= fd->n_events;
    free(fd->data);
}


void sys_socket(vm_t* vm, uint32_t argv, uint32_t retv)
{
    uint64_t* args = (uint64_t*)deref(argv, 8, vm);
    uint64_t* ret = (uint64_t*)deref(retv, 8, vm);
    if (!args || !ret)
    {
        vm->error_no = EFAULT;
        if (ret) *ret = 1;
        return;
    }

    uint64_t fd = alloc_fd(vm);

    int sockfd = -1;
    errno = 0;
    switch (args[0])
    {
    case SOCK_T_TCP:<commit_msg>memory leak fix<commit_after>#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>

#include "vm.h"
#include "syscall_net.h"


void net_io_close_handler(vm_t* vm, vm_fd_t* fd)
{
    vm->io.n_io_events -= fd->n_events;
    for (uint32_t e = 0; e < fd->n_events; e++)
    {
        vm_io_evt_t* evt = fd->events + e;
        free(evt->data);
    }
    free(fd->data);
}


void sys_socket(vm_t* vm, uint32_t argv, uint32_t retv)
{
    uint64_t* args = (uint64_t*)deref(argv, 8, vm);
    uint64_t* ret = (uint64_t*)deref(retv, 8, vm);
    if (!args || !ret)
    {
        vm->error_no = EFAULT;
        if (ret) *ret = 1;
        return;
    }

    uint64_t fd = alloc_fd(vm);

    int sockfd = -1;
    errno = 0;
    switch (args[0])
    {
    case SOCK_T_TCP:
{'fraction_non_alphanumeric': 0.1693548387096774, 'fraction_numerical': 0.026674937965260544, 'mean_word_length': 2.8404761904761906, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 30, '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': '3071605', 'n_tokens_mistral': 749, 'n_tokens_neox': 707, 'n_words': 147}