Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix SEGFAULT on early exit with IPv6 enabled #97

Merged
merged 3 commits into from
Feb 17, 2024
Merged
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
10 changes: 6 additions & 4 deletions conserver/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ int fAll = 0, fNoinit = 0, fVersion = 0, fStrip = 0, fReopen =
char *pcConfig = CONFIGFILE;
int cMaxMemb = MAXMEMB;
#if USE_IPV6
struct addrinfo *bindAddr;
struct addrinfo *bindBaseAddr;
struct addrinfo *bindAddr = (struct addrinfo *)0;
struct addrinfo *bindBaseAddr = (struct addrinfo *)0;
Copy link
Contributor

Choose a reason for hiding this comment

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

This change is unnecessary. These are globals, and have "static storage duration" and thus are already guaranteed to be initialized to NULL.

In section 3.5.7 of the C89 drafts available onliine:
"If an object that has static storage duration is not initialized explicitly, it is initialized implicitly as if every member that has arithmetic type were assigned 0 and every member that has pointer type were assigned a null pointer constant. "

#else
in_addr_t bindAddr = INADDR_ANY;
unsigned short bindPort;
Expand Down Expand Up @@ -781,8 +781,10 @@ DestroyDataStructures(void)

#if USE_IPV6
/* clean up addrinfo stucts */
freeaddrinfo(bindAddr);
freeaddrinfo(bindBaseAddr);
if ((struct addrinfo *)0 != bindAddr)
Copy link
Contributor

Choose a reason for hiding this comment

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

you don't need the casts. A NULL or 0 in pointer context can be compared against a pointer of any type. See C89 section 3.2.2.3.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, sure. Just trying my best to match the existing code style.

freeaddrinfo(bindAddr);
if ((struct addrinfo *)0 != bindBaseAddr)
freeaddrinfo(bindBaseAddr);
#else
if (myAddrs != (struct in_addr *)0)
free(myAddrs);
Expand Down