free all allocated items, use %zu for size_t

`items` itself is not checked for NULL as calling free on NULL is defined to be
a no-op.
This commit is contained in:
NRK 2022-03-25 22:51:09 +01:00 committed by Hiltjo Posthuma
parent 22511c41d5
commit b43ec0577f
1 changed files with 6 additions and 3 deletions

View File

@ -104,6 +104,9 @@ cleanup(void)
XUngrabKey(dpy, AnyKey, AnyModifier, root); XUngrabKey(dpy, AnyKey, AnyModifier, root);
for (i = 0; i < SchemeLast; i++) for (i = 0; i < SchemeLast; i++)
free(scheme[i]); free(scheme[i]);
for (i = 0; items && items[i].text; ++i)
free(items[i].text);
free(items);
drw_free(drw); drw_free(drw);
XSync(dpy, False); XSync(dpy, False);
XCloseDisplay(dpy); XCloseDisplay(dpy);
@ -239,7 +242,7 @@ match(void)
/* separate input text into tokens to be matched individually */ /* separate input text into tokens to be matched individually */
for (s = strtok(buf, " "); s; tokv[tokc - 1] = s, s = strtok(NULL, " ")) for (s = strtok(buf, " "); s; tokv[tokc - 1] = s, s = strtok(NULL, " "))
if (++tokc > tokn && !(tokv = realloc(tokv, ++tokn * sizeof *tokv))) if (++tokc > tokn && !(tokv = realloc(tokv, ++tokn * sizeof *tokv)))
die("cannot realloc %u bytes:", tokn * sizeof *tokv); die("cannot realloc %zu bytes:", tokn * sizeof *tokv);
len = tokc ? strlen(tokv[0]) : 0; len = tokc ? strlen(tokv[0]) : 0;
matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL; matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL;
@ -553,11 +556,11 @@ readstdin(void)
for (i = 0; fgets(buf, sizeof buf, stdin); i++) { for (i = 0; fgets(buf, sizeof buf, stdin); i++) {
if (i + 1 >= size / sizeof *items) if (i + 1 >= size / sizeof *items)
if (!(items = realloc(items, (size += BUFSIZ)))) if (!(items = realloc(items, (size += BUFSIZ))))
die("cannot realloc %u bytes:", size); die("cannot realloc %zu bytes:", size);
if ((p = strchr(buf, '\n'))) if ((p = strchr(buf, '\n')))
*p = '\0'; *p = '\0';
if (!(items[i].text = strdup(buf))) if (!(items[i].text = strdup(buf)))
die("cannot strdup %u bytes:", strlen(buf) + 1); die("cannot strdup %zu bytes:", strlen(buf) + 1);
items[i].out = 0; items[i].out = 0;
} }
if (items) if (items)