Skip to contentSkip to conversation

hw/display/tcx.c: tcx_realizefn: fix memory leak, make FCode loading error fatal and improve error message

PATCH In review Michael Tokarev 2 participants 2 messages May 30, 2015 – Jun 2, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 hw/display/tcx.c: tcx_realizefn: fix memory leak, make FCode loading error fatal and improve error message

---
 hw/display/tcx.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
hw/display/tcx.c +6 -3
index a9f9f66..c2b32c3 100644
@@ -1014,10 +1014,13 @@ static void tcx_realizefn(DeviceState *dev, Error **errp)
     if (fcode_filename) {
         ret = load_image_targphys(fcode_filename, s->prom_addr,
                                   FCODE_MAX_ROM_SIZE);
-        if (ret < 0 || ret > FCODE_MAX_ROM_SIZE) {
-            error_report("tcx: could not load prom '%s'", TCX_ROM_FILE);
-        }
     }
+    if (!fcode_filename || ret < 0 || ret > FCODE_MAX_ROM_SIZE) {
+        error_report("tcx: could not load prom '%s'",
+                     fcode_filename ? fcode_filename : TCX_ROM_FILE);
+        exit(1);
+    }
+    g_free(fcode_filename);
 
     /* 0/DFB8 : 8-bit plane */
     s->vram = vram_base;
Signature · 1 line
2.1.4
Reviewed-by on v1 2/2
#1 lore raw
Quoted 1 line · Michael Tokarev
Quoted 26 lines
---
 hw/display/tcx.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
hw/display/tcx.c +6 -3
index a9f9f66..c2b32c3 100644
@@ -1014,10 +1014,13 @@ static void tcx_realizefn(DeviceState *dev, Error **errp)
     if (fcode_filename) {
         ret = load_image_targphys(fcode_filename, s->prom_addr,
                                   FCODE_MAX_ROM_SIZE);
-        if (ret < 0 || ret > FCODE_MAX_ROM_SIZE) {
-            error_report("tcx: could not load prom '%s'", TCX_ROM_FILE);
-        }
     }
+    if (!fcode_filename || ret < 0 || ret > FCODE_MAX_ROM_SIZE) {
+        error_report("tcx: could not load prom '%s'",
+                     fcode_filename ? fcode_filename : TCX_ROM_FILE);
+        exit(1);
+    }
+    g_free(fcode_filename);
 
     /* 0/DFB8 : 8-bit plane */
     s->vram = vram_base;
Signature · 1 line
Shannon