Fixed potential memory leaks on error paths in scp.c/sim_rest (Peter Schorn)
This commit is contained in:
parent
928b4a071f
commit
54ad020b4e
1 changed files with 13 additions and 4 deletions
17
scp.c
17
scp.c
|
@ -3118,8 +3118,10 @@ for (i = 0; (dptr = sim_devices[i]) != NULL; i++) { /* loop thru devices */
|
|||
for (l = 0; (l < SRBSIZ) && (k < high); l++,
|
||||
k = k + (dptr->aincr)) { /* check for 0 block */
|
||||
r = dptr->examine (&val, k, uptr, SIM_SW_REST);
|
||||
if (r != SCPE_OK)
|
||||
if (r != SCPE_OK) {
|
||||
free (mbuf);
|
||||
return r;
|
||||
}
|
||||
if (val) zeroflg = FALSE;
|
||||
SZ_STORE (sz, val, mbuf, l);
|
||||
} /* end for l */
|
||||
|
@ -3358,19 +3360,26 @@ for ( ;; ) { /* device loop */
|
|||
if ((mbuf = calloc (SRBSIZ, sz)) == NULL)
|
||||
return SCPE_MEM;
|
||||
for (k = 0; k < high; ) { /* loop thru mem */
|
||||
READ_I (blkcnt); /* block count */
|
||||
if (sim_fread (&blkcnt, sizeof (blkcnt), 1, rfile) == 0) {/* block count */
|
||||
free (mbuf);
|
||||
return SCPE_IOERR;
|
||||
}
|
||||
if (blkcnt < 0) /* compressed? */
|
||||
limit = -blkcnt;
|
||||
else limit = (int32)sim_fread (mbuf, sz, blkcnt, rfile);
|
||||
if (limit <= 0) /* invalid or err? */
|
||||
if (limit <= 0) { /* invalid or err? */
|
||||
free (mbuf);
|
||||
return SCPE_IOERR;
|
||||
}
|
||||
for (j = 0; j < limit; j++, k = k + (dptr->aincr)) {
|
||||
if (blkcnt < 0) /* compressed? */
|
||||
val = 0;
|
||||
else SZ_LOAD (sz, val, mbuf, j); /* saved value */
|
||||
r = dptr->deposit (val, k, uptr, SIM_SW_REST);
|
||||
if (r != SCPE_OK)
|
||||
if (r != SCPE_OK) {
|
||||
free (mbuf);
|
||||
return r;
|
||||
}
|
||||
} /* end for j */
|
||||
} /* end for k */
|
||||
free (mbuf); /* dealloc buffer */
|
||||
|
|
Loading…
Add table
Reference in a new issue