From dc27cff8ab80074c8e0c5f9d1345bc23d942d410 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 2 May 2008 10:31:51 +0200 Subject: [PATCH] [awesome] Remove checking for value before p_delete()'ing memory Signed-off-by: Julien Danjou --- awesome-menu.c | 22 +++++++++++----------- awesome.c | 3 +-- common/xutil.c | 11 +++-------- ewmh.c | 4 +--- rules.c | 6 ++---- widgets/iconbox.c | 3 +-- 6 files changed, 19 insertions(+), 30 deletions(-) diff --git a/awesome-menu.c b/awesome-menu.c index c11091e3a..69d62a4a7 100644 --- a/awesome-menu.c +++ b/awesome-menu.c @@ -1140,28 +1140,29 @@ handle_kpress(xcb_key_press_event_t *e) #ifndef HAVE_GETLINE static int -getline(char ** buf, size_t* len, FILE* in) +getline(char **buf, size_t *len, FILE* in) { int i; - if (*buf) { + + if (*buf) p_delete(buf); - (*buf) = NULL; - } if (*len) *len = 0; - do { + do + { p_realloc(buf, *len + 10); (*len) += 10; - for (i = 0; i < 10 && !feof(in); i++) { + for (i = 0; i < 10 && !feof(in); i++) + { (*buf)[*len - 10 + i] = getchar(); - if ((*buf)[*len - 10 + i] == '\n' || - (*buf)[*len - 10 + i] == '\r') { + if ((*buf)[*len - 10 + i] == '\n' + || (*buf)[*len - 10 + i] == '\r') return (*len - 10 + i + 1); - } } } while(!feof(in)); + return -1; } #endif @@ -1195,8 +1196,7 @@ item_list_fill_stdin(void) } while((line_len = getline(&buf, &len, stdin)) != -1); - if(buf) - p_delete(&buf); + p_delete(&buf); return has_entry; } diff --git a/awesome.c b/awesome.c index 227bafb3b..367afdc94 100644 --- a/awesome.c +++ b/awesome.c @@ -128,8 +128,7 @@ scan() !(attr_r->map_state == XCB_MAP_STATE_VIEWABLE || window_getstate(wins[i]) == XCB_WM_ICONIC_STATE)) { - if(attr_r) - p_delete(&attr_r); + p_delete(&attr_r); continue; } diff --git a/common/xutil.c b/common/xutil.c index 864ec2ae3..7fda19ff9 100644 --- a/common/xutil.c +++ b/common/xutil.c @@ -57,8 +57,7 @@ xutil_gettextprop(xcb_connection_t *conn, xcb_window_t w, xcb_atom_t atom, if(!prop_r || !prop_r->value_len || prop_r->format != 8) { - if(prop_r) - p_delete(&prop_r); + p_delete(&prop_r); return false; } @@ -143,9 +142,7 @@ xutil_get_transient_for_hint(xcb_connection_t *c, xcb_window_t win, t_hint_r->length == 0) { *prop_win = XCB_NONE; - if(t_hint_r) - p_delete(&t_hint_r); - + p_delete(&t_hint_r); return false; } @@ -198,9 +195,7 @@ xutil_get_class_hint(xcb_connection_t *conn, xcb_window_t win) if(!class_hint_r || class_hint_r->type != STRING || class_hint_r->format != 8) { - if(class_hint_r) - p_delete(&class_hint_r); - + p_delete(&class_hint_r); return NULL; } diff --git a/ewmh.c b/ewmh.c index 939ae34f9..40866fdfc 100644 --- a/ewmh.c +++ b/ewmh.c @@ -437,9 +437,7 @@ ewmh_get_window_icon(xcb_window_t w) if(!r || r->type != CARDINAL || r->format != 32 || r->length < 2 || !(data = (uint32_t *) xcb_get_property_value(r))) { - if(r) - p_delete(&r); - + p_delete(&r); return NULL; } diff --git a/rules.c b/rules.c index 84d941572..adca0686f 100644 --- a/rules.c +++ b/rules.c @@ -71,10 +71,8 @@ rule_matching_client(client_t *c) snprintf(prop, len, "%s:%s:%s", ch->res_class ? ch->res_class : "", ch->res_name ? ch->res_name : "", c->name); - if(ch->res_class) - p_delete(&ch->res_class); - if(ch->res_name) - p_delete(&ch->res_name); + p_delete(&ch->res_class); + p_delete(&ch->res_name); p_delete(&ch); for(r = globalconf.rules; r; r = r->next) diff --git a/widgets/iconbox.c b/widgets/iconbox.c index fca651f6a..fa65ec1b4 100644 --- a/widgets/iconbox.c +++ b/widgets/iconbox.c @@ -75,8 +75,7 @@ iconbox_tell(widget_t *widget, char *property, char *new_value) if(!a_strcmp(property, "image")) { - if(d->image) - p_delete(&d->image); + p_delete(&d->image); d->image = a_strdup(new_value); } else if(!a_strcmp(property, "resize"))