Skip to content
Open
Changes from all commits
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
9 changes: 3 additions & 6 deletions sf-pcapng.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ read_block(FILE *fp, pcap_t *p, struct block_cursor *cursor, char *errbuf)
return (-1);
}
p->buffer = bigger_buffer;
p->bufsize = bhdr.total_length;
}

/*
Expand Down Expand Up @@ -902,9 +903,7 @@ pcap_ng_check_header(const uint8_t *magic, FILE *fp, u_int precision,
default:
snprintf(errbuf, PCAP_ERRBUF_SIZE,
"unknown time stamp resolution %u", precision);
free(p);
*err = 1;
return (NULL);
goto fail;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure there's a leak there, as nothing other than the pcap_t-plus-private-data was allocated, and it's freed, but this is good practice anyway in case the code changes - the resource deallocation is, at least, centralized.

(This is not one of C's strengths.)

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.

Agreed. Even if the secondary allocations havent occurred yet at this specific point, funneling everything through a centralized goto fail block removes a major footgun for future modifications. And yes, definitely not one of C's strengths!

}

p->opt.tstamp_precision = precision;
Expand All @@ -931,9 +930,7 @@ pcap_ng_check_header(const uint8_t *magic, FILE *fp, u_int precision,
p->buffer = malloc(p->bufsize);
if (p->buffer == NULL) {
snprintf(errbuf, PCAP_ERRBUF_SIZE, "out of memory");
free(p);
*err = 1;
return (NULL);
goto fail;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ditto.

}
ps->max_blocksize = INITIAL_MAX_BLOCKSIZE;

Expand Down