]> git.sur5r.net Git - i3/i3/commitdiff
Merge pull request #3022 from orestisf1993/i3bar-leaks
authorIngo Bürk <admin@airblader.de>
Sun, 3 Dec 2017 18:51:25 +0000 (19:51 +0100)
committerGitHub <noreply@github.com>
Sun, 3 Dec 2017 18:51:25 +0000 (19:51 +0100)
Fix i3bar leaks

1  2 
i3bar/src/config.c
i3bar/src/xcb.c

diff --combined i3bar/src/config.c
index b98d41232449f2e29a54e3f4e07d08f02aac4fc5,edccd3c66f811f2cba68147ba7245bd826bdef3b..79e106c07447f9d56a994958b34229dc8dab216b
@@@ -107,34 -107,34 +107,34 @@@ static int config_string_cb(void *param
  
      if (!strcmp(cur_key, "mode")) {
          DLOG("mode = %.*s, len = %d\n", len, val, len);
 -        config.hide_on_modifier = (len == 4 && !strncmp((const char *)val, "dock", strlen("dock")) ? M_DOCK
 -                                                                                                   : (len == 4 && !strncmp((const char *)val, "hide", strlen("hide")) ? M_HIDE
 -                                                                                                                                                                      : M_INVISIBLE));
 +        config.hide_on_modifier = (len == strlen("dock") && !strncmp((const char *)val, "dock", strlen("dock")) ? M_DOCK
 +                                                                                                                : (len == strlen("hide") && !strncmp((const char *)val, "hide", strlen("hide")) ? M_HIDE
 +                                                                                                                                                                                                : M_INVISIBLE));
          return 1;
      }
  
      if (!strcmp(cur_key, "hidden_state")) {
          DLOG("hidden_state = %.*s, len = %d\n", len, val, len);
 -        config.hidden_state = (len == 4 && !strncmp((const char *)val, "hide", strlen("hide")) ? S_HIDE : S_SHOW);
 +        config.hidden_state = (len == strlen("hide") && !strncmp((const char *)val, "hide", strlen("hide")) ? S_HIDE : S_SHOW);
          return 1;
      }
  
      if (!strcmp(cur_key, "modifier")) {
          DLOG("modifier = %.*s\n", len, val);
 -        if (len == 4 && !strncmp((const char *)val, "none", strlen("none"))) {
 +        if (len == strlen("none") && !strncmp((const char *)val, "none", strlen("none"))) {
              config.modifier = XCB_NONE;
              return 1;
          }
  
 -        if (len == 5 && !strncmp((const char *)val, "shift", strlen("shift"))) {
 +        if (len == strlen("shift") && !strncmp((const char *)val, "shift", strlen("shift"))) {
              config.modifier = ShiftMask;
              return 1;
          }
 -        if (len == 4 && !strncmp((const char *)val, "ctrl", strlen("ctrl"))) {
 +        if (len == strlen("ctrl") && !strncmp((const char *)val, "ctrl", strlen("ctrl"))) {
              config.modifier = ControlMask;
              return 1;
          }
 -        if (len == 4 && !strncmp((const char *)val, "Mod", strlen("Mod"))) {
 +        if (len == strlen("Mod") + 1 && !strncmp((const char *)val, "Mod", strlen("Mod"))) {
              switch (val[3]) {
                  case '1':
                      config.modifier = Mod1Mask;
  
      if (!strcmp(cur_key, "position")) {
          DLOG("position = %.*s\n", len, val);
 -        config.position = (len == 3 && !strncmp((const char *)val, "top", strlen("top")) ? POS_TOP : POS_BOT);
 +        config.position = (len == strlen("top") && !strncmp((const char *)val, "top", strlen("top")) ? POS_TOP : POS_BOT);
          return 1;
      }
  
  
      if (!strcmp(cur_key, "font")) {
          DLOG("font = %.*s\n", len, val);
+         FREE(config.fontname);
          sasprintf(&config.fontname, "%.*s", len, val);
          return 1;
      }
diff --combined i3bar/src/xcb.c
index 98f0dcbe02296fdb49ee5af8495d17940871022f,815f41fdf3678eea41ad1f4ab4041430925f35f4..1a9240fb996dae3e14ca162650ec4eef7dbac656
@@@ -83,6 -83,7 +83,6 @@@ int mod_pressed = 0
  
  /* Event watchers, to interact with the user */
  ev_prepare *xcb_prep;
 -ev_check *xcb_chk;
  ev_io *xcb_io;
  ev_io *xkb_io;
  
@@@ -1074,11 -1075,21 +1074,11 @@@ static void handle_resize_request(xcb_r
  }
  
  /*
 - * This function is called immediately before the main loop locks. We flush xcb
 - * then (and only then)
 + * This function is called immediately before the main loop locks. We check for
 + * events from X11, handle them, then flush our outgoing queue.
   *
   */
  void xcb_prep_cb(struct ev_loop *loop, ev_prepare *watcher, int revents) {
 -    xcb_flush(xcb_connection);
 -}
 -
 -/*
 - * This function is called immediately after the main loop locks, so when one
 - * of the watchers registered an event.
 - * We check whether an X-Event arrived and handle it.
 - *
 - */
 -void xcb_chk_cb(struct ev_loop *loop, ev_check *watcher, int revents) {
      xcb_generic_event_t *event;
  
      if (xcb_connection_has_error(xcb_connection)) {
          }
          free(event);
      }
 +
 +    xcb_flush(xcb_connection);
  }
  
  /*
@@@ -1258,12 -1267,21 +1258,12 @@@ char *init_xcb_early() 
      /* The various watchers to communicate with xcb */
      xcb_io = smalloc(sizeof(ev_io));
      xcb_prep = smalloc(sizeof(ev_prepare));
 -    xcb_chk = smalloc(sizeof(ev_check));
  
      ev_io_init(xcb_io, &xcb_io_cb, xcb_get_file_descriptor(xcb_connection), EV_READ);
      ev_prepare_init(xcb_prep, &xcb_prep_cb);
 -    ev_check_init(xcb_chk, &xcb_chk_cb);
 -
 -    /* Within an event loop iteration, run the xcb_chk watcher last: other
 -     * watchers might call xcb_flush(), which, unexpectedly, can also read
 -     * events into the queue (see _xcb_conn_wait). Hence, we need to drain xcb’s
 -     * queue last, otherwise we risk dead-locking. */
 -    ev_set_priority(xcb_chk, EV_MINPRI);
  
      ev_io_start(main_loop, xcb_io);
      ev_prepare_start(main_loop, xcb_prep);
 -    ev_check_start(main_loop, xcb_chk);
  
      /* Now we get the atoms and save them in a nice data structure */
      get_atoms();
@@@ -1499,16 -1517,7 +1499,7 @@@ void init_tray_colors(void) 
   *
   */
  void clean_xcb(void) {
-     i3_output *o_walk;
-     free_workspaces();
-     SLIST_FOREACH(o_walk, outputs, slist) {
-         destroy_window(o_walk);
-         FREE(o_walk->trayclients);
-         FREE(o_walk->workspaces);
-         FREE(o_walk->name);
-     }
-     FREE_SLIST(outputs, i3_output);
-     FREE(outputs);
+     free_outputs();
  
      free_font();
  
      xcb_aux_sync(xcb_connection);
      xcb_disconnect(xcb_connection);
  
 -    ev_check_stop(main_loop, xcb_chk);
      ev_prepare_stop(main_loop, xcb_prep);
      ev_io_stop(main_loop, xcb_io);
  
 -    FREE(xcb_chk);
      FREE(xcb_prep);
      FREE(xcb_io);
  }