From 2fb741046d127c8eb77257c2e8949ac18a239bdc Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Fri, 4 Mar 2022 18:28:30 -0800 Subject: [PATCH] PDP11 & VAX: Avoid RQ DEVICE uname memory leaks Additional UNITs from 4 up to 254 are replicated from Unit 0. If the UNIT->uname has already been populated, we could leak memory if it isn't released before copying from the template UNIT. --- PDP11/pdp11_rq.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/PDP11/pdp11_rq.c b/PDP11/pdp11_rq.c index 9e75a992..4d0bc827 100644 --- a/PDP11/pdp11_rq.c +++ b/PDP11/pdp11_rq.c @@ -3029,9 +3029,13 @@ if (!plugs_inited ) { rq_devmap[i]->units[RQ_QUEUE].flags = UNIT_DIS; sprintf (uname, "%s-QUESVC", rq_devmap[i]->name); sim_set_uname (&rq_devmap[i]->units[RQ_QUEUE], uname); + free (rq_devmap[i]->units[0].uname); /* We're going to use unit 0 as a template for extended units */ + rq_devmap[i]->units[0].uname = NULL; /* free the only potentially allocated pointer in the structure */ for (d = 0; d < rq_devmap[i]->numunits - 2; d++) { if (d >= RQ_NUMDR) { - rq_devmap[i]->units[d] = rq_devmap[i]->units[0]; + free (rq_devmap[i]->units[d].uname); /* Make sure to not lose a populated uname pointer */ + rq_devmap[i]->units[d].uname = NULL; + rq_devmap[i]->units[d] = rq_devmap[i]->units[0]; /* Overwrite additional unit with unit0 as a template */ rq_devmap[i]->units[d].flags |= UNIT_DIS; rq_devmap[i]->units[d].flags &= ~UNIT_DISABLE; }