From 65f3618d80f4b5d9b53e861ea15e0bfddad41305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?= =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?= Date: Sun, 25 Jul 2021 13:37:51 +0800 Subject: Functions to free places memory --- pikul.c | 20 ++++++++++++++++++++ pikul.h | 1 + 2 files changed, 21 insertions(+) diff --git a/pikul.c b/pikul.c index b40ee17..93bc664 100644 --- a/pikul.c +++ b/pikul.c @@ -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) { diff --git a/pikul.h b/pikul.h index 9b60181..4802547 100644 --- a/pikul.h +++ b/pikul.h @@ -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); -- cgit v1.2.3