Commit 0b7e64ea authored by Štěpán Balážik's avatar Štěpán Balážik

fix files left open

parent 367725d6
......@@ -1776,17 +1776,17 @@ union swrap_packet_payload {
static const char *swrap_pcap_init_file(void)
{
static int initialized = 0;
static const char *s = NULL;
static const struct swrap_file_hdr h;
static const struct swrap_packet_frame f;
static const union swrap_packet_ip i;
static const union swrap_packet_payload p;
if (initialized == 1) {
return s;
}
initialized = 1;
// if (initialized == 1) {
// printf("return: 1\n");
// return s;
// }
// initialized = 1;
/*
* TODO: don't use the structs use plain buffer offsets
......@@ -2071,9 +2071,9 @@ static uint8_t *swrap_pcap_packet_init(struct timeval *tval,
static int swrap_pcap_get_fd(const char *fname)
{
static int fd = -1;
int fd = -1;
if (fd != -1) return fd;
// if (fd != -1) return fd;
fd = libc_open(fname, O_WRONLY|O_CREAT|O_EXCL|O_APPEND, 0644);
if (fd != -1) {
......@@ -2400,11 +2400,12 @@ static void swrap_pcap_dump_packet(struct socket_info *si,
fd = swrap_pcap_get_fd(file_name);
if (fd != -1) {
if (write(fd, packet, packet_len) != (ssize_t)packet_len) {
close(fd);
free(packet);
return;
}
}
close(fd);
free(packet);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment