mirror of
https://github.com/open-simh/simh.git
synced 2026-01-25 19:57:36 +00:00
sim_disk.c: only free filebuf if it was allocated here too.
PDP11/pdp11_rq.c re-uses ->filebuf as a sector buffer (under the #defined name rqxb) and allocates it as such. If an RQ disk is detached and another attached, this buffer would be lost and the pointer reset to NULL. sim_disk.c would only allocate the buffer if UNIT_BUFABLE is set, which means to buffer the whole disk. Since this rightly isn't set on RQ disks, the pointer would remain NULL and segfaults would ensue. See open-simh issue 274. add comment about safe re-use of filebuf
This commit is contained in:
committed by
Paul Koning
parent
1e371e7c98
commit
86ffe4bec2
10
sim_disk.c
10
sim_disk.c
@@ -3380,12 +3380,14 @@ if ((uptr->flags & UNIT_BUF) && (uptr->filebuf)) {
|
||||
sim_messagef (SCPE_OK, "%s: writing buffer to file: %s\n", sim_uname (uptr), uptr->filename);
|
||||
sim_disk_wrsect (uptr, 0, (uint8 *)uptr->filebuf, NULL, (cap + ctx->sector_size - 1) / ctx->sector_size);
|
||||
}
|
||||
if (uptr->flags & UNIT_MUSTBUF) { /* dyn alloc? */
|
||||
free (uptr->filebuf); /* free buffers */
|
||||
uptr->filebuf = NULL;
|
||||
free (uptr->filebuf2);
|
||||
uptr->filebuf2 = NULL;
|
||||
}
|
||||
uptr->flags = uptr->flags & ~UNIT_BUF;
|
||||
}
|
||||
free (uptr->filebuf); /* free buffers */
|
||||
uptr->filebuf = NULL;
|
||||
free (uptr->filebuf2);
|
||||
uptr->filebuf2 = NULL;
|
||||
|
||||
update_disk_footer (uptr); /* Update meta data if highwater has changed */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user