Reduce some code around frees

This commit is contained in:
Orestis Floros 2018-08-01 18:08:26 +03:00
parent 565d38c5af
commit 50880db2c5
No known key found for this signature in database
GPG Key ID: E9AD9F32E401E38F
7 changed files with 8 additions and 15 deletions

View File

@ -216,7 +216,7 @@ static const char *get_string(const char *identifier) {
static void clear_stack(void) {
for (int c = 0; c < 10; c++) {
if (stack[c].type == STACK_STR && stack[c].val.str != NULL)
if (stack[c].type == STACK_STR)
free(stack[c].val.str);
stack[c].identifier = NULL;
stack[c].val.str = NULL;

View File

@ -54,9 +54,7 @@ void init_dpi(void) {
DLOG("Found Xft.dpi = %ld.\n", dpi);
init_dpi_end:
if (resource != NULL) {
free(resource);
}
free(resource);
if (database != NULL) {
xcb_xrm_database_free(database);

View File

@ -224,9 +224,7 @@ i3Font load_font(const char *pattern, const bool fallback) {
error->error_code);
}
}
if (error != NULL) {
free(error);
}
free(error);
font.pattern = sstrdup(pattern);
LOG("Using X font %s\n", pattern);
@ -275,8 +273,7 @@ void free_font(void) {
case FONT_TYPE_XCB: {
/* Close the font and free the info */
xcb_close_font(conn, savedFont->specific.xcb.id);
if (savedFont->specific.xcb.info)
free(savedFont->specific.xcb.info);
free(savedFont->specific.xcb.info);
break;
}
case FONT_TYPE_PANGO:

View File

@ -157,7 +157,7 @@ static long get_long(const char *identifier) {
// TODO move to a common util
static void clear_stack(void) {
for (int c = 0; c < 10; c++) {
if (stack[c].type == STACK_STR && stack[c].val.str != NULL)
if (stack[c].type == STACK_STR)
free(stack[c].val.str);
stack[c].identifier = NULL;
stack[c].val.str = NULL;

View File

@ -171,7 +171,7 @@ static long get_long(const char *identifier) {
static void clear_stack(void) {
for (int c = 0; c < 10; c++) {
if (stack[c].type == STACK_STR && stack[c].val.str != NULL)
if (stack[c].type == STACK_STR)
free(stack[c].val.str);
stack[c].identifier = NULL;
stack[c].val.str = NULL;

View File

@ -153,8 +153,7 @@ static int json_end_map(void *ctx) {
free(marks[i]);
}
free(marks);
marks = NULL;
FREE(marks);
num_marks = 0;
}

View File

@ -501,8 +501,7 @@ ssize_t slurp(const char *path, char **buf) {
fclose(f);
if ((ssize_t)n != stbuf.st_size) {
ELOG("File \"%s\" could not be read entirely: got %zd, want %" PRIi64 "\n", path, n, (int64_t)stbuf.st_size);
free(*buf);
*buf = NULL;
FREE(*buf);
return -1;
}
return (ssize_t)n;