diff options
author | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2021-07-25 13:37:51 +0800 |
---|---|---|
committer | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2021-07-25 13:37:51 +0800 |
commit | 65f3618d80f4b5d9b53e861ea15e0bfddad41305 (patch) | |
tree | 37fa004dfb824a08fb8ee1b27af1043028bf0aea | |
parent | 017f4c4312444c1ba386d6e0f6192fdc40f03c01 (diff) |
Functions to free places memory
-rw-r--r-- | pikul.c | 20 | ||||
-rw-r--r-- | pikul.h | 1 |
2 files changed, 21 insertions, 0 deletions
@@ -225,6 +225,26 @@ struct pikul_place **pikul_destinations(enum pikul_company company) return (struct pikul_place **)shipping->data; } +static inline void free_place(struct pikul_place *place) +{ + if (place->province) + free(place->province); + if (place->city) + free(place->city); + if (place->district) + free(place->district); + free(place->code); + free(place); +} + +void pikul_free_places(struct pikul_place **places) +{ + size_t i = 0; + while (places[i]) + free_place(places[i++]); + free(places); +} + struct pikul_service **pikul_services(enum pikul_company company, const char *origin, const char *destination, double weight) { @@ -29,6 +29,7 @@ extern "C" { void pikul_init(enum pikul_company company, char *provisions[]); struct pikul_place **pikul_origins(enum pikul_company company); struct pikul_place **pikul_destinations(enum pikul_company company); +void pikul_free_places(struct pikul_place **places); struct pikul_service **pikul_services(enum pikul_company company, const char *origin, const char *destination, double weight); void pikul_free_services(struct pikul_service **services); |