diff options
author | Jon Lund Steffensen <jonlst@gmail.com> | 2017-10-11 20:36:41 -0700 |
---|---|---|
committer | Jon Lund Steffensen <jonlst@gmail.com> | 2017-10-13 18:09:28 -0700 |
commit | b27acd687800499324381648036edd098c996524 (patch) | |
tree | 3197172546126fff94e8918ad2244f0788f60ee7 /src/gamma-randr.c | |
parent | Move module struct definitions to separate files (diff) | |
download | redshift-ng-b27acd687800499324381648036edd098c996524.tar.gz redshift-ng-b27acd687800499324381648036edd098c996524.tar.bz2 redshift-ng-b27acd687800499324381648036edd098c996524.tar.xz |
Allocate module data in init functions
Diffstat (limited to 'src/gamma-randr.c')
-rw-r--r-- | src/gamma-randr.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/src/gamma-randr.c b/src/gamma-randr.c index ef240b2..44bd497 100644 --- a/src/gamma-randr.c +++ b/src/gamma-randr.c @@ -43,29 +43,33 @@ static int -randr_init(randr_state_t *state) +randr_init(randr_state_t **state) { /* Initialize state. */ - state->screen_num = -1; - state->crtc_num = NULL; + *state = malloc(sizeof(randr_state_t)); + if (*state == NULL) return -1; - state->crtc_num_count = 0; - state->crtc_count = 0; - state->crtcs = NULL; + randr_state_t *s = *state; + s->screen_num = -1; + s->crtc_num = NULL; - state->preserve = 1; + s->crtc_num_count = 0; + s->crtc_count = 0; + s->crtcs = NULL; + + s->preserve = 1; xcb_generic_error_t *error; /* Open X server connection */ - state->conn = xcb_connect(NULL, &state->preferred_screen); + s->conn = xcb_connect(NULL, &s->preferred_screen); /* Query RandR version */ xcb_randr_query_version_cookie_t ver_cookie = - xcb_randr_query_version(state->conn, RANDR_VERSION_MAJOR, + xcb_randr_query_version(s->conn, RANDR_VERSION_MAJOR, RANDR_VERSION_MINOR); xcb_randr_query_version_reply_t *ver_reply = - xcb_randr_query_version_reply(state->conn, ver_cookie, &error); + xcb_randr_query_version_reply(s->conn, ver_cookie, &error); /* TODO What does it mean when both error and ver_reply is NULL? Apparently, we have to check both to avoid seg faults. */ @@ -73,7 +77,8 @@ randr_init(randr_state_t *state) int ec = (error != 0) ? error->error_code : -1; fprintf(stderr, _("`%s' returned error %d\n"), "RANDR Query Version", ec); - xcb_disconnect(state->conn); + xcb_disconnect(s->conn); + free(s); return -1; } @@ -82,7 +87,8 @@ randr_init(randr_state_t *state) fprintf(stderr, _("Unsupported RANDR version (%u.%u)\n"), ver_reply->major_version, ver_reply->minor_version); free(ver_reply); - xcb_disconnect(state->conn); + xcb_disconnect(s->conn); + free(s); return -1; } @@ -269,6 +275,8 @@ randr_free(randr_state_t *state) /* Close connection */ xcb_disconnect(state->conn); + + free(state); } static void |