[spice-gtk,v2,18/33] fixup! usb-redir: add files for SCSI and USB MSC implementation

Submitted by Frediano Ziglio on Aug. 9, 2019, 2:26 p.m.

Details

Message ID 20190809142651.2967-19-fziglio@redhat.com
State Superseded
Headers show
Series "CD emulation follow ups" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Frediano Ziglio Aug. 9, 2019, 2:26 p.m.
Retain stream using reference counting.
Allow caller to free the object.
---
 src/cd-scsi.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/cd-scsi.c b/src/cd-scsi.c
index f9e8441c..1cb268bf 100644
--- a/src/cd-scsi.c
+++ b/src/cd-scsi.c
@@ -433,6 +433,7 @@  void cd_scsi_target_free(CdScsiTarget *st)
         if (unit->realized) {
             cd_scsi_dev_unrealize(st, lun);
         }
+        g_clear_object(&unit->stream);
     }
     g_clear_object(&st->cancellable);
     g_free(st);
@@ -497,7 +498,7 @@  int cd_scsi_dev_realize(CdScsiTarget *st, uint32_t lun,
 static void cd_scsi_lu_media_reset(CdScsiLU *dev)
 {
     /* media_event is not set here, as it depends on the context */
-    dev->stream = NULL;
+    g_clear_object(&dev->stream);
     dev->size = 0;
     dev->block_size = 0;
     dev->num_blocks = 0;
@@ -526,7 +527,7 @@  static void cd_scsi_lu_load(CdScsiLU *dev,
 {
     if (media_params != NULL) {
         dev->media_event = CD_MEDIA_EVENT_NEW_MEDIA;
-        dev->stream = media_params->stream;
+        dev->stream = g_object_ref(media_params->stream);
         dev->size = media_params->size;
         dev->block_size = media_params->block_size;
         dev->num_blocks = media_params->size / media_params->block_size;