diff options
Diffstat (limited to 'net')
-rw-r--r-- | net/vhost-vdpa.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 679ef4bed0..5542b47a8f 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -831,7 +831,16 @@ out: error_report("Bad device CVQ written length"); } vhost_svq_push_elem(svq, elem, MIN(in_len, sizeof(status))); - g_free(elem); + /* + * `elem` belongs to vhost_vdpa_net_handle_ctrl_avail() only when + * the function successfully forwards the CVQ command, indicated + * by a non-negative value of `dev_written`. Otherwise, it still + * belongs to SVQ. + * This function should only free the `elem` when it owns. + */ + if (dev_written >= 0) { + g_free(elem); + } return dev_written < 0 ? dev_written : 0; } |