XQuartz: Drop calls to alloca

This makes us more consistent with the rest of the codebase, using xalloc/xfree

Signed-off-by: Jeremy Huddleston <jeremyhu@freedesktop.org>
Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
Jeremy Huddleston 2009-11-30 11:03:59 -08:00 committed by Keith Packard
parent 66a9616d64
commit f4fc340672
3 changed files with 28 additions and 9 deletions

View File

@ -306,12 +306,12 @@ int main(int argc, char **argv, char **envp) {
/* We have fixed-size string lengths due to limitations in IPC, /* We have fixed-size string lengths due to limitations in IPC,
* so we need to copy our argv and envp. * so we need to copy our argv and envp.
*/ */
newargv = (string_array_t)alloca(argc * sizeof(string_t)); newargv = (string_array_t)malloc(argc * sizeof(string_t));
newenvp = (string_array_t)alloca(envpc * sizeof(string_t)); newenvp = (string_array_t)malloc(envpc * sizeof(string_t));
if(!newargv || !newenvp) { if(!newargv || !newenvp) {
fprintf(stderr, "Xquartz: Memory allocation failure\n"); fprintf(stderr, "Xquartz: Memory allocation failure\n");
exit(EXIT_FAILURE); return EXIT_FAILURE;
} }
for(i=0; i < argc; i++) { for(i=0; i < argc; i++) {
@ -322,6 +322,10 @@ int main(int argc, char **argv, char **envp) {
} }
kr = start_x11_server(mp, newargv, argc, newenvp, envpc); kr = start_x11_server(mp, newargv, argc, newenvp, envpc);
free(newargv);
free(newenvp);
if (kr != KERN_SUCCESS) { if (kr != KERN_SUCCESS) {
fprintf(stderr, "Xquartz: start_x11_server: %s\n", mach_error_string(kr)); fprintf(stderr, "Xquartz: start_x11_server: %s\n", mach_error_string(kr));
return EXIT_FAILURE; return EXIT_FAILURE;

View File

@ -34,6 +34,7 @@
#include "x-hook.h" #include "x-hook.h"
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
#include "os.h"
#define CELL_NEW(f,d) X_PFX (list_prepend) ((x_list *) (f), (d)) #define CELL_NEW(f,d) X_PFX (list_prepend) ((x_list *) (f), (d))
#define CELL_FREE(c) X_PFX (list_free_1) (c) #define CELL_FREE(c) X_PFX (list_free_1) (c)
@ -79,9 +80,13 @@ X_PFX (hook_run) (x_list *lst, void *arg)
int length, i; int length, i;
length = X_PFX (list_length) (lst); length = X_PFX (list_length) (lst);
fun = alloca (sizeof (x_hook_function *) * length); fun = xalloc (sizeof (x_hook_function *) * length);
data = alloca (sizeof (void *) * length); data = xalloc (sizeof (void *) * length);
if(!fun || !data) {
FatalError("Failed to allocate memory in %s\n", __func__);
}
for (i = 0, node = lst; node != NULL; node = node->next, i++) for (i = 0, node = lst; node != NULL; node = node->next, i++)
{ {
cell = node->data; cell = node->data;
@ -93,6 +98,9 @@ X_PFX (hook_run) (x_list *lst, void *arg)
{ {
(*fun[i]) (arg, data[i]); (*fun[i]) (arg, data[i]);
} }
xfree(fun);
xfree(data);
} }
X_EXTERN void X_EXTERN void

View File

@ -95,7 +95,10 @@ load_cursor(CursorPtr src, int screen)
const uint32_t *be_data=(uint32_t *) src->bits->argb; const uint32_t *be_data=(uint32_t *) src->bits->argb;
unsigned i; unsigned i;
rowbytes = src->bits->width * sizeof (CARD32); rowbytes = src->bits->width * sizeof (CARD32);
data=alloca (rowbytes * src->bits->height); data = xalloc(rowbytes * src->bits->height);
if(!data) {
FatalError("Failed to allocate memory in %s\n", __func__);
}
for(i=0;i<(src->bits->width*src->bits->height);i++) for(i=0;i<(src->bits->width*src->bits->height);i++)
data[i]=ntohl(be_data[i]); data[i]=ntohl(be_data[i]);
#endif #endif
@ -118,8 +121,11 @@ load_cursor(CursorPtr src, int screen)
/* round up to 8 pixel boundary so we can convert whole bytes */ /* round up to 8 pixel boundary so we can convert whole bytes */
rowbytes = ((src->bits->width * 4) + 31) & ~31; rowbytes = ((src->bits->width * 4) + 31) & ~31;
data = alloca(rowbytes * src->bits->height); data = xalloc(rowbytes * src->bits->height);
if(!data) {
FatalError("Failed to allocate memory in %s\n", __func__);
}
if (!src->bits->emptyMask) if (!src->bits->emptyMask)
{ {
ycount = src->bits->height; ycount = src->bits->height;
@ -168,6 +174,7 @@ load_cursor(CursorPtr src, int screen)
} }
err = xp_set_cursor(width, height, hot_x, hot_y, data, rowbytes); err = xp_set_cursor(width, height, hot_x, hot_y, data, rowbytes);
xfree(data);
return err == Success; return err == Success;
} }