From 4b36edf684b49eb5584f8f0c5aff3dd7aac2c834 Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Tue, 5 Jun 2018 20:31:45 +0200
Subject: Released the mutex even in case of register loading failure.

---
 plugins/arm/v7/registers/banked.c  | 7 ++++---
 plugins/arm/v7/registers/basic.c   | 7 ++++---
 plugins/arm/v7/registers/coproc.c  | 7 ++++---
 plugins/arm/v7/registers/simd.c    | 7 ++++---
 plugins/arm/v7/registers/special.c | 7 ++++---
 5 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/plugins/arm/v7/registers/banked.c b/plugins/arm/v7/registers/banked.c
index bce48dd..72274a6 100644
--- a/plugins/arm/v7/registers/banked.c
+++ b/plugins/arm/v7/registers/banked.c
@@ -683,11 +683,12 @@ static GArchRegister *get_armv7_banked_register(BankedRegisterTarget target)
 
     result = _armv7_banked_registers[target];
 
-    G_UNLOCK(_av7_banked_reg_mutex);
+ bad_values:
 
-    g_object_ref(G_OBJECT(result));
+    G_UNLOCK(_av7_banked_reg_mutex);
 
- bad_values:
+    if (result != NULL)
+        g_object_ref(G_OBJECT(result));
 
     return result;
 
diff --git a/plugins/arm/v7/registers/basic.c b/plugins/arm/v7/registers/basic.c
index aed9001..7194c7f 100644
--- a/plugins/arm/v7/registers/basic.c
+++ b/plugins/arm/v7/registers/basic.c
@@ -418,11 +418,12 @@ static GArchRegister *get_armv7_basic_register(uint8_t index)
 
     result = _armv7_basic_registers[index];
 
-    G_UNLOCK(_av7_basic_reg_mutex);
+ bad_index:
 
-    g_object_ref(G_OBJECT(result));
+    G_UNLOCK(_av7_basic_reg_mutex);
 
- bad_index:
+    if (result != NULL)
+        g_object_ref(G_OBJECT(result));
 
     return result;
 
diff --git a/plugins/arm/v7/registers/coproc.c b/plugins/arm/v7/registers/coproc.c
index f1dc3bc..f13a7aa 100644
--- a/plugins/arm/v7/registers/coproc.c
+++ b/plugins/arm/v7/registers/coproc.c
@@ -398,11 +398,12 @@ static GArchRegister *get_armv7_cp_register(uint8_t index)
 
     result = _armv7_cp_registers[index];
 
-    G_UNLOCK(_av7_cp_reg_mutex);
+ bad_index:
 
-    g_object_ref(G_OBJECT(result));
+    G_UNLOCK(_av7_cp_reg_mutex);
 
- bad_index:
+    if (result != NULL)
+        g_object_ref(G_OBJECT(result));
 
     return result;
 
diff --git a/plugins/arm/v7/registers/simd.c b/plugins/arm/v7/registers/simd.c
index 1a71fc7..d762d90 100644
--- a/plugins/arm/v7/registers/simd.c
+++ b/plugins/arm/v7/registers/simd.c
@@ -486,11 +486,12 @@ static GArchRegister *get_armv7_simd_register(SIMDRegisterMapping mapping, uint8
 
     result = _armv7_simd_registers[mapping][index];
 
-    G_UNLOCK(_av7_simd_reg_mutex);
+ bad_index:
 
-    g_object_ref(G_OBJECT(result));
+    G_UNLOCK(_av7_simd_reg_mutex);
 
- bad_index:
+    if (result != NULL)
+        g_object_ref(G_OBJECT(result));
 
     return result;
 
diff --git a/plugins/arm/v7/registers/special.c b/plugins/arm/v7/registers/special.c
index ce3d859..8f80c71 100644
--- a/plugins/arm/v7/registers/special.c
+++ b/plugins/arm/v7/registers/special.c
@@ -442,11 +442,12 @@ static GArchRegister *get_armv7_special_register(SpecRegTarget target)
 
     result = _armv7_special_registers[target];
 
-    G_UNLOCK(_av7_special_reg_mutex);
+ bad_index:
 
-    g_object_ref(G_OBJECT(result));
+    G_UNLOCK(_av7_special_reg_mutex);
 
- bad_index:
+    if (result != NULL)
+        g_object_ref(G_OBJECT(result));
 
     return result;
 
-- 
cgit v0.11.2-87-g4458