]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
pool: Destroy enumerator before deleting existing pool
authorTobias Brunner <tobias@strongswan.org>
Mon, 6 Nov 2017 09:29:56 +0000 (10:29 +0100)
committerTobias Brunner <tobias@strongswan.org>
Wed, 8 Nov 2017 15:40:14 +0000 (16:40 +0100)
The MySQL client doesn't like overlapping queries on the same
connection, so we make sure to destroy the enumerator used to check for
an existing pool before deleting it when --replace is used.

src/pool/pool.c

index c0d855b73de5ce3e64e2a1bd154a9f879f9a9b5a..b755365ec078c7f91452b59876bf130de7c0d6e2 100644 (file)
@@ -60,20 +60,22 @@ static u_int create_pool(char *name, chunk_t start, chunk_t end, u_int timeout)
 {
        enumerator_t *e;
        int pool;
+       bool exists;
 
        e = db->query(db, "SELECT id FROM pools WHERE name = ?",
                        DB_TEXT, name, DB_UINT);
-       if (e && e->enumerate(e, &pool))
+       exists = e && e->enumerate(e, &pool);
+       DESTROY_IF(e);
+
+       if (exists)
        {
-               if (replace_pool == FALSE)
+               if (!replace_pool)
                {
                        fprintf(stderr, "pool '%s' exists.\n", name);
-                       e->destroy(e);
                        exit(EXIT_FAILURE);
                }
                del(name);
        }
-       DESTROY_IF(e);
        if (db->execute(db, &pool,
                        "INSERT INTO pools (name, start, end, timeout) VALUES (?, ?, ?, ?)",
                        DB_TEXT, name, DB_BLOB, start, DB_BLOB, end,