diff --git a/src/bus.c b/src/bus.c index dec03dd..a0dfcde 100644 --- a/src/bus.c +++ b/src/bus.c @@ -10,6 +10,7 @@ #include +#include #include #include "bus.h" @@ -26,7 +27,7 @@ bus_device_add(bus_t *b, device_t *d, uint16_t addr) { device_mapping_t *dm; - dm = (device_mapping_t *) malloc(sizeof(device_mapping_t)); + dm = (device_mapping_t *) GC_MALLOC(sizeof(device_mapping_t)); dm->dev = d; /* TODO: check if addr + size is not bigger than RK65C02_BUS_SIZE */ @@ -186,7 +187,5 @@ void bus_finish(bus_t *t) { assert(t != NULL); - - /* TODO: foreach devices free 'em */ } diff --git a/src/debug.c b/src/debug.c index 81371c3..5225b64 100644 --- a/src/debug.c +++ b/src/debug.c @@ -1,5 +1,7 @@ #include #include + +#include #include #include "rk65c02.h" @@ -33,9 +35,6 @@ debug_trace_print_all(rk65c02emu_t *e) rk65c02_log(LOG_TRACE, "%X: %s\t%s", tr->address, instrstr, regsstr); - - free(instrstr); - free(regsstr); } } @@ -46,7 +45,7 @@ debug_trace_savestate(rk65c02emu_t *e, uint16_t address, instrdef_t *id, { trace_t *tr; - tr = (trace_t *) malloc(sizeof(trace_t)); + tr = (trace_t *) GC_MALLOC(sizeof(trace_t)); if (tr == NULL) { fprintf(stderr, "Error allocating trace structure.\n"); return; @@ -86,7 +85,7 @@ debug_breakpoint_add(rk65c02emu_t *e, uint16_t address) { breakpoint_t *bp; - bp = (breakpoint_t *) malloc(sizeof(breakpoint_t)); + bp = (breakpoint_t *) GC_MALLOC(sizeof(breakpoint_t)); if (bp == NULL) return false; diff --git a/src/device_fb.c b/src/device_fb.c index 3cbcf24..d112925 100644 --- a/src/device_fb.c +++ b/src/device_fb.c @@ -3,6 +3,8 @@ #include #include +#include + #include "bus.h" #include "device.h" @@ -55,7 +57,7 @@ device_fb_init() device_t *d; struct fb_state *f; - d = (device_t *) malloc(sizeof(device_t)); + d = (device_t *) GC_MALLOC(sizeof(device_t)); assert(d != NULL); @@ -65,10 +67,10 @@ device_fb_init() d->read_1 = device_fb_read_1; d->write_1 = device_fb_write_1; - f = malloc(sizeof(struct fb_state)); + f = GC_MALLOC(sizeof(struct fb_state)); d->aux = f; - f->cram = malloc(FB_AS_SIZE); + f->cram = GC_MALLOC(FB_AS_SIZE); memset(d->aux, 0, FB_AS_SIZE); return d; @@ -81,7 +83,5 @@ device_fb_finish(device_t *d) f = d->aux; - free(f->cram); - free(f); } diff --git a/src/device_ram.c b/src/device_ram.c index 9bcbaa2..8c07133 100644 --- a/src/device_ram.c +++ b/src/device_ram.c @@ -3,6 +3,8 @@ #include #include +#include + #include "bus.h" #include "device.h" @@ -38,7 +40,7 @@ device_ram_init(uint16_t size) { device_t *d; - d = (device_t *) malloc(sizeof(device_t)); + d = (device_t *) GC_MALLOC(sizeof(device_t)); assert(d != NULL); @@ -48,7 +50,7 @@ device_ram_init(uint16_t size) d->read_1 = device_ram_read_1; d->write_1 = device_ram_write_1; - d->aux = malloc(size); + d->aux = GC_MALLOC(size); memset(d->aux, 0, size); return d; @@ -57,6 +59,5 @@ device_ram_init(uint16_t size) void device_ram_finish(device_t *d) { - free(d->aux); } diff --git a/src/device_serial.c b/src/device_serial.c index c75c1a1..7ff652c 100644 --- a/src/device_serial.c +++ b/src/device_serial.c @@ -7,6 +7,8 @@ #include #include +#include + #include "bus.h" #include "device.h" @@ -74,7 +76,7 @@ device_serial_init() device_t *d; struct device_serial_priv *dp; - d = (device_t *) malloc(sizeof(device_t)); + d = (device_t *) GC_MALLOC(sizeof(device_t)); assert(d != NULL); @@ -84,7 +86,7 @@ device_serial_init() d->read_1 = device_serial_read_1; d->write_1 = device_serial_write_1; - dp = (struct device_serial_priv *) malloc(sizeof(struct device_serial_priv)); + dp = (struct device_serial_priv *) GC_MALLOC(sizeof(struct device_serial_priv)); d->aux = dp; if (mkfifo(txpipepath, S_IRUSR | S_IWUSR) != 0) { @@ -115,8 +117,6 @@ device_serial_finish(device_t *d) unlink(txpipepath); unlink(rxpipepath); - free(d->aux); - // XXX? } diff --git a/src/instruction.c b/src/instruction.c index 5dab91f..8554062 100644 --- a/src/instruction.c +++ b/src/instruction.c @@ -7,6 +7,8 @@ #include #include +#include + #include "bus.h" #include "rk65c02.h" #include "65c02isa.h" @@ -61,8 +63,6 @@ instruction_print(instruction_t *i) str = instruction_string_get(i); printf("%s", str); - - free(str); } char * @@ -72,7 +72,7 @@ instruction_string_get(instruction_t *i) instrdef_t id; char *str; - str = malloc(INSTR_STR_LEN); + str = GC_MALLOC(INSTR_STR_LEN); if (str == NULL) { rk65c02_log(LOG_CRIT, "Error allocating memory for buffer: %s.", strerror(errno)); @@ -164,7 +164,6 @@ assemble_single(assembler_t *a, const char *mnemonic, addressing_t mode, uint8_t return rv; rv = bus_load_buf(a->bus, a->pc, asmbuf, bsize); - free(asmbuf); a->pc += bsize; return rv; @@ -205,7 +204,7 @@ assemble_single_buf(uint8_t **buf, uint8_t *bsize, const char *mnemonic, address } *bsize = id.size; - *buf = malloc(id.size); + *buf = GC_MALLOC(id.size); if(*buf == NULL) { rk65c02_log(LOG_ERROR, "Error allocating assembly buffer."); return false; diff --git a/src/rk65c02.c b/src/rk65c02.c index 7e2a96d..cc4e406 100644 --- a/src/rk65c02.c +++ b/src/rk65c02.c @@ -7,6 +7,8 @@ #include #include +#include + #include "bus.h" #include "instruction.h" #include "rk65c02.h" @@ -195,7 +197,6 @@ rk65c02_dump_regs(reg_state_t regs) printf ("%s\n", str); - free(str); } char * @@ -205,7 +206,7 @@ rk65c02_regs_string_get(reg_state_t regs) char *str; /* XXX: string allocation to a separate utility function? */ - str = malloc(REGS_STR_LEN); + str = GC_MALLOC(REGS_STR_LEN); if (str == NULL) { rk65c02_log(LOG_CRIT, "Error allocating memory for buffer: %s.", strerror(errno)); diff --git a/test/Makefile b/test/Makefile index 80845f3..1c669c7 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,5 +1,5 @@ CFLAGS=-Wall -I../src -g -LDFLAGS=-latf-c +LDFLAGS=-latf-c -lgc RK6502LIB=../src/librk65c02.a VASM=vasm6502_std VASMFLAGS=-Fbin -c02 diff --git a/test/test_assemble.c b/test/test_assemble.c index 40c8bcc..0f18e04 100644 --- a/test/test_assemble.c +++ b/test/test_assemble.c @@ -28,20 +28,17 @@ ATF_TC_BODY(assemble_single_buf, tc) ATF_REQUIRE(assemble_single_buf_implied(&asmbuf, &bsize, "nop")); ATF_CHECK(asmbuf[0] == 0xEA); /* check if nop really */ ATF_REQUIRE(bus_load_buf(&b, caddr, asmbuf, bsize)); - free(asmbuf); caddr += bsize; ATF_REQUIRE(assemble_single_buf(&asmbuf, &bsize, "lda", IMMEDIATE, 0xAA, 0)); ATF_CHECK(asmbuf[0] == 0xA9); /* check if lda really */ ATF_CHECK(asmbuf[1] == 0xAA); /* check the operand */ ATF_REQUIRE(bus_load_buf(&b, caddr, asmbuf, bsize)); - free(asmbuf); caddr += bsize; ATF_REQUIRE(assemble_single_buf_implied(&asmbuf, &bsize, "stp")); ATF_CHECK(asmbuf[0] == 0xDB); /* check if stp really */ ATF_REQUIRE(bus_load_buf(&b, caddr, asmbuf, bsize)); - free(asmbuf); caddr += bsize; rk65c02_start(&e); diff --git a/test/test_interrupt.c b/test/test_interrupt.c index a895a62..464a833 100644 --- a/test/test_interrupt.c +++ b/test/test_interrupt.c @@ -87,17 +87,14 @@ ATF_TC_BODY(intr_rti, tc) ATF_REQUIRE(assemble_single_buf_implied(&asmbuf, &bsize, "nop")); ATF_REQUIRE(bus_load_buf(&b, israsmpc, asmbuf, bsize)); - free(asmbuf); israsmpc += bsize; ATF_REQUIRE(assemble_single_buf_implied(&asmbuf, &bsize, "rti")); ATF_REQUIRE(bus_load_buf(&b, israsmpc, asmbuf, bsize)); - free(asmbuf); israsmpc += bsize; ATF_REQUIRE(assemble_single_buf_implied(&asmbuf, &bsize, "nop")); ATF_REQUIRE(bus_load_buf(&b, ROM_LOAD_ADDR, asmbuf, bsize)); - free(asmbuf); /* There's a return address and saved processor flags on stack. */ e.regs.SP = 0xFF; diff --git a/test/utils.c b/test/utils.c index ff7bc34..7eaf446 100644 --- a/test/utils.c +++ b/test/utils.c @@ -2,7 +2,9 @@ #include #include #include + #include +#include #include "bus.h" #include "rk65c02.h" @@ -15,7 +17,7 @@ rom_path(const char *name, const atf_tc_t *tc) char *rompath; const char *srcdir; - rompath = malloc(PATH_MAX); + rompath = GC_MALLOC(PATH_MAX); srcdir = atf_tc_get_config_var(tc, "srcdir"); strcpy(rompath, srcdir);