Fix sqlite memory leak issue
[platform/core/telephony/tel-plugin-database.git] / src / database_main.c
index 24ce10f..a96c5ae 100644 (file)
@@ -97,11 +97,16 @@ static gboolean update_query_database(Storage *strg, void *handle, const char *q
 
                        if (rv != SQLITE_OK) {
                                dbg("fail to bind data (%d)", rv);
-                               return FALSE;
+                               break;
                        }
                }
        }
 
+       if (rv != SQLITE_OK) {
+               sqlite3_finalize(stmt);
+               return FALSE;
+       }
+
        rv = sqlite3_step(stmt);
        dbg("update query executed (%d)", rv);
        sqlite3_finalize(stmt);
@@ -149,11 +154,16 @@ static gboolean _read_query_database_internal(Storage *strg, void *handle, const
 
                        if (rv != SQLITE_OK) {
                                dbg("fail to bind data (%d)", rv);
-                               return FALSE;
+                               break;
                        }
                }
        }
 
+       if (rv != SQLITE_OK) {
+               sqlite3_finalize(stmt);
+               return FALSE;
+       }
+
        rv = sqlite3_step(stmt);
        dbg("read query executed (%d), in_order (%d)", rv, in_order);
 
@@ -253,11 +263,16 @@ static gboolean insert_query_database(Storage *strg, void *handle, const char *q
 
                        if (rv != SQLITE_OK) {
                                dbg("fail to bind data (%d)", rv);
-                               return FALSE;
+                               break;
                        }
                }
        }
 
+       if (rv != SQLITE_OK) {
+               sqlite3_finalize(stmt);
+               return FALSE;
+       }
+
        rv = sqlite3_step(stmt);
        dbg("insert query executed (%d)", rv);
        sqlite3_finalize(stmt);
@@ -303,11 +318,16 @@ static gboolean remove_query_database(Storage *strg, void *handle, const char *q
 
                        if (rv != SQLITE_OK) {
                                dbg("fail to bind data (%d)", rv);
-                               return FALSE;
+                               break;
                        }
                }
        }
 
+       if (rv != SQLITE_OK) {
+               sqlite3_finalize(stmt);
+               return FALSE;
+       }
+
        rv = sqlite3_step(stmt);
        dbg("remove query executed (%d)", rv);
        sqlite3_finalize(stmt);