From f31d107d81d6a5e062e4f463bfd1ceb61f19b7ba Mon Sep 17 00:00:00 2001 From: Stefan Rueger Date: Fri, 19 Apr 2024 22:22:53 +0100 Subject: [PATCH] Utilise magic memory tree interface for xbee.c --- src/avrdude.h | 1 + src/xbee.c | 13 ++++--------- 2 files changed, 5 insertions(+), 9 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/xbee.c b/src/xbee.c index 1771d73b..2ecb5a1e 100644 --- a/src/xbee.c +++ b/src/xbee.c @@ -1036,7 +1036,7 @@ static int xbeeATError(int rc) { static void xbeedev_free(struct XBeeBootSession *xbs) { xbs->serialDevice->close(&xbs->serialDescriptor); - free(xbs); + mmt_free(xbs); } static void xbeedev_close(union filedescriptor *fdp) @@ -1065,12 +1065,7 @@ static int xbeedev_open(const char *port, union pinfo pinfo, return -1; } - struct XBeeBootSession *xbs = malloc(sizeof(struct XBeeBootSession)); - if (xbs == NULL) { - pmsg_error("out of memory\n"); - return -1; - } - + struct XBeeBootSession *xbs = mmt_malloc(sizeof(struct XBeeBootSession)); XBeeBootSessionInit(xbs); char *tty = &ttySeparator[1]; @@ -1107,7 +1102,7 @@ static int xbeedev_open(const char *port, union pinfo pinfo, if (addrIndex != 8 || address != ttySeparator || nybble != -1) { pmsg_error("XBee: bad XBee address, require 16-character hexadecimal address\n"); - free(xbs); + mmt_free(xbs); return -1; } @@ -1174,7 +1169,7 @@ static int xbeedev_open(const char *port, union pinfo pinfo, const int rc = xbs->serialDevice->open(tty, pinfo, &xbs->serialDescriptor); if (rc < 0) { - free(xbs); + mmt_free(xbs); return rc; } }