From fb6366600741b4372cf67e388ac07687849a243e Mon Sep 17 00:00:00 2001 From: Jim Garlick Date: Thu, 8 Feb 2024 13:07:46 -0800 Subject: [PATCH 1/2] expunge builtin memory leak/corruption checks Problem: the powerman source code includes "magic cookie checks" in many of its classes, and the xmalloc() wrapper actually tracks the total number of bytes allocated and freed, but we have tools for this sort of thing nowadays so these checks are extra. Get rid of memory checks. --- src/libcommon/error.c | 3 -- src/libcommon/xmalloc.c | 77 +++-------------------------------- src/libcommon/xpoll.c | 12 ------ src/libcommon/xregex.c | 16 -------- src/powerman/client.c | 9 ---- src/powerman/device.c | 11 ----- src/powerman/device_private.h | 4 -- src/powerman/device_serial.c | 1 - src/powerman/device_tcp.c | 3 -- src/powerman/libpowerman.c | 19 +++------ src/powerman/parse_tab.y | 13 ------ src/powerman/pluglist.c | 14 ------- 12 files changed, 11 insertions(+), 171 deletions(-) diff --git a/src/libcommon/error.c b/src/libcommon/error.c index 07fc8775..c2b03647 100644 --- a/src/libcommon/error.c +++ b/src/libcommon/error.c @@ -22,8 +22,6 @@ #include "list.h" #include "error.h" -#include "debug.h" -#include "xmalloc.h" static char *err_prog = NULL; /* basename of calling program */ static bool err_ttyvalid = true; /* use stderr until told otherwise */ @@ -80,7 +78,6 @@ void err_exit(bool errno_valid, const char *fmt, ...) va_start(ap, fmt); _verr(errno_valid, fmt, ap); va_end(ap); - dbg(DBG_MEMORY, "err_exit: memory not reclaimed: %d\n", xmemory()); exit(1); } diff --git a/src/libcommon/xmalloc.c b/src/libcommon/xmalloc.c index 88f18656..45dfa7e1 100644 --- a/src/libcommon/xmalloc.c +++ b/src/libcommon/xmalloc.c @@ -19,102 +19,35 @@ #include "xmalloc.h" #include "error.h" -#ifndef NDEBUG -static int memory_alloc = 0; -#endif - -/* Review: look into dmalloc */ -#define MALLOC_MAGIC 0xf00fbaab -#define MALLOC_PAD_SIZE 16 -#define MALLOC_PAD_FILL 0x55 - -#ifndef NDEBUG -int xmemory(void) -{ - return memory_alloc; -} - -static int _checkfill(char *buf, unsigned char fill, int size) -{ - while (size-- > 0) - if (buf[size] != fill) - return 0; - return 1; -} -#endif - char *xmalloc(int size) { char *new; - int *p; - - assert(size > 0); - p = (int *) malloc(2*sizeof(int) + size + MALLOC_PAD_SIZE); - if (p == NULL) + if (!(new = calloc(1, size))) err_exit(false, "out of memory"); - p[0] = MALLOC_MAGIC; /* magic cookie */ - p[1] = size; /* store size in buffer */ -#ifndef NDEBUG - memory_alloc += size; -#endif - new = (char *) &p[2]; - memset(new, 0, size); - memset(new + size, MALLOC_PAD_FILL, MALLOC_PAD_SIZE); return new; } char *xrealloc(char *item , int newsize) { char *new; - int *p = (int *)item - 2; - int oldsize; - - assert(item != NULL); - assert(newsize > 0); - assert(p[0] == MALLOC_MAGIC); - oldsize = p[1]; - assert(_checkfill(item + oldsize, MALLOC_PAD_FILL, MALLOC_PAD_SIZE)); - p = (int *)realloc(p, 2*sizeof(int) + newsize + MALLOC_PAD_SIZE); - if (p == NULL) + if (!(new = realloc(item, newsize))) err_exit(false, "out of memory"); - assert(p[0] == MALLOC_MAGIC); - p[1] = newsize; -#ifndef NDEBUG - memory_alloc += (newsize - oldsize); -#endif - new = (char *) &p[2]; - if (newsize > oldsize) - memset(new + oldsize, 0, newsize - oldsize); - memset(new + newsize, MALLOC_PAD_FILL, MALLOC_PAD_SIZE); return new; } void xfree(void *ptr) { - if (ptr != NULL) { - int *p = (int *) ptr - 2; - int size; - - assert(p[0] == MALLOC_MAGIC); /* magic cookie still there? */ - size = p[1]; - assert(_checkfill((char*)ptr + size, MALLOC_PAD_FILL, MALLOC_PAD_SIZE)); - memset(p, 0, 2*sizeof(int) + size + MALLOC_PAD_SIZE); -#ifndef NDEBUG - memory_alloc -= size; -#endif - free(p); - } + free(ptr); } char *xstrdup(const char *str) { char *cpy; - cpy = xmalloc(strlen(str) + 1); - - strcpy(cpy, str); + if (!(cpy = strdup(str))) + err_exit(false, "out of memory"); return cpy; } diff --git a/src/libcommon/xpoll.c b/src/libcommon/xpoll.c index 65236a07..3916d906 100644 --- a/src/libcommon/xpoll.c +++ b/src/libcommon/xpoll.c @@ -41,9 +41,7 @@ #define XPOLLFD_ALLOC_CHUNK 16 -#define XPOLLFD_MAGIC 0x56452334 struct xpollfd { - int magic; #if HAVE_POLL unsigned int nfds; unsigned int ufds_size; @@ -138,7 +136,6 @@ xpoll(xpollfd_t pfd, struct timeval *tv) static void _grow_pollfd(xpollfd_t pfd, int n) { - assert(pfd->magic == XPOLLFD_MAGIC); while (pfd->ufds_size < n) { pfd->ufds_size += XPOLLFD_ALLOC_CHUNK; pfd->ufds = (struct pollfd *)xrealloc((char *)pfd->ufds, sizeof(struct pollfd) * pfd->ufds_size); @@ -151,7 +148,6 @@ xpollfd_create(void) { xpollfd_t pfd = (xpollfd_t)xmalloc(sizeof(struct xpollfd)); - pfd->magic = XPOLLFD_MAGIC; #if HAVE_POLL pfd->ufds_size += XPOLLFD_ALLOC_CHUNK; pfd->ufds = (struct pollfd *)xmalloc(sizeof(struct pollfd)*pfd->ufds_size); @@ -168,8 +164,6 @@ xpollfd_create(void) void xpollfd_destroy(xpollfd_t pfd) { - assert(pfd->magic == XPOLLFD_MAGIC); - pfd->magic = 0; #if HAVE_POLL if (pfd->ufds != NULL) xfree(pfd->ufds); @@ -180,7 +174,6 @@ xpollfd_destroy(xpollfd_t pfd) void xpollfd_zero(xpollfd_t pfd) { - assert(pfd->magic == XPOLLFD_MAGIC); #if HAVE_POLL pfd->nfds = 0; /*memset(pfd->ufds, 0, sizeof(struct pollfd) * pfd->ufds_size);*/ @@ -197,7 +190,6 @@ xpollfd_set(xpollfd_t pfd, int fd, short events) #if HAVE_POLL int i; - assert(pfd->magic == XPOLLFD_MAGIC); for (i = 0; i < pfd->nfds; i++) { if (pfd->ufds[i].fd == fd) { pfd->ufds[i].events |= xflag2flag(events); @@ -210,7 +202,6 @@ xpollfd_set(xpollfd_t pfd, int fd, short events) pfd->ufds[i].events = xflag2flag(events); } #else - assert(pfd->magic == XPOLLFD_MAGIC); assert(fd < FD_SETSIZE); if (events & XPOLLIN) FD_SET(fd, &pfd->rset); @@ -227,7 +218,6 @@ xpollfd_str(xpollfd_t pfd, char *str, int len) #if HAVE_POLL int maxfd = -1; #endif - assert(pfd->magic == XPOLLFD_MAGIC); #if HAVE_POLL memset(str, '.', len); for (i = 0; i < pfd->nfds; i++) { @@ -271,7 +261,6 @@ xpollfd_revents(xpollfd_t pfd, int fd) #if HAVE_POLL int i; - assert(pfd->magic == XPOLLFD_MAGIC); for (i = 0; i < pfd->nfds; i++) { if (pfd->ufds[i].fd == fd) { flags = flag2xflag(pfd->ufds[i].revents); @@ -279,7 +268,6 @@ xpollfd_revents(xpollfd_t pfd, int fd) } } #else - assert(pfd->magic == XPOLLFD_MAGIC); if (FD_ISSET(fd, &pfd->rset)) flags |= XPOLLIN; if (FD_ISSET(fd, &pfd->wset)) diff --git a/src/libcommon/xregex.c b/src/libcommon/xregex.c index daec2cdc..ca9355a8 100644 --- a/src/libcommon/xregex.c +++ b/src/libcommon/xregex.c @@ -22,15 +22,11 @@ #include "xregex.h" #include "xmalloc.h" -#define XREGEX_MAGIC 0x3456aaaa struct xregex_struct { - int xr_magic; int xr_cflags; regex_t *xr_regex; }; -#define XREGEX_MATCH_MAGIC 0x3456aaba struct xregex_match_struct { - int xm_magic; int xm_nmatch; regmatch_t *xm_pmatch; char *xm_str; @@ -43,7 +39,6 @@ xregex_create(void) { xregex_t xrp = (xregex_t)xmalloc(sizeof(struct xregex_struct)); - xrp->xr_magic = XREGEX_MAGIC; xrp->xr_regex = NULL; return xrp; @@ -52,12 +47,10 @@ xregex_create(void) void xregex_destroy(xregex_t xrp) { - assert(xrp->xr_magic == XREGEX_MAGIC); if (xrp->xr_regex) { regfree(xrp->xr_regex); xfree(xrp->xr_regex); } - xrp->xr_magic = 0; xfree(xrp); } @@ -86,7 +79,6 @@ xregex_compile(xregex_t xrp, const char *regex, bool withsub) int n; assert(regex != NULL); - assert(xrp->xr_magic == XREGEX_MAGIC); assert(xrp->xr_regex == NULL); /* No particular limit is imposed on the length of REs(!). Programs @@ -120,10 +112,8 @@ xregex_exec(xregex_t xrp, const char *s, xregex_match_t xm) int eflags = REG_NOTEOL; int res; - assert(xrp->xr_magic == XREGEX_MAGIC); assert(xrp->xr_regex != NULL); if (xm != NULL) { - assert(xm->xm_magic == XREGEX_MATCH_MAGIC); assert(xm->xm_used == false); } @@ -147,7 +137,6 @@ xregex_match_create(int nmatch) xregex_match_t xm; xm = (xregex_match_t)xmalloc(sizeof(struct xregex_match_struct)); - xm->xm_magic = XREGEX_MATCH_MAGIC; xm->xm_nmatch = nmatch + 1; xm->xm_pmatch = (regmatch_t *)xmalloc(sizeof(regmatch_t) * (nmatch + 1)); xm->xm_str = NULL; @@ -159,12 +148,10 @@ xregex_match_create(int nmatch) void xregex_match_destroy(xregex_match_t xm) { - assert(xm->xm_magic == XREGEX_MATCH_MAGIC); xfree(xm->xm_pmatch); if (xm->xm_str) xfree(xm->xm_str); - xm->xm_magic = 0; xfree(xm); } @@ -184,7 +171,6 @@ xregex_match_strdup(xregex_match_t xm) { char *s = NULL; - assert(xm->xm_magic == XREGEX_MATCH_MAGIC); assert(xm->xm_used); if (xm->xm_result == 0) { @@ -199,7 +185,6 @@ xregex_match_strdup(xregex_match_t xm) int xregex_match_strlen(xregex_match_t xm) { - assert(xm->xm_magic == XREGEX_MATCH_MAGIC); assert(xm->xm_used); return xm->xm_pmatch[0].rm_eo; @@ -210,7 +195,6 @@ xregex_match_sub_strdup(xregex_match_t xm, int i) { char *s = NULL; - assert(xm->xm_magic == XREGEX_MATCH_MAGIC); assert(xm->xm_used); if (xm->xm_result == 0 && i >= 0 && i < xm->xm_nmatch diff --git a/src/powerman/client.c b/src/powerman/client.c index aa34375f..da2048b5 100644 --- a/src/powerman/client.c +++ b/src/powerman/client.c @@ -68,9 +68,7 @@ typedef struct { ArgList arglist; /* argument for query commands */ } Command; -#define CLI_MAGIC 0xdadadada typedef struct { - int magic; int fd; /* file descriptor for the socket */ int ofd; /* separate output file descriptor (if used) */ char *ip; /* IP address of the client's host */ @@ -679,7 +677,6 @@ static void _act_finish(int client_id, ActError acterr, const char *fmt, ...) /* if client has gone away do nothing */ if (!(c = _find_client(client_id))) return; - assert(c->magic == CLI_MAGIC); assert(c->cmd != NULL); /* handle errors immediately */ @@ -734,8 +731,6 @@ static void _act_finish(int client_id, ActError acterr, const char *fmt, ...) */ static void _destroy_client(Client *c) { - assert(c->magic == CLI_MAGIC); - if (c->fd != NO_FD) { dbg(DBG_CLIENT, "_destroy_client: closing fd %d", c->fd); if (close(c->fd) < 0) @@ -886,7 +881,6 @@ static void _create_client_socket(int fd) /* create client data structure */ c = (Client *) xmalloc(sizeof(Client)); - c->magic = CLI_MAGIC; c->to = NULL; c->from = NULL; c->cmd = NULL; @@ -964,7 +958,6 @@ static void _create_client_stdio(void) /* create client data structure */ c = (Client *) xmalloc(sizeof(Client)); - c->magic = CLI_MAGIC; c->cmd = NULL; c->client_id = _next_cli_id(); c->telemetry = false; @@ -997,7 +990,6 @@ static void _handle_read(Client * c) int n; int dropped; - assert(c->magic == CLI_MAGIC); n = cbuf_write_from_fd(c->from, c->fd, -1, &dropped); if (n < 0) { c->client_quit = true; @@ -1021,7 +1013,6 @@ static void _handle_write(Client * c) int n; int ofd = c->ofd != NO_FD ? c->ofd : c->fd; - assert(c->magic == CLI_MAGIC); if (c->client_quit) nonblock_clr(ofd); n = cbuf_read_to_fd(c->to, ofd, -1); diff --git a/src/powerman/device.c b/src/powerman/device.c index c4578d6c..067d31ba 100644 --- a/src/powerman/device.c +++ b/src/powerman/device.c @@ -85,10 +85,8 @@ typedef struct { * represents a request to run a particular script on a device, for a set of * plugs. Actions can be enqueued by the client or internally (e.g. login). */ -#define ACT_MAGIC 0xb00bb000 #define MAX_LEVELS 2 typedef struct { - int magic; int com; /* one of the PM_* above */ List exec; /* stack of ExecCtxs (outer block is first) */ ActionCB complete_fun; /* callback for action completion */ @@ -263,7 +261,6 @@ static Action *_create_action(Device * dev, int com, List plugs, dbg(DBG_ACTION, "_create_action: %d", com); act = (Action *) xmalloc(sizeof(Action)); - act->magic = ACT_MAGIC; act->com = com; act->complete_fun = complete_fun; act->vpf_fun = vpf_fun; @@ -281,8 +278,6 @@ static Action *_create_action(Device * dev, int com, List plugs, static void _destroy_action(Action * act) { - assert(act->magic == ACT_MAGIC); - act->magic = 0; dbg(DBG_ACTION, "_destroy_action: %d", act->com); if (act->exec) list_destroy(act->exec); @@ -1264,7 +1259,6 @@ Device *dev_create(const char *name) int i; dev = (Device *) xmalloc(sizeof(Device)); - dev->magic = DEV_MAGIC; dev->name = xstrdup(name); dev->connect_state = DEV_NOT_CONNECTED; dev->fd = NO_FD; @@ -1305,8 +1299,6 @@ void dev_destroy(Device * dev) { int i; - assert(dev->magic == DEV_MAGIC); - if (dev->connect_state == DEV_CONNECTED) dev->disconnect(dev); @@ -1326,7 +1318,6 @@ void dev_destroy(Device * dev) cbuf_destroy(dev->to); cbuf_destroy(dev->from); xregex_match_destroy(dev->xmatch); - dev->magic = 0; xfree(dev); } @@ -1369,7 +1360,6 @@ static bool _handle_read(Device * dev) int n; int dropped; - assert(dev->magic == DEV_MAGIC); n = cbuf_write_from_fd(dev->from, dev->fd, -1, &dropped); if (n < 0) { err(true, "read error on %s", dev->name); @@ -1393,7 +1383,6 @@ static bool _handle_write(Device * dev) { int n; - assert(dev->magic == DEV_MAGIC); n = cbuf_read_to_fd(dev->to, dev->fd, -1); if (n < 0) { err(true, "write error on %s", dev->name); diff --git a/src/powerman/device_private.h b/src/powerman/device_private.h index 715f9d48..6bbe617e 100644 --- a/src/powerman/device_private.h +++ b/src/powerman/device_private.h @@ -46,9 +46,7 @@ #define MAX_MATCH_POS 20 -#define INTERP_MAGIC 0x13434550 typedef struct { - int magic; InterpState state; char *str; xregex_t re; @@ -101,9 +99,7 @@ typedef List Script; */ typedef enum { DEV_NOT_CONNECTED, DEV_CONNECTING, DEV_CONNECTED } ConnectState; -#define DEV_MAGIC 0xbeefb111 typedef struct _device { - int magic; char *name; /* name of device */ char *specname; /* name of specification, e.g. "icebox3" */ diff --git a/src/powerman/device_serial.c b/src/powerman/device_serial.c index 07c7f679..b43aea24 100644 --- a/src/powerman/device_serial.c +++ b/src/powerman/device_serial.c @@ -186,7 +186,6 @@ bool serial_connect(Device * dev) int res; int n; - assert(dev->magic == DEV_MAGIC); assert(dev->connect_state == DEV_NOT_CONNECTED); assert(dev->fd == NO_FD); diff --git a/src/powerman/device_tcp.c b/src/powerman/device_tcp.c index f51bff6f..6e2ac47a 100644 --- a/src/powerman/device_tcp.c +++ b/src/powerman/device_tcp.c @@ -190,7 +190,6 @@ bool tcp_finish_connect(Device * dev) { TcpDev *tcp; - assert(dev->magic == DEV_MAGIC); assert(dev->connect_state == DEV_CONNECTING); tcp = (TcpDev *)dev->data; @@ -227,7 +226,6 @@ bool tcp_connect(Device * dev) { TcpDev *tcp; - assert(dev->magic == DEV_MAGIC); assert(dev->connect_state == DEV_NOT_CONNECTED); assert(dev->fd == NO_FD); @@ -263,7 +261,6 @@ void tcp_disconnect(Device * dev) { TcpDev *tcp; - assert(dev->magic == DEV_MAGIC); assert(dev->connect_state == DEV_CONNECTING || dev->connect_state == DEV_CONNECTED); tcp = (TcpDev *)dev->data; diff --git a/src/powerman/libpowerman.c b/src/powerman/libpowerman.c index a510ad7e..103e8643 100644 --- a/src/powerman/libpowerman.c +++ b/src/powerman/libpowerman.c @@ -35,9 +35,7 @@ #endif -#define PMH_MAGIC 0x44445555 struct pm_handle_struct { - int pmh_magic; int pmh_fd; }; @@ -49,9 +47,7 @@ struct list_struct { list_free_t freefun; }; -#define PMI_MAGIC 0x41a452b5 struct pm_node_iterator_struct { - int pmi_magic; struct list_struct *pmi_nodes; struct list_struct *pmi_pos; }; @@ -362,7 +358,6 @@ pm_connect(char *server, void *arg, pm_handle_t *pmhp, int flags) return PM_EBADARG; if ((pmh = (pm_handle_t)malloc(sizeof(struct pm_handle_struct))) == NULL) return PM_ENOMEM; - pmh->pmh_magic = PMH_MAGIC; if ((err = _connect_to_server_tcp(pmh, server, (flags & PM_CONN_INET6) ? PF_INET6 : PF_UNSPEC)) != PM_ESUCCESS) { @@ -394,7 +389,6 @@ _node_iterator_create(pm_node_iterator_t *pmip) if (!(pmi = malloc(sizeof(struct pm_node_iterator_struct)))) return PM_ENOMEM; - pmi->pmi_magic = PMI_MAGIC; pmi->pmi_pos = pmi->pmi_nodes = NULL; *pmip = pmi; return PM_ESUCCESS; @@ -405,7 +399,6 @@ pm_node_iterator_destroy(pm_node_iterator_t pmi) { _list_free(&pmi->pmi_nodes); pmi->pmi_pos = NULL; - pmi->pmi_magic = 0; free(pmi); } @@ -417,7 +410,7 @@ pm_node_iterator_create(pm_handle_t pmh, pm_node_iterator_t *pmip) char *cpy, node[CP_LINEMAX]; pm_err_t err; - if (pmh == NULL || pmh->pmh_magic != PMH_MAGIC) + if (pmh == NULL) return PM_EBADHAND; if ((err = _node_iterator_create(&pmi)) != PM_ESUCCESS) return err; @@ -470,7 +463,7 @@ pm_node_iterator_reset(pm_node_iterator_t pmi) void pm_disconnect(pm_handle_t pmh) { - if (pmh != NULL && pmh->pmh_magic == PMH_MAGIC) { + if (pmh != NULL) { (void)_server_command(pmh, CP_QUIT, NULL, NULL); /* PM_ESERVEREOF */ (void)close(pmh->pmh_fd); free(pmh); @@ -488,7 +481,7 @@ pm_node_status(pm_handle_t pmh, char *node, pm_node_state_t *statep) struct list_struct *resp; pm_node_state_t state; - if (pmh == NULL || pmh->pmh_magic != PMH_MAGIC) + if (pmh == NULL) return PM_EBADHAND; if ((err = _server_command(pmh, CP_STATUS, node, &resp)) != PM_ESUCCESS) return err; @@ -513,7 +506,7 @@ pm_node_status(pm_handle_t pmh, char *node, pm_node_state_t *statep) pm_err_t pm_node_on(pm_handle_t pmh, char *node) { - if (pmh == NULL || pmh->pmh_magic != PMH_MAGIC) + if (pmh == NULL) return PM_EBADHAND; return _server_command(pmh, CP_ON, node, NULL); } @@ -523,7 +516,7 @@ pm_node_on(pm_handle_t pmh, char *node) pm_err_t pm_node_off(pm_handle_t pmh, char *node) { - if (pmh == NULL || pmh->pmh_magic != PMH_MAGIC) + if (pmh == NULL) return PM_EBADHAND; return _server_command(pmh, CP_OFF, node, NULL); } @@ -533,7 +526,7 @@ pm_node_off(pm_handle_t pmh, char *node) pm_err_t pm_node_cycle(pm_handle_t pmh, char *node) { - if (pmh == NULL || pmh->pmh_magic != PMH_MAGIC) + if (pmh == NULL) return PM_EBADHAND; return _server_command(pmh, CP_CYCLE, node, NULL); } diff --git a/src/powerman/parse_tab.y b/src/powerman/parse_tab.y index 4094f4c2..eec8057c 100644 --- a/src/powerman/parse_tab.y +++ b/src/powerman/parse_tab.y @@ -45,9 +45,7 @@ /* * A PreScript is a list of PreStmts. */ -#define PRESTMT_MAGIC 0x89786756 typedef struct { - int magic; StmtType type; /* delay/expect/send */ char *str; /* expect string, send fmt, setplugstate plug */ struct timeval tv; /* delay value */ @@ -384,7 +382,6 @@ static PreStmt *makePreStmt(StmtType type, char *str, char *tvstr, new = (PreStmt *) xmalloc(sizeof(PreStmt)); - new->magic = PRESTMT_MAGIC; new->type = type; new->mp1 = mp1str ? _strtolong(mp1str) : -1; new->mp2 = mp2str ? _strtolong(mp2str) : -1; @@ -400,8 +397,6 @@ static PreStmt *makePreStmt(StmtType type, char *str, char *tvstr, static void destroyPreStmt(PreStmt *p) { - assert(p->magic == PRESTMT_MAGIC); - p->magic = 0; if (p->str) xfree(p->str); p->str = NULL; @@ -473,7 +468,6 @@ static Interp *makeInterp(InterpState state, char *str) { Interp *new = (Interp *)xmalloc(sizeof(Interp)); - new->magic = INTERP_MAGIC; new->str = xstrdup(str); new->re = xregex_create(); new->state = state; @@ -483,8 +477,6 @@ static Interp *makeInterp(InterpState state, char *str) static void destroyInterp(Interp *i) { - assert(i->magic == INTERP_MAGIC); - i->magic = 0; xfree(i->str); xregex_destroy(i->re); xfree(i); @@ -500,10 +492,8 @@ static List copyInterpList(List il) itr = list_iterator_create(il); while((ip = list_next(itr))) { - assert(ip->magic == INTERP_MAGIC); icpy = makeInterp(ip->state, ip->str); xregex_compile(icpy->re, icpy->str, false); - assert(icpy->magic == INTERP_MAGIC); list_append(new, icpy); } list_iterator_destroy(itr); @@ -553,7 +543,6 @@ static Stmt *makeStmt(PreStmt *p) PreStmt *subp; ListIterator itr; - assert(p->magic == PRESTMT_MAGIC); stmt = (Stmt *) xmalloc(sizeof(Stmt)); stmt->type = p->type; switch (p->type) { @@ -580,7 +569,6 @@ static Stmt *makeStmt(PreStmt *p) stmt->u.foreach.stmts = list_create((ListDelF) destroyStmt); itr = list_iterator_create(p->prestmts); while((subp = list_next(itr))) { - assert(subp->magic == PRESTMT_MAGIC); list_append(stmt->u.foreach.stmts, makeStmt(subp)); } list_iterator_destroy(itr); @@ -590,7 +578,6 @@ static Stmt *makeStmt(PreStmt *p) stmt->u.ifonoff.stmts = list_create((ListDelF) destroyStmt); itr = list_iterator_create(p->prestmts); while((subp = list_next(itr))) { - assert(subp->magic == PRESTMT_MAGIC); list_append(stmt->u.ifonoff.stmts, makeStmt(subp)); } list_iterator_destroy(itr); diff --git a/src/powerman/pluglist.c b/src/powerman/pluglist.c index 2de187d9..2824e27a 100644 --- a/src/powerman/pluglist.c +++ b/src/powerman/pluglist.c @@ -29,16 +29,11 @@ #include "hostlist.h" #include "pluglist.h" -#define PLUGLISTITR_MAGIC 0xfeedfefe -#define PLUGLIST_MAGIC 0xfeedb0b - struct pluglist_iterator { - int magic; ListIterator itr; }; struct pluglist { - int magic; List pluglist; bool hardwired; }; @@ -69,7 +64,6 @@ PlugList pluglist_create(List plugnames) { PlugList pl = (PlugList) xmalloc(sizeof(struct pluglist)); - pl->magic = PLUGLIST_MAGIC; pl->pluglist = list_create((ListDelF)_destroy_plug); pl->hardwired = false; @@ -91,9 +85,7 @@ PlugList pluglist_create(List plugnames) void pluglist_destroy(PlugList pl) { assert(pl != NULL); - assert(pl->magic == PLUGLIST_MAGIC); - pl->magic = 0; list_destroy(pl->pluglist); xfree(pl); } @@ -163,7 +155,6 @@ pl_err_t pluglist_map(PlugList pl, char *nodelist, char *pluglist) pl_err_t res = EPL_SUCCESS; assert(pl != NULL); - assert(pl->magic == PLUGLIST_MAGIC); assert(nodelist != NULL); /* If pluglist is omitted we have one of two cases: @@ -228,7 +219,6 @@ PlugListIterator pluglist_iterator_create(PlugList pl) { PlugListIterator itr = (PlugListIterator)xmalloc(sizeof(struct pluglist_iterator)); - itr->magic = PLUGLISTITR_MAGIC; itr->itr = list_iterator_create(pl->pluglist); return itr; @@ -237,8 +227,6 @@ PlugListIterator pluglist_iterator_create(PlugList pl) void pluglist_iterator_destroy(PlugListIterator itr) { assert(itr != NULL); - assert(itr->magic == PLUGLISTITR_MAGIC); - itr->magic = 0; list_iterator_destroy(itr->itr); xfree(itr); } @@ -246,7 +234,6 @@ void pluglist_iterator_destroy(PlugListIterator itr) Plug *pluglist_next(PlugListIterator itr) { assert(itr != NULL); - assert(itr->magic == PLUGLISTITR_MAGIC); return (Plug *)list_next(itr->itr); } @@ -256,7 +243,6 @@ Plug *pluglist_find(PlugList pl, char *name) Plug *plug; assert(pl != NULL); - assert(pl->magic == PLUGLIST_MAGIC); assert(name != NULL); plug = _pluglist_find_any(pl, name); From 6bf6fd6df25622994713271748d48c4ee9f19920 Mon Sep 17 00:00:00 2001 From: Jim Garlick Date: Thu, 8 Feb 2024 13:13:57 -0800 Subject: [PATCH 2/2] move libcommon/debug.[ch] into powerman source Problem: the debug.c stuff is only used by powerman but it appears in libcommon. Move it into the powerman directory. --- src/libcommon/Makefile.am | 2 -- src/powerman/Makefile.am | 2 ++ src/{libcommon => powerman}/debug.c | 0 src/{libcommon => powerman}/debug.h | 0 4 files changed, 2 insertions(+), 2 deletions(-) rename src/{libcommon => powerman}/debug.c (100%) rename src/{libcommon => powerman}/debug.h (100%) diff --git a/src/libcommon/Makefile.am b/src/libcommon/Makefile.am index edde856a..6a654844 100644 --- a/src/libcommon/Makefile.am +++ b/src/libcommon/Makefile.am @@ -8,8 +8,6 @@ noinst_LTLIBRARIES = libcommon.la libcommon_la_SOURCES = \ argv.c \ argv.h \ - debug.c \ - debug.h \ error.c \ error.h \ hprintf.c \ diff --git a/src/powerman/Makefile.am b/src/powerman/Makefile.am index 685e438d..e2b64df5 100644 --- a/src/powerman/Makefile.am +++ b/src/powerman/Makefile.am @@ -40,6 +40,8 @@ powermand_SOURCES = \ client_proto.h \ daemon.c \ daemon.h \ + debug.c \ + debug.h \ device.c \ device.h \ device_pipe.c \ diff --git a/src/libcommon/debug.c b/src/powerman/debug.c similarity index 100% rename from src/libcommon/debug.c rename to src/powerman/debug.c diff --git a/src/libcommon/debug.h b/src/powerman/debug.h similarity index 100% rename from src/libcommon/debug.h rename to src/powerman/debug.h