Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
edd003b6
Commit
edd003b6
authored
Oct 01, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib/nfs/Connection: fix memory leak when cancelling Open()
Close the newly allocated file handle passed to the callback.
parent
10cc87e4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
5 deletions
+23
-5
Connection.cxx
src/lib/nfs/Connection.cxx
+11
-3
Connection.hxx
src/lib/nfs/Connection.hxx
+12
-2
No files found.
src/lib/nfs/Connection.cxx
View file @
edd003b6
...
...
@@ -94,6 +94,14 @@ NfsConnection::CancellableCallback::Callback(int err, void *data)
cb
.
OnNfsError
(
Error
(
nfs_domain
,
err
,
(
const
char
*
)
data
));
}
else
{
if
(
open
)
{
/* a nfs_open_async() call was cancelled - to
avoid a memory leak, close the newly
allocated file handle immediately */
struct
nfsfh
*
fh
=
(
struct
nfsfh
*
)
data
;
connection
.
Close
(
fh
);
}
connection
.
callbacks
.
Remove
(
*
this
);
}
}
...
...
@@ -157,7 +165,7 @@ NfsConnection::Open(const char *path, int flags, NfsCallback &callback,
{
assert
(
!
callbacks
.
Contains
(
callback
));
auto
&
c
=
callbacks
.
Add
(
callback
,
*
this
);
auto
&
c
=
callbacks
.
Add
(
callback
,
*
this
,
true
);
if
(
!
c
.
Open
(
context
,
path
,
flags
,
error
))
{
callbacks
.
Remove
(
c
);
return
false
;
...
...
@@ -172,7 +180,7 @@ NfsConnection::Stat(struct nfsfh *fh, NfsCallback &callback, Error &error)
{
assert
(
!
callbacks
.
Contains
(
callback
));
auto
&
c
=
callbacks
.
Add
(
callback
,
*
this
);
auto
&
c
=
callbacks
.
Add
(
callback
,
*
this
,
false
);
if
(
!
c
.
Stat
(
context
,
fh
,
error
))
{
callbacks
.
Remove
(
c
);
return
false
;
...
...
@@ -188,7 +196,7 @@ NfsConnection::Read(struct nfsfh *fh, uint64_t offset, size_t size,
{
assert
(
!
callbacks
.
Contains
(
callback
));
auto
&
c
=
callbacks
.
Add
(
callback
,
*
this
);
auto
&
c
=
callbacks
.
Add
(
callback
,
*
this
,
false
);
if
(
!
c
.
Read
(
context
,
fh
,
offset
,
size
,
error
))
{
callbacks
.
Remove
(
c
);
return
false
;
...
...
src/lib/nfs/Connection.hxx
View file @
edd003b6
...
...
@@ -39,11 +39,21 @@ class NfsConnection : SocketMonitor, DeferredMonitor {
class
CancellableCallback
:
public
CancellablePointer
<
NfsCallback
>
{
NfsConnection
&
connection
;
/**
* Is this a nfs_open_async() operation? If yes, then
* we need to call nfs_close_async() on the new file
* handle as soon as the callback is invoked
* successfully.
*/
const
bool
open
;
public
:
explicit
CancellableCallback
(
NfsCallback
&
_callback
,
NfsConnection
&
_connection
)
NfsConnection
&
_connection
,
bool
_open
)
:
CancellablePointer
<
NfsCallback
>
(
_callback
),
connection
(
_connection
)
{}
connection
(
_connection
),
open
(
_open
)
{}
bool
Open
(
nfs_context
*
context
,
const
char
*
path
,
int
flags
,
Error
&
error
);
...
...
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