diff --git a/cd.h b/cd.h index 36a8c00..f021856 100644 --- a/cd.h +++ b/cd.h @@ -30,6 +30,7 @@ typedef struct int last; int sectorSize; chd_file *chd_f; + int chd_hunksize; cd_track_t tracks[100]; fileTYPE sub; diff --git a/ide_cdrom.cpp b/ide_cdrom.cpp index 33698b0..0ffab8c 100644 --- a/ide_cdrom.cpp +++ b/ide_cdrom.cpp @@ -301,7 +301,7 @@ static const char* load_chd_file(drive_t *drv, const char *chdfile) free(drv->chd_hunkbuf); } - drv->chd_hunkbuf = (uint8_t *)malloc(CD_FRAME_SIZE * CD_FRAMES_PER_HUNK); + drv->chd_hunkbuf = (uint8_t *)malloc(tmpTOC.chd_hunksize); drv->chd_hunknum = -1; drv->chd_f = tmpTOC.chd_f; diff --git a/support/chd/mister_chd.cpp b/support/chd/mister_chd.cpp index c5606cf..666debe 100644 --- a/support/chd/mister_chd.cpp +++ b/support/chd/mister_chd.cpp @@ -48,6 +48,7 @@ chd_error mister_load_chd(const char *filename, toc_t *cd_toc) } mister_chd_log("hunkbytes %d unitbytes %d logical length %llu\n", chd_header->hunkbytes, chd_header->unitbytes, chd_header->logicalbytes); + cd_toc->chd_hunksize = chd_header->hunkbytes; //Set CLOEXEC on underlying FD int chd_fd = fileno((FILE *)chd_core_file(cd_toc->chd_f)->argp); diff --git a/support/megacd/megacdd.cpp b/support/megacd/megacdd.cpp index 257aed7..2bb42ac 100644 --- a/support/megacd/megacdd.cpp +++ b/support/megacd/megacdd.cpp @@ -264,7 +264,7 @@ int cdd_t::Load(const char *filename) free(this->chd_hunkbuf); } - this->chd_hunkbuf = (uint8_t *)malloc(CD_FRAME_SIZE * CD_FRAMES_PER_HUNK); + this->chd_hunkbuf = (uint8_t *)malloc(this->toc.chd_hunksize); this->chd_hunknum = -1; } else { return (-1); diff --git a/support/pcecd/pcecdd.cpp b/support/pcecd/pcecdd.cpp index f6eddf9..ff0f50d 100644 --- a/support/pcecd/pcecdd.cpp +++ b/support/pcecd/pcecdd.cpp @@ -264,7 +264,7 @@ int pcecdd_t::Load(const char *filename) this->chd_hunkbuf = NULL; } - this->chd_hunkbuf = (uint8_t *)malloc(CD_FRAME_SIZE * CD_FRAMES_PER_HUNK); + this->chd_hunkbuf = (uint8_t *)malloc(this->toc.chd_hunksize); this->chd_hunknum = -1; } else { return -1; diff --git a/support/psx/psx.cpp b/support/psx/psx.cpp index 2abcd2f..baefd9e 100644 --- a/support/psx/psx.cpp +++ b/support/psx/psx.cpp @@ -16,7 +16,7 @@ #include static char buf[1024]; -static uint8_t chd_hunkbuf[CD_FRAME_SIZE * CD_FRAMES_PER_HUNK]; +static uint8_t *chd_hunkbuf = NULL; static int chd_hunknum; static int sgets(char *out, int sz, char **in) @@ -108,7 +108,7 @@ static void unload_chd(toc_t *table) { chd_close(table->chd_f); } - memset(chd_hunkbuf, 0, sizeof(chd_hunkbuf)); + if (chd_hunkbuf) free(chd_hunkbuf); memset(table, 0, sizeof(toc_t)); chd_hunknum = -1; @@ -154,7 +154,7 @@ static int load_chd(const char *filename, toc_t *table) table->end = table->tracks[table->last - 1].end + 1; - memset(chd_hunkbuf, 0, sizeof(chd_hunkbuf)); + chd_hunkbuf = (uint8_t *)malloc(table->chd_hunksize); chd_hunknum = -1; return 1; diff --git a/support/saturn/saturncdd.cpp b/support/saturn/saturncdd.cpp index 00f3b8e..63e7f0d 100644 --- a/support/saturn/saturncdd.cpp +++ b/support/saturn/saturncdd.cpp @@ -339,7 +339,7 @@ int satcdd_t::Load(const char *filename) free(this->chd_hunkbuf); } - this->chd_hunkbuf = (uint8_t *)malloc(CD_FRAME_SIZE * CD_FRAMES_PER_HUNK); + this->chd_hunkbuf = (uint8_t *)malloc(this->toc.chd_hunksize); this->chd_hunknum = -1; if (this->toc.tracks[0].sector_size) {