Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

Commit

Permalink
slirp: use exit notifier for slirp_smb_cleanup
Browse files Browse the repository at this point in the history
We would like to move back net_cleanup() at the end of main function,
like it used to be until f30dbae, but minimum
cleanup is needed regardless at exit() time for slirp's SMB
functionality.  Use an exit notifier to call slirp_smb_cleanup.
If net_cleanup() is called first, then remove the exit notifier as it
will become a dangling pointer otherwise.

Reviewed-by: Marc-André Lureau <[email protected]>
Reviewed-by: Jason Wang <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
bonzini committed Jul 13, 2016
1 parent 9e32ff3 commit f6c2e66
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions net/slirp.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "slirp/libslirp.h"
#include "slirp/ip6.h"
#include "sysemu/char.h"
#include "sysemu/sysemu.h"
#include "qemu/cutils.h"

static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
Expand Down Expand Up @@ -76,6 +77,7 @@ typedef struct SlirpState {
NetClientState nc;
QTAILQ_ENTRY(SlirpState) entry;
Slirp *slirp;
Notifier exit_notifier;
#ifndef _WIN32
char smb_dir[128];
#endif
Expand Down Expand Up @@ -118,11 +120,18 @@ static ssize_t net_slirp_receive(NetClientState *nc, const uint8_t *buf, size_t
return size;
}

static void slirp_smb_exit(Notifier *n, void *data)
{
SlirpState *s = container_of(n, SlirpState, exit_notifier);
slirp_smb_cleanup(s);
}

static void net_slirp_cleanup(NetClientState *nc)
{
SlirpState *s = DO_UPCAST(SlirpState, nc, nc);

slirp_cleanup(s->slirp);
qemu_remove_exit_notifier(&s->exit_notifier);
slirp_smb_cleanup(s);
QTAILQ_REMOVE(&slirp_stacks, s, entry);
}
Expand Down Expand Up @@ -349,6 +358,8 @@ static int net_slirp_init(NetClientState *peer, const char *model,
}
#endif

s->exit_notifier.notify = slirp_smb_exit;
qemu_add_exit_notifier(&s->exit_notifier);
return 0;

error:
Expand Down

0 comments on commit f6c2e66

Please sign in to comment.