Don't test for NULL before calling free(3)

free(3) accepts NULL, since the oldest ISO C.  I guess the
paranoid code was taking care of prehistoric implementations of
free(3).  I've never known of an implementation that doesn't
conform to this, so let's simplify this.

Remove xfree(3), which was effectively an equivalent of free(3).

Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alex Colomar
2022-09-28 22:03:52 +02:00
committed by Iker Pedrosa
parent 1b0e189e35
commit 0d9799de04
11 changed files with 18 additions and 58 deletions

View File

@@ -85,9 +85,7 @@ int lrename (const char *old, const char *new)
res = rename (old, new);
#ifdef __GLIBC__
if (NULL != r) {
free (r);
}
free (r);
#endif /* __GLIBC__ */
return res;
@@ -337,9 +335,7 @@ static void free_linked_list (struct commonio_db *db)
p = db->head;
db->head = p->next;
if (NULL != p->line) {
free (p->line);
}
free (p->line);
if (NULL != p->eptr) {
db->ops->free (p->eptr);
@@ -395,10 +391,8 @@ int commonio_lock_nowait (struct commonio_db *db, bool log)
err = 1;
}
cleanup_ENOMEM:
if (file)
free(file);
if (lock)
free(lock);
free(file);
free(lock);
return err;
}
@@ -1200,9 +1194,7 @@ int commonio_remove (struct commonio_db *db, const char *name)
commonio_del_entry (db, p);
if (NULL != p->line) {
free (p->line);
}
free (p->line);
if (NULL != p->eptr) {
db->ops->free (p->eptr);

View File

@@ -388,10 +388,7 @@ int putdef_str (const char *name, const char *value)
return -1;
}
if (NULL != d->value) {
free (d->value);
}
free (d->value);
d->value = cp;
return 0;
}

View File

@@ -418,9 +418,7 @@ static int split_groups (unsigned int max_members)
/* Shift all the members */
/* The number of members in new_gptr will be check later */
for (i = 0; NULL != new_gptr->gr_mem[i + max_members]; i++) {
if (NULL != new_gptr->gr_mem[i]) {
free (new_gptr->gr_mem[i]);
}
free (new_gptr->gr_mem[i]);
new_gptr->gr_mem[i] = new_gptr->gr_mem[i + max_members];
new_gptr->gr_mem[i + max_members] = NULL;
}

View File

@@ -483,7 +483,6 @@ extern bool valid (const char *, const struct passwd *);
extern /*@maynotreturn@*/ /*@only@*//*@out@*//*@notnull@*/void *xmalloc (size_t size)
/*@ensures MaxSet(result) == (size - 1); @*/;
extern /*@maynotreturn@*/ /*@only@*//*@notnull@*/char *xstrdup (const char *);
extern void xfree(void *ap);
/* xgetpwnam.c */
extern /*@null@*/ /*@only@*/struct passwd *xgetpwnam (const char *);

View File

@@ -54,8 +54,7 @@ static char **list (char *s)
rbuf = malloc (size * sizeof (char *));
}
if (!rbuf) {
if (members)
free (members);
free (members);
members = 0;
size = 0;
return (char **) 0;
@@ -89,8 +88,7 @@ struct group *sgetgrent (const char *buf)
if (strlen (buf) + 1 > size) {
/* no need to use realloc() here - just free it and
allocate a larger block */
if (grpbuf)
free (grpbuf);
free (grpbuf);
size = strlen (buf) + 1000; /* at least: strlen(buf) + 1 */
grpbuf = malloc (size);
if (!grpbuf) {

View File

@@ -380,9 +380,7 @@ shadowtcb_status shadowtcb_set_user (const char* name)
return SHADOWTCB_SUCCESS;
}
if (NULL != stored_tcb_user) {
free (stored_tcb_user);
}
free (stored_tcb_user);
stored_tcb_user = strdup (name);
if (NULL == stored_tcb_user) {