From 0f6d07323d46b7782468f93e82b6aab4f2e44cfe Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Fri, 19 Apr 2024 22:30:47 +0100 Subject: [PATCH] Utilise magic memory tree interface for stk500.c --- src/avrdude.h | 1 + src/stk500.c | 14 ++++---------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/avrdude.h b/src/avrdude.h index c679a654..6b777d30 100644 --- a/src/avrdude.h +++ b/src/avrdude.h @@ -44,6 +44,7 @@ extern const char *pgmid; // Programmer -c string #define mmt_strdup(s) cfg_strdup(__func__, s) #define mmt_malloc(n) cfg_malloc(__func__, n) #define mmt_realloc(p, n) cfg_realloc(__func__, p, n) +#define mmt_free(p) free(p) int avrdude_message2(FILE *fp, int lno, const char *file, const char *func, int msgmode, int msglvl, const char *format, ...); diff --git a/src/stk500.c b/src/stk500.c index 16d0ec09..d873c6d4 100644 --- a/src/stk500.c +++ b/src/stk500.c @@ -1567,13 +1567,8 @@ static void stk500_print_parms(const PROGRAMMER *pgm, FILE *fp) { stk500_print_parms1(pgm, "", fp); } -static void stk500_setup(PROGRAMMER * pgm) -{ - if ((pgm->cookie = malloc(sizeof(struct pdata))) == 0) { - pmsg_error("out of memory allocating private data\n"); - return; - } - memset(pgm->cookie, 0, sizeof(struct pdata)); +static void stk500_setup(PROGRAMMER * pgm) { + pgm->cookie = mmt_malloc(sizeof(struct pdata)); PDATA(pgm)->ext_addr_byte = 0xff; PDATA(pgm)->xbeeResetPin = XBEE_DEFAULT_RESET_PIN; // nanoSTK (Arduino Nano HW) uses 16 MHz @@ -1583,9 +1578,8 @@ static void stk500_setup(PROGRAMMER * pgm) PDATA(pgm)->xtal = STK500_XTAL; } -static void stk500_teardown(PROGRAMMER * pgm) -{ - free(pgm->cookie); +static void stk500_teardown(PROGRAMMER * pgm) { + mmt_free(pgm->cookie); pgm->cookie = NULL; }