summaryrefslogtreecommitdiff
path: root/libpipe/pq.c
diff options
context:
space:
mode:
authorMarcus Brinkmann <marcus@gnu.org>2002-04-22 20:06:40 +0000
committerMarcus Brinkmann <marcus@gnu.org>2002-04-22 20:06:40 +0000
commit203a6eaf044d39c289cd76f06c7d2f8841a72038 (patch)
tree7b35af95cdddaa51993749534f4081a6fe3f3b30 /libpipe/pq.c
parentff37b9ba6d994c897a5fecdb63ce8c20e095ba98 (diff)
2002-04-22 Marcus Brinkmann <marcus@gnu.org>
* pq.c (packet_set_ports): Correctly replace old ports buffer with new one. Take size of mach_port_t rather than pointer to it. (packet_read_ports): Take size of mach_port_t rather than pointer to it. (pq_queue): Update PACKET->num_ports, PACKET->buf_start and PACKET->buf_end for reused packets as well. Submitted by Ognyan Kulev <ogi@fmi.uni-sofia.bg>.
Diffstat (limited to 'libpipe/pq.c')
-rw-r--r--libpipe/pq.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/libpipe/pq.c b/libpipe/pq.c
index 07196000..9267a3cd 100644
--- a/libpipe/pq.c
+++ b/libpipe/pq.c
@@ -127,13 +127,15 @@ pq_queue (struct pq *pq, unsigned type, void *source)
packet->buf = 0;
packet->buf_len = 0;
packet->ports = 0;
- packet->num_ports = packet->ports_alloced = 0;
- packet->buf_start = packet->buf_end = packet->buf;
+ packet->ports_alloced = 0;
packet->buf_vm_alloced = 0;
}
else
pq->free = packet->next;
+ packet->num_ports = 0;
+ packet->buf_start = packet->buf_end = packet->buf;
+
packet->type = type;
packet->source = source;
packet->next = 0;
@@ -295,13 +297,14 @@ packet_set_ports (struct packet *packet,
packet_dealloc_ports (packet);
if (num_ports > packet->ports_alloced)
{
- mach_port_t *new_ports = malloc (sizeof (mach_port_t *) * num_ports);
+ mach_port_t *new_ports = malloc (sizeof (mach_port_t) * num_ports);
if (! new_ports)
return ENOMEM;
free (packet->ports);
+ packet->ports = new_ports;
packet->ports_alloced = num_ports;
}
- bcopy (ports, packet->ports, sizeof (mach_port_t *) * num_ports);
+ bcopy (ports, packet->ports, sizeof (mach_port_t) * num_ports);
packet->num_ports = num_ports;
return 0;
}
@@ -312,7 +315,7 @@ error_t
packet_read_ports (struct packet *packet,
mach_port_t **ports, size_t *num_ports)
{
- int length = packet->num_ports * sizeof (mach_port_t *);
+ int length = packet->num_ports * sizeof (mach_port_t);
if (*num_ports < packet->num_ports)
{
*ports = mmap (0, length, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0);