PDP11, VAX: Fix memory leak when preparing DEC Std 144 bad block table on new disk images

This commit is contained in:
Mark Pizzolato 2016-01-22 11:31:22 -08:00
parent ed64606ea3
commit 32440a4138
2 changed files with 18 additions and 23 deletions

View file

@ -905,9 +905,11 @@ return SCPE_OK;
/* Factory bad block table creation routine /* Factory bad block table creation routine
This routine writes a DEC standard 044 compliant bad block table on the This routine writes a DEC standard 144 compliant bad block table on the
last track of the specified unit. The bad block table consists of 10 last track of the specified unit as described in:
repetitions of the same table, formatted as follows: EL-00144_B_DEC_STD_144_Disk_Standard_for_Recording_and_Handling_Bad_Sectors_Nov76.pdf
The bad block table consists of 10 repetitions of the same table,
formatted as follows:
words 0-1 pack id number words 0-1 pack id number
words 2-3 cylinder/sector/surface specifications words 2-3 cylinder/sector/surface specifications
@ -943,17 +945,13 @@ if (sim_fseek (uptr->fileref, da, SEEK_SET))
return SCPE_IOERR; return SCPE_IOERR;
if ((buf = (uint16 *) malloc (wds * sizeof (uint16))) == NULL) if ((buf = (uint16 *) malloc (wds * sizeof (uint16))) == NULL)
return SCPE_MEM; return SCPE_MEM;
if ((namebuf = (char *) malloc (1 + strlen (uptr->filename))) == NULL) { namebuf = uptr->filename;
free (buf);
return SCPE_MEM;
}
strcpy (namebuf, uptr->filename);
if ((c = strrchr (namebuf, '/'))) if ((c = strrchr (namebuf, '/')))
strcpy (namebuf, c+1); namebuf = c+1;
if ((c = strrchr (namebuf, '\\'))) if ((c = strrchr (namebuf, '\\')))
strcpy (namebuf, c+1); namebuf = c+1;
if ((c = strrchr (namebuf, ']'))) if ((c = strrchr (namebuf, ']')))
strcpy (namebuf, c+1); namebuf = c+1;
packid = eth_crc32(0, namebuf, strlen (namebuf)); packid = eth_crc32(0, namebuf, strlen (namebuf));
buf[0] = (uint16)packid; buf[0] = (uint16)packid;
buf[1] = (uint16)(packid >> 16) & 0x7FFF; /* Make sure MSB is clear */ buf[1] = (uint16)(packid >> 16) & 0x7FFF; /* Make sure MSB is clear */
@ -962,7 +960,6 @@ for (i = 4; i < wds; i++)
buf[i] = 0177777u; buf[i] = 0177777u;
for (i = 0; (i < sec) && (i < 10); i++) for (i = 0; (i < sec) && (i < 10); i++)
sim_fwrite (buf, sizeof (uint16), wds, uptr->fileref); sim_fwrite (buf, sizeof (uint16), wds, uptr->fileref);
free (namebuf);
free (buf); free (buf);
if (ferror (uptr->fileref)) if (ferror (uptr->fileref))
return SCPE_IOERR; return SCPE_IOERR;

View file

@ -1511,9 +1511,11 @@ return SCPE_OK;
/* Factory bad block table creation routine /* Factory bad block table creation routine
This routine writes a DEC standard 044 compliant bad block table on the This routine writes a DEC standard 144 compliant bad block table on the
last track of the specified unit. The bad block table consists of 10 last track of the specified unit as described in:
repetitions of the same table, formatted as follows: EL-00144_B_DEC_STD_144_Disk_Standard_for_Recording_and_Handling_Bad_Sectors_Nov76.pdf
The bad block table consists of 10 repetitions of the same table,
formatted as follows:
words 0-1 pack id number words 0-1 pack id number
words 2-3 cylinder/sector/surface specifications words 2-3 cylinder/sector/surface specifications
@ -1552,17 +1554,13 @@ if (!get_yn ("Overwrite last track? [N]", FALSE))
return SCPE_OK; return SCPE_OK;
if ((buf = (uint16 *) malloc (wds * sizeof (uint16))) == NULL) if ((buf = (uint16 *) malloc (wds * sizeof (uint16))) == NULL)
return SCPE_MEM; return SCPE_MEM;
if ((namebuf = (char *) malloc (1 + strlen (uptr->filename))) == NULL) { namebuf = uptr->filename;
free (buf);
return SCPE_MEM;
}
strcpy (namebuf, uptr->filename);
if ((c = strrchr (namebuf, '/'))) if ((c = strrchr (namebuf, '/')))
memcpy (namebuf, c+1, strlen(c+1)+1); namebuf = c+1;
if ((c = strrchr (namebuf, '\\'))) if ((c = strrchr (namebuf, '\\')))
memcpy (namebuf, c+1, strlen(c+1)+1); namebuf = c+1;
if ((c = strrchr (namebuf, ']'))) if ((c = strrchr (namebuf, ']')))
memcpy (namebuf, c+1, strlen(c+1)+1); namebuf = c+1;
packid = eth_crc32(0, namebuf, strlen (namebuf)); packid = eth_crc32(0, namebuf, strlen (namebuf));
buf[0] = (uint16)packid; buf[0] = (uint16)packid;
buf[1] = (uint16)(packid >> 16) & 0x7FFF; /* Make sure MSB is clear */ buf[1] = (uint16)(packid >> 16) & 0x7FFF; /* Make sure MSB is clear */