Skip to content

Commit be8ad54

Browse files
committed
Simplify the use of free
Quote from man pages: The free() function deallocates the memory allocation pointed to by ptr. If ptr is a NULL pointer, no operation is performed. Thus, no extra if statement is required before the invocation of free.
1 parent e237ecd commit be8ad54

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

src/draw.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,7 @@ static twin_xform_t *twin_pixmap_init_xform(twin_pixmap_t *pixmap,
421421

422422
static void twin_pixmap_free_xform(twin_xform_t *xform)
423423
{
424-
if (xform)
425-
free(xform);
424+
free(xform);
426425
}
427426

428427
#define FX(x) twin_int_to_fixed(x)

src/path.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,8 @@ twin_path_t *twin_path_create(void)
450450

451451
void twin_path_destroy(twin_path_t *path)
452452
{
453-
if (path->points)
454-
free(path->points);
455-
if (path->sublen)
456-
free(path->sublen);
453+
free(path->points);
454+
free(path->sublen);
457455
free(path);
458456
}
459457

src/window.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ void twin_window_destroy(twin_window_t *window)
7676
{
7777
twin_window_hide(window);
7878
twin_pixmap_destroy(window->pixmap);
79-
if (window->name)
80-
free(window->name);
79+
free(window->name);
8180
free(window);
8281
}
8382

@@ -149,8 +148,7 @@ void twin_window_style_size(twin_window_style_t style, twin_rect_t *size)
149148

150149
void twin_window_set_name(twin_window_t *window, const char *name)
151150
{
152-
if (window->name)
153-
free(window->name);
151+
free(window->name);
154152
window->name = malloc(strlen(name) + 1);
155153
if (window->name)
156154
strcpy(window->name, name);

0 commit comments

Comments
 (0)