* daemon/event.c (virEventAddHandleImpl, virEventAddTimeoutImpl):
Change VIR_EXPAND_N to VIR_RESIZE_N.
* daemon/libvirtd.c (qemudDispatchServer): Likewise.
* daemon/libvirtd.h (qemud_server): Add allocation trackers.
---
daemon/event.c | 12 ++++++------
daemon/libvirtd.c | 6 +++---
daemon/libvirtd.h | 1 +
3 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/daemon/event.c b/daemon/event.c
index 77498e8..9ff0b6b 100644
--- a/daemon/event.c
+++ b/daemon/event.c
@@ -113,10 +113,10 @@ int virEventAddHandleImpl(int fd, int events,
EVENT_DEBUG("Add handle fd=%d events=%d cb=%p opaque=%p", fd, events, cb,
opaque);
virEventLock();
if (eventLoop.handlesCount == eventLoop.handlesAlloc) {
- EVENT_DEBUG("Used %zu handle slots, adding %d more",
+ EVENT_DEBUG("Used %zu handle slots, adding at least %d more",
eventLoop.handlesAlloc, EVENT_ALLOC_EXTENT);
- if (VIR_EXPAND_N(eventLoop.handles, eventLoop.handlesAlloc,
- EVENT_ALLOC_EXTENT) < 0) {
+ if (VIR_RESIZE_N(eventLoop.handles, eventLoop.handlesAlloc,
+ eventLoop.handlesCount, EVENT_ALLOC_EXTENT) < 0) {
virEventUnlock();
return -1;
}
@@ -213,10 +213,10 @@ int virEventAddTimeoutImpl(int frequency,
virEventLock();
if (eventLoop.timeoutsCount == eventLoop.timeoutsAlloc) {
- EVENT_DEBUG("Used %zu timeout slots, adding %d more",
+ EVENT_DEBUG("Used %zu timeout slots, adding at least %d more",
eventLoop.timeoutsAlloc, EVENT_ALLOC_EXTENT);
- if (VIR_EXPAND_N(eventLoop.timeouts, eventLoop.timeoutsAlloc,
- EVENT_ALLOC_EXTENT) < 0) {
+ if (VIR_RESIZE_N(eventLoop.timeouts, eventLoop.timeoutsAlloc,
+ eventLoop.timeoutsCount, EVENT_ALLOC_EXTENT) < 0) {
virEventUnlock();
return -1;
}
diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index f0681a7..150bacf 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -1320,7 +1320,8 @@ static int qemudDispatchServer(struct qemud_server *server, struct
qemud_socket
return -1;
}
- if (VIR_EXPAND_N(server->clients, server->nclients, 1) < 0) {
+ if (VIR_RESIZE_N(server->clients, server->nclients_max,
+ server->nclients, 1) < 0) {
VIR_ERROR0(_("Out of memory allocating clients"));
close(fd);
return -1;
@@ -1444,7 +1445,7 @@ static int qemudDispatchServer(struct qemud_server *server, struct
qemud_socket
}
}
- server->clients[server->nclients - 1] = client;
+ server->clients[server->nclients++] = client;
if (server->nclients > server->nactiveworkers &&
server->nactiveworkers < server->nworkers) {
@@ -1468,7 +1469,6 @@ static int qemudDispatchServer(struct qemud_server *server, struct
qemud_socket
if (client)
VIR_FREE(client->rx);
VIR_FREE(client);
- VIR_SHRINK_N(server->clients, server->nclients, 1);
return -1;
}
diff --git a/daemon/libvirtd.h b/daemon/libvirtd.h
index 8d7720d..b45a0e1 100644
--- a/daemon/libvirtd.h
+++ b/daemon/libvirtd.h
@@ -267,6 +267,7 @@ struct qemud_server {
size_t nsockets;
struct qemud_socket *sockets;
size_t nclients;
+ size_t nclients_max;
struct qemud_client **clients;
int sigread;
--
1.7.2.1