diff --git a/common/rpc-service.c b/common/rpc-service.c
index 0cbca4c..6b34a9d 100644
--- a/common/rpc-service.c
+++ b/common/rpc-service.c
@@ -3873,6 +3873,7 @@ seafile_check_repo_blocks_missing (const char *repo_id,
     free (json_data);
     json_decref (ret_json);
     json_decref (array);
+    seaf_repo_unref (repo);
     return ret;
 }
 
diff --git a/common/seaf-db.c b/common/seaf-db.c
index 788c7c8..6176b7c 100644
--- a/common/seaf-db.c
+++ b/common/seaf-db.c
@@ -150,7 +150,7 @@ out:
         for (index = size - 1; index >= 0; index--) {
             d_conn = g_ptr_array_index (pool->connections, index);
             if (d_conn->delete_pending) {
-                g_ptr_array_remove (conn->pool->connections, d_conn);
+                g_ptr_array_remove (pool->connections, d_conn);
                 mysql_db_release_connection (d_conn);
             }
         }