From b27acd687800499324381648036edd098c996524 Mon Sep 17 00:00:00 2001 From: Jon Lund Steffensen Date: Wed, 11 Oct 2017 20:36:41 -0700 Subject: Allocate module data in init functions --- src/gamma-vidmode.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/gamma-vidmode.c') diff --git a/src/gamma-vidmode.c b/src/gamma-vidmode.c index 8d49363..8d1791a 100644 --- a/src/gamma-vidmode.c +++ b/src/gamma-vidmode.c @@ -38,18 +38,21 @@ static int -vidmode_init(vidmode_state_t *state) +vidmode_init(vidmode_state_t **state) { - state->screen_num = -1; - state->saved_ramps = NULL; + *state = malloc(sizeof(vidmode_state_t)); + if (*state == NULL) return -1; - state->preserve = 1; + vidmode_state_t *s = *state; + s->screen_num = -1; + s->saved_ramps = NULL; + + s->preserve = 1; /* Open display */ - state->display = XOpenDisplay(NULL); - if (state->display == NULL) { - fprintf(stderr, _("X request failed: %s\n"), - "XOpenDisplay"); + s->display = XOpenDisplay(NULL); + if (s->display == NULL) { + fprintf(stderr, _("X request failed: %s\n"), "XOpenDisplay"); return -1; } @@ -121,6 +124,8 @@ vidmode_free(vidmode_state_t *state) /* Close display connection */ XCloseDisplay(state->display); + + free(state); } static void -- cgit v1.2.3-70-g09d2