mirror of
https://github.com/mintycube/dmenu.git
synced 2024-10-22 12:05:48 +00:00
highpriority: adding check for malloc failure + cleanup on exit
ref. https://git.suckless.org/sites/commit/9bbc02d13a89e427a046817771c6f8fd332d0167.html
This commit is contained in:
parent
67180f6288
commit
40ee9e2b7d
5
dmenu.c
5
dmenu.c
@ -271,6 +271,11 @@ 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]);
|
||||||
|
#if HIGHPRIORITY_PATCH
|
||||||
|
for (i = 0; i < hplength; ++i)
|
||||||
|
free(hpitems[i]);
|
||||||
|
free(hpitems);
|
||||||
|
#endif // HIGHPRIORITY_PATCH
|
||||||
drw_free(drw);
|
drw_free(drw);
|
||||||
XSync(dpy, False);
|
XSync(dpy, False);
|
||||||
XCloseDisplay(dpy);
|
XCloseDisplay(dpy);
|
||||||
|
@ -1,17 +1,20 @@
|
|||||||
static char **hpitems = NULL;
|
static char **hpitems = NULL;
|
||||||
static int hplength = 0;
|
static int hplength = 0;
|
||||||
|
|
||||||
static char**
|
static char **
|
||||||
tokenize(char *source, const char *delim, int *llen) {
|
tokenize(char *source, const char *delim, int *llen)
|
||||||
int listlength = 0;
|
{
|
||||||
char **list = malloc(1 * sizeof(char*));
|
int listlength = 0, list_size = 0;
|
||||||
char *token = strtok(source, delim);
|
char **list = NULL, *token;
|
||||||
|
|
||||||
|
token = strtok(source, delim);
|
||||||
while (token) {
|
while (token) {
|
||||||
if (!(list = realloc(list, sizeof(char*) * (listlength + 1))))
|
if (listlength + 1 >= list_size) {
|
||||||
die("Unable to realloc %d bytes\n", sizeof(char*) * (listlength + 1));
|
if (!(list = realloc(list, (list_size += 8) * sizeof(*list))))
|
||||||
|
die("Unable to realloc %zu bytes\n", list_size * sizeof(*list));
|
||||||
|
}
|
||||||
if (!(list[listlength] = strdup(token)))
|
if (!(list[listlength] = strdup(token)))
|
||||||
die("Unable to strdup %d bytes\n", strlen(token) + 1);
|
die("Unable to strdup %zu bytes\n", strlen(token) + 1);
|
||||||
token = strtok(NULL, delim);
|
token = strtok(NULL, delim);
|
||||||
listlength++;
|
listlength++;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user