[spice-gtk,v2,17/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-18-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.
Free all possible data in cd_scsi_target_free.
Avoid some leaks.
---
 src/cd-scsi.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/cd-scsi.c b/src/cd-scsi.c
index 66e4ddef..f9e8441c 100644
--- a/src/cd-scsi.c
+++ b/src/cd-scsi.c
@@ -423,10 +423,19 @@  CdScsiTarget *cd_scsi_target_alloc(void *target_user_data, uint32_t max_luns)
     return st;
 }
 
-void cd_scsi_target_free(CdScsiTarget *scsi_target)
+void cd_scsi_target_free(CdScsiTarget *st)
 {
-    cd_scsi_target_reset(scsi_target);
-    g_free(scsi_target);
+    uint32_t lun;
+
+    cd_scsi_target_reset(st);
+    for (lun = 0; lun < st->max_luns; lun++) {
+        CdScsiLU *unit = &st->units[lun];
+        if (unit->realized) {
+            cd_scsi_dev_unrealize(st, lun);
+        }
+    }
+    g_clear_object(&st->cancellable);
+    g_free(st);
 }
 
 /* SCSI Device */