From 674716804a1377ae495091002aacd12a59bb09a8 Mon Sep 17 00:00:00 2001 From: Kevin Sala Date: Tue, 10 Aug 2021 10:18:12 +0200 Subject: [PATCH] Avoiding stack overflows --- emu.c | 12 +++++++----- ovni2prv.c | 14 ++++++++------ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/emu.c b/emu.c index 54587b2..3bd1d4e 100644 --- a/emu.c +++ b/emu.c @@ -617,15 +617,17 @@ emu_destroy(struct ovni_emu *emu) int main(int argc, char *argv[]) { - struct ovni_emu emu; + struct ovni_emu *emu = (struct ovni_emu *) malloc(sizeof(struct ovni_emu)); - emu_init(&emu, argc, argv); + emu_init(emu, argc, argv); - emulate(&emu); + emulate(emu); - emu_post(&emu); + emu_post(emu); - emu_destroy(&emu); + emu_destroy(emu); + + free(emu); return 0; } diff --git a/ovni2prv.c b/ovni2prv.c index 8d70fe2..fd67177 100644 --- a/ovni2prv.c +++ b/ovni2prv.c @@ -102,7 +102,7 @@ void dump_events(struct ovni_trace *trace) int main(int argc, char *argv[]) { char *tracedir; - struct ovni_trace trace; + struct ovni_trace *trace = malloc(sizeof(struct ovni_trace)); if(argc != 2) { @@ -112,19 +112,21 @@ int main(int argc, char *argv[]) tracedir = argv[1]; - if(ovni_load_trace(&trace, tracedir)) + if(ovni_load_trace(trace, tracedir)) return 1; - if(ovni_load_streams(&trace)) + if(ovni_load_streams(trace)) return 1; - printf("#Paraver (19/01/38 at 03:14):00000000000000000000_ns:0:1:1(%d:1)\n", trace.nstreams); + printf("#Paraver (19/01/38 at 03:14):00000000000000000000_ns:0:1:1(%d:1)\n", trace->nstreams); - dump_events(&trace); + dump_events(trace); - ovni_free_streams(&trace); + ovni_free_streams(trace); fflush(stdout); + free(trace); + return 0; }