tree-wide: return NULL from freeing functions

I started working on this because I wanted to change how
DEFINE_TRIVIAL_CLEANUP_FUNC is defined. Even independently of that change, it's
nice to make make things more consistent and predictable.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2021-02-16 17:15:10 +01:00
parent 5d160a2304
commit 75db809ae5
52 changed files with 154 additions and 165 deletions
+3 -2
View File
@@ -123,14 +123,15 @@ int barrier_create(Barrier *b) {
*
* If @b is NULL, this is a no-op.
*/
void barrier_destroy(Barrier *b) {
Barrier* barrier_destroy(Barrier *b) {
if (!b)
return;
return NULL;
b->me = safe_close(b->me);
b->them = safe_close(b->them);
safe_close_pair(b->pipe);
b->barriers = 0;
return NULL;
}
/**
+1 -1
View File
@@ -37,7 +37,7 @@ struct Barrier {
#define BARRIER_NULL {-1, -1, {-1, -1}, 0}
int barrier_create(Barrier *obj);
void barrier_destroy(Barrier *b);
Barrier* barrier_destroy(Barrier *b);
DEFINE_TRIVIAL_CLEANUP_FUNC(Barrier*, barrier_destroy);
+5 -5
View File
@@ -24,11 +24,11 @@
#define BITMAP_NUM_TO_REM(n) ((n) % (sizeof(uint64_t) * 8))
#define BITMAP_OFFSET_TO_NUM(offset, rem) ((offset) * sizeof(uint64_t) * 8 + (rem))
Bitmap *bitmap_new(void) {
Bitmap* bitmap_new(void) {
return new0(Bitmap, 1);
}
Bitmap *bitmap_copy(Bitmap *b) {
Bitmap* bitmap_copy(Bitmap *b) {
Bitmap *ret;
ret = bitmap_new();
@@ -43,12 +43,12 @@ Bitmap *bitmap_copy(Bitmap *b) {
return ret;
}
void bitmap_free(Bitmap *b) {
Bitmap* bitmap_free(Bitmap *b) {
if (!b)
return;
return NULL;
free(b->bitmaps);
free(b);
return mfree(b);
}
int bitmap_ensure_allocated(Bitmap **b) {
+3 -3
View File
@@ -12,10 +12,10 @@ typedef struct Bitmap {
size_t bitmaps_allocated;
} Bitmap;
Bitmap *bitmap_new(void);
Bitmap *bitmap_copy(Bitmap *b);
Bitmap* bitmap_new(void);
Bitmap* bitmap_copy(Bitmap *b);
int bitmap_ensure_allocated(Bitmap **b);
void bitmap_free(Bitmap *b);
Bitmap* bitmap_free(Bitmap *b);
int bitmap_set(Bitmap *b, unsigned n);
void bitmap_unset(Bitmap *b, unsigned n);
+3 -3
View File
@@ -61,9 +61,9 @@ static int match_job_removed(sd_bus_message *m, void *userdata, sd_bus_error *er
return 0;
}
void bus_wait_for_jobs_free(BusWaitForJobs *d) {
BusWaitForJobs* bus_wait_for_jobs_free(BusWaitForJobs *d) {
if (!d)
return;
return NULL;
set_free(d->jobs);
@@ -75,7 +75,7 @@ void bus_wait_for_jobs_free(BusWaitForJobs *d) {
free(d->name);
free(d->result);
free(d);
return mfree(d);
}
int bus_wait_for_jobs_new(sd_bus *bus, BusWaitForJobs **ret) {
+1 -1
View File
@@ -8,7 +8,7 @@
typedef struct BusWaitForJobs BusWaitForJobs;
int bus_wait_for_jobs_new(sd_bus *bus, BusWaitForJobs **ret);
void bus_wait_for_jobs_free(BusWaitForJobs *d);
BusWaitForJobs* bus_wait_for_jobs_free(BusWaitForJobs *d);
int bus_wait_for_jobs_add(BusWaitForJobs *d, const char *path);
int bus_wait_for_jobs(BusWaitForJobs *d, bool quiet, const char* const* extra_args);
int bus_wait_for_jobs_one(BusWaitForJobs *d, const char *path, bool quiet);
+3 -4
View File
@@ -33,14 +33,13 @@
/* Let's make sure that the microsecond component is safe to be stored in an 'int' */
assert_cc(INT_MAX >= USEC_PER_SEC);
static void chain_free(CalendarComponent *c) {
CalendarComponent *n;
static CalendarComponent* chain_free(CalendarComponent *c) {
while (c) {
n = c->next;
CalendarComponent *n = c->next;
free(c);
c = n;
}
return NULL;
}
DEFINE_TRIVIAL_CLEANUP_FUNC(CalendarComponent*, chain_free);
+3 -3
View File
@@ -1681,12 +1681,12 @@ static int verity_can_reuse(
return 0;
}
static inline void dm_deferred_remove_clean(char *name) {
static inline char* dm_deferred_remove_clean(char *name) {
if (!name)
return;
return NULL;
(void) sym_crypt_deactivate_by_name(NULL, name, CRYPT_DEACTIVATE_DEFERRED);
free(name);
return mfree(name);
}
DEFINE_TRIVIAL_CLEANUP_FUNC(char *, dm_deferred_remove_clean);
+3 -3
View File
@@ -3346,12 +3346,12 @@ int unit_file_preset_all(
return execute_preset(scope, &plus, &minus, &paths, config_path, NULL, mode, !!(flags & UNIT_FILE_FORCE), changes, n_changes);
}
static void unit_file_list_free_one(UnitFileList *f) {
static UnitFileList* unit_file_list_free_one(UnitFileList *f) {
if (!f)
return;
return NULL;
free(f->path);
free(f);
return mfree(f);
}
Hashmap* unit_file_list_free(Hashmap *h) {