[Spice-devel] [vdagent-win PATCH 09/13] file_xfer: Use shared_ptr to simplify memory management
Christophe Fergeau
cfergeau at redhat.com
Mon May 28 15:03:18 UTC 2018
On Mon, May 28, 2018 at 09:33:11AM -0400, Frediano Ziglio wrote:
> >
> > On Mon, May 28, 2018 at 09:58:02AM +0100, Frediano Ziglio wrote:
> > > Clear automatically tasks items.
> > >
> > > Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> > > ---
> > > vdagent/file_xfer.cpp | 25 ++++---------------------
> > > vdagent/file_xfer.h | 3 ++-
> > > 2 files changed, 6 insertions(+), 22 deletions(-)
> > >
> > > diff --git a/vdagent/file_xfer.cpp b/vdagent/file_xfer.cpp
> > > index e96065b..71b56ed 100644
> > > --- a/vdagent/file_xfer.cpp
> > > +++ b/vdagent/file_xfer.cpp
> > > @@ -41,19 +41,11 @@
> > >
> > > void FileXfer::reset()
> > > {
> > > - FileXferTasks::iterator iter;
> > > - FileXferTask* task;
> > > -
> > > - for (iter = _tasks.begin(); iter != _tasks.end(); iter++) {
> > > - task = iter->second;
> > > - delete task;
> > > - }
> > > _tasks.clear();
> > > }
> > >
> > > FileXfer::~FileXfer()
> > > {
> > > - reset();
> > > }
> > >
> > > void FileXfer::handle_start(VDAgentFileXferStartMessage* start,
> > > @@ -63,7 +55,6 @@ void FileXfer::handle_start(VDAgentFileXferStartMessage*
> > > start,
> > > TCHAR file_path[MAX_PATH];
> > > char file_name[MAX_PATH];
> > > ULARGE_INTEGER free_bytes;
> > > - FileXferTask* task;
> > > uint64_t file_size;
> > > HANDLE handle;
> > > AsUser as_user;
> > > @@ -146,7 +137,7 @@ void
> > > FileXfer::handle_start(VDAgentFileXferStartMessage* start,
> > > vd_printf("Failed creating %ls. More than 63 copies exist?",
> > > file_path);
> > > return;
> > > }
> > > - task = new FileXferTask(handle, file_size, file_path);
> > > + auto task = std::make_shared<FileXferTask>(handle, file_size,
> > > file_path);
> >
> > For what it's worth, I'd stick to FileXferTask * here, and below where
> > you add another 'auto'
> >
>
> No, here is not possible. make_shared returns a std::shard_ptr<FileXferTask>,
> not a FileXferTask,
Ah ok, never mind then, I did not check what this was returning exactly,
and assumed some automatic casting would happen :)
Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20180528/de70574b/attachment.sig>
More information about the Spice-devel
mailing list