rem: buffer = wmalloc(length);
add: buffer = malloc(length);
context: readMenuDirectory(WScreen *scr, char *title, char **path, char *command){    DIR *dir;    struct dirent *dentry;    struct stat stat_buf;    WMenu *menu=NULL;    char *buffer;    LinkedList *dirs = NULL, *files = NULL;    int length, i, have_space=0;    dir_data *data;    int stripExtension = 0;    i=0;    while (path[i]!=NULL) {	if (strcmp(path[i], "-noext")==0) {	    stripExtension = 1;	    i++;	    continue;	}        dir = opendir(path[i]);        if (!dir) {            i++;            continue;        }        while ((dentry = readdir(dir))) {            if (strcmp(dentry->d_name, ".")==0 ||                strcmp(dentry->d_name, "..")==0)                continue;	    if (dentry->d_name[0] == '.')		continue;            buffer = wmalloc(strlen(path[i])+strlen(dentry->d_name)+4);            if (!buffer) {                wsyserror(_("out of memory while constructing directory menu %s"),                         path[i]);                break;            }            strcpy(buffer, path[i]);            strcat(buffer, "/");            strcat(buffer, dentry->d_name);            if (stat(buffer, &stat_buf)!=0) {                wsyserror(_("%s:could not stat file \"%s\" in menu directory"),                          path[i], dentry->d_name);            } else {		Bool isFilePack = False;		data = NULL;                if (S_ISDIR(stat_buf.st_mode)		    && !(isFilePack = isFilePackage(dentry->d_name))) {                    /* access always returns success for user root */                    if (access(buffer, X_OK)==0) {                        /* Directory is accesible. Add to directory list */			data = (dir_data*) wmalloc(sizeof(dir_data));			data->name = wstrdup(dentry->d_name);			data->index = i;                        list_insert_sorted(data, &dirs, (int(*)())myCompare);                    }                } else if (S_ISREG(stat_buf.st_mode) || isFilePack) {                    /* Hack because access always returns X_OK success for user root */#define S_IXANY (S_IXUSR | S_IXGRP | S_IXOTH)                    if ((command!=NULL && access(buffer, R_OK)==0) ||                        (command==NULL && access(buffer, X_OK)==0 &&                         (stat_buf.st_mode & S_IXANY))) {			data = (dir_data*) wmalloc(sizeof(dir_data));			data->name = wstrdup(dentry->d_name);			data->index = i;                        list_insert_sorted(data, &files, (int(*)())myCompare);                    }                }            }            free(buffer);        }        closedir(dir);        i++;    }    if (!dirs && !files)        return NULL;    menu = wMenuCreate(scr, title, False);    menu->on_destroy = removeShortcutsForMenu;        while (dirs != NULL) {        /* New directory. Use same OPEN_MENU command that was used         * for the current directory. */        dir_data *d = (dir_data*)dirs->head;        length = strlen(path[d->index])+strlen(d->name)+6;        if (command)            length += strlen(command) + 6;        buffer = wmalloc(length);        if (!buffer) {            wsyserror(_("out of memory while constructing directory menu %s"),                     path[d->index]);            break;        }        have_space = strchr(path[d->index], ' ')!=NULL ||                     strchr(d->name, ' ')!=NULL;        if (have_space) {            buffer[0] = '"';            buffer[1] = 0;            strcat(buffer, path[d->index]);        } else {            strcpy(buffer, path[d->index]);        }        strcat(buffer, "/");        strcat(buffer, d->name);        if (have_space)            strcat(buffer, "\"");        if (command) {            strcat(buffer, " WITH ");            strcat(buffer, command);        }        addMenuEntry(menu, d->name, NULL, "OPEN_MENU", buffer, path[d->index]);        free(buffer);        if (dirs->head) {            if (d->name)                free(d->name);            free(dirs->head);        }        list_remove_head(&dirs);    }    while (files != NULL) {        /* executable: add as entry */        dir_data *f = (dir_data*) files->head;;        length = strlen(path[f->index])+strlen(f->name)+6;        if (command)            length += strlen(command);        buffer = wmalloc(length);        if (!buffer) {            wsyserror(_("out of memory while constructing directory menu %s"),                     path[f->index]);            break;        }        have_space = strchr(path[f->index], ' ')!=NULL ||                     strchr(f->name, ' ')!=NULL;        if (command!=NULL) {            strcpy(buffer, command);            strcat(buffer, " ");            if (have_space)                strcat(buffer, "\"");            strcat(buffer, path[f->index]);        } else {            if (have_space) {                buffer[0] = '"';                buffer[1] = 0;                strcat(buffer, path[f->index]);            } else {                strcpy(buffer, path[f->index]);            }        }        strcat(buffer, "/");        strcat(buffer, f->name);        if (have_space)            strcat(buffer, "\"");	if (stripExtension) {	    char *ptr = strrchr(f->name, '.');	    if (ptr && ptr!=f->name)		*ptr = 0;	}        addMenuEntry(menu, f->name, NULL, "EXEC", buffer, path[f->index]);        free(buffer);        if (files->head) {            if (f->name)                free(f->name);            free(files->head);        }        list_remove_head(&files);    }    return menu;}