Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pistache
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
pistache
Commits
2be5c97d
Commit
2be5c97d
authored
Jan 01, 2019
by
Dennis Jenkins
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed memory leak of 'struct addrinfo' from ::getaddrinfo() in Listener::bind().
parent
c390b975
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
4 deletions
+41
-4
include/pistache/net.h
include/pistache/net.h
+36
-0
src/server/listener.cc
src/server/listener.cc
+5
-4
No files found.
include/pistache/net.h
View file @
2be5c97d
...
@@ -26,6 +26,42 @@
...
@@ -26,6 +26,42 @@
namespace
Pistache
{
namespace
Pistache
{
// Wrapper around 'getaddrinfo()' that handles cleanup on destruction.
class
AddrInfo
{
public:
// Disable copy and assign.
AddrInfo
(
const
AddrInfo
&
)
=
delete
;
AddrInfo
&
operator
=
(
const
AddrInfo
&
)
=
delete
;
// Default construction: do nothing.
AddrInfo
()
:
addrs
(
nullptr
)
{}
~
AddrInfo
()
{
if
(
addrs
)
{
::
freeaddrinfo
(
addrs
);
}
}
// Call "::getaddrinfo()", but stash result locally. Takes the same args
// as the first 3 args to "::getaddrinfo()" and returns the same result.
int
invoke
(
const
char
*
node
,
const
char
*
service
,
const
struct
addrinfo
*
hints
)
{
if
(
addrs
)
{
::
freeaddrinfo
(
addrs
);
addrs
=
nullptr
;
}
return
::
getaddrinfo
(
node
,
service
,
hints
,
&
addrs
);
}
const
struct
addrinfo
*
get_info_ptr
()
const
{
return
addrs
;
}
private:
struct
addrinfo
*
addrs
;
};
class
Port
{
class
Port
{
public:
public:
Port
(
uint16_t
port
=
0
);
Port
(
uint16_t
port
=
0
);
...
...
src/server/listener.cc
View file @
2be5c97d
...
@@ -189,13 +189,14 @@ Listener::bind(const Address& address) {
...
@@ -189,13 +189,14 @@ Listener::bind(const Address& address) {
const
auto
&
host
=
addr_
.
host
();
const
auto
&
host
=
addr_
.
host
();
const
auto
&
port
=
addr_
.
port
().
toString
();
const
auto
&
port
=
addr_
.
port
().
toString
();
struct
addrinfo
*
addrs
;
AddrInfo
addr_info
;
TRY
(
::
getaddrinfo
(
host
.
c_str
(),
port
.
c_str
(),
&
hints
,
&
addrs
));
TRY
(
addr_info
.
invoke
(
host
.
c_str
(),
port
.
c_str
(),
&
hints
));
int
fd
=
-
1
;
int
fd
=
-
1
;
addrinfo
*
add
r
;
const
addrinfo
*
addr
=
nullpt
r
;
for
(
addr
=
addr
s
;
addr
;
addr
=
addr
->
ai_next
)
{
for
(
addr
=
addr
_info
.
get_info_ptr
()
;
addr
;
addr
=
addr
->
ai_next
)
{
fd
=
::
socket
(
addr
->
ai_family
,
addr
->
ai_socktype
,
addr
->
ai_protocol
);
fd
=
::
socket
(
addr
->
ai_family
,
addr
->
ai_socktype
,
addr
->
ai_protocol
);
if
(
fd
<
0
)
continue
;
if
(
fd
<
0
)
continue
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment