Utilise magic memory tree interface for xbee.c

This commit is contained in:
Stefan Rueger
2024-04-19 22:22:53 +01:00
parent b2e71428b9
commit f31d107d81
2 changed files with 5 additions and 9 deletions

View File

@@ -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, ...);

View File

@@ -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;
}
}