libgrapheme

Freestanding C library for unicode string handling
git clone https://git.sinitax.com/suckless/libgrapheme
Log | Files | Refs | README | LICENSE | sfeed.txt

commit a25a1e7894ccb4f13b1d4f07d65ab172b09df478
parent 7ae94d162127b6408fbe7a7a9899bca2a451ebff
Author: Laslo Hunhold <dev@frign.de>
Date:   Tue, 14 Dec 2021 15:59:25 +0100

Fix memory leaks during header-generation

For extra-correctness, also clean up memory before exiting. This
only affects the generation phase, as libgrapheme itself has no memory
allocations.

Signed-off-by: Laslo Hunhold <dev@frign.de>

Diffstat:
Mgen/grapheme-test.c | 1+
Mgen/grapheme.c | 1+
Mgen/util.c | 23++++++++++++++++++++++-
Mgen/util.h | 4+++-
4 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/gen/grapheme-test.c b/gen/grapheme-test.c @@ -13,6 +13,7 @@ main(int argc, char *argv[]) segment_test_list_parse("data/GraphemeBreakTest.txt", &st, &numsegtests); segment_test_list_print(st, numsegtests, "grapheme_test", argv[0]); + segment_test_list_free(st, numsegtests); return 0; } diff --git a/gen/grapheme.c b/gen/grapheme.c @@ -87,6 +87,7 @@ main(int argc, char *argv[]) property_list_parse(segment_property, LEN(segment_property)); property_list_print(segment_property, LEN(segment_property), "grapheme_prop", argv[0]); + property_list_free(segment_property, LEN(segment_property)); return 0; } diff --git a/gen/util.c b/gen/util.c @@ -182,6 +182,9 @@ parse_file_with_callback(char *fname, int (*callback)(char *, char **, size_t, c exit(1); } } + + free(line); + free(field); } static int @@ -261,6 +264,18 @@ property_list_print(const struct property *prop, size_t numprops, printf("};\n"); } +void +property_list_free(struct property *prop, size_t numprops) +{ + size_t i; + + for (i = 0; i < numprops; i++) { + free(prop[i].table); + prop[i].table = NULL; + prop[i].tablelen = 0; + } +} + static int segment_test_callback(char *fname, char **field, size_t nfields, char *comment, void *payload) { @@ -349,7 +364,7 @@ segment_test_list_parse(char *fname, struct segment_test **st, size_t *numsegtes } void -segment_test_list_print(struct segment_test *st, size_t numsegtests, +segment_test_list_print(const struct segment_test *st, size_t numsegtests, const char *identifier, const char *progname) { size_t i, j; @@ -390,4 +405,10 @@ segment_test_list_print(struct segment_test *st, size_t numsegtests, printf("};\n"); } +void +segment_test_list_free(struct segment_test *st, size_t numsegtests) +{ + (void)numsegtests; + free(st); +} diff --git a/gen/util.h b/gen/util.h @@ -30,8 +30,10 @@ struct segment_test { void property_list_parse(struct property *, size_t); void property_list_print(const struct property *, size_t, const char *, const char *); +void property_list_free(struct property *, size_t); void segment_test_list_parse(char *, struct segment_test **, size_t *); -void segment_test_list_print(struct segment_test *, size_t, const char *, const char *); +void segment_test_list_print(const struct segment_test *, size_t, const char *, const char *); +void segment_test_list_free(struct segment_test *, size_t); #endif /* UTIL_H */