Based on 85529c815b47c22839e0f148af67fd37e977cbfa Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Tue, 12 Aug 2014 19:29:27 +0200
Subject: [PATCH] sd-resolve: fix allocation if query ids, never reuse them

---
 src/libsystemd/sd-resolve/sd-resolve.c |   12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

--- src/libsystemd/sd-resolve/sd-resolve.c
+++ src/libsystemd/sd-resolve/sd-resolve.c	2014-08-22 14:18:24.838235343 +0000
@@ -81,7 +81,7 @@ struct sd_resolve {
         pthread_t workers[WORKERS_MAX];
         unsigned n_valid_workers;
 
-        unsigned current_id, current_index;
+        unsigned current_id;
         sd_resolve_query* queries[QUERIES_MAX];
         unsigned n_queries;
 
@@ -892,21 +892,17 @@ static int alloc_query(sd_resolve *resol
         if (r < 0)
                 return r;
 
-        while (resolve->queries[resolve->current_index]) {
-                resolve->current_index++;
+        while (resolve->queries[resolve->current_id % QUERIES_MAX])
                 resolve->current_id++;
 
-                resolve->current_index %= QUERIES_MAX;
-        }
-
-        q = resolve->queries[resolve->current_index] = new0(sd_resolve_query, 1);
+        q = resolve->queries[resolve->current_id % QUERIES_MAX] = new0(sd_resolve_query, 1);
         if (!q)
                 return -ENOMEM;
 
         resolve->n_queries++;
 
         q->resolve = resolve;
-        q->id = resolve->current_id;
+        q->id = resolve->current_id++;
 
         *_q = q;
         return 0;