t-reftable-readwrite: use free_names() instead of a for loop

free_names() as defined by reftable/basics.{c,h} frees a NULL terminated array of malloced strings along with the array itself. Use this function instead of a for loop to free such an array. Mentored-by: Patrick Steinhardt <ps@pks.im> Mentored-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Chandra Pratap committed Aug 13, 2024 at 20:04 UTC 3dd4fb13a080ba9cbcf047e94b7fc4ed35b6153e
1 file changed +3 -7
t/unit-tests/t-reftable-readwrite.c
+3 -7
@@ -7,6 +7,7 @@ https://developers.google.com/open-source/licenses/bsd
7 */
8
9 #include "test-lib.h"
10 +#include "reftable/basics.h"
11 #include "reftable/blocksource.h"
12 #include "reftable/reader.h"
13 #include "reftable/reftable-error.h"
@@ -413,7 +414,6 @@ static void t_table_read_api(void)
414 struct reftable_reader rd = { 0 };
415 struct reftable_block_source source = { 0 };
416 int err;
416 - int i;
417 struct reftable_log_record log = { 0 };
418 struct reftable_iterator it = { 0 };
419
@@ -432,10 +432,8 @@ static void t_table_read_api(void)
432 check_int(err, ==, REFTABLE_API_ERROR);
433
434 strbuf_release(&buf);
435 - for (i = 0; i < N; i++)
436 - reftable_free(names[i]);
435 + free_names(names);
436 reftable_iterator_destroy(&it);
438 - reftable_free(names);
437 reader_close(&rd);
438 strbuf_release(&buf);
439 }
@@ -498,9 +496,7 @@ static void t_table_read_write_seek(int index, int hash_id)
496 reftable_iterator_destroy(&it);
497
498 strbuf_release(&buf);
501 - for (i = 0; i < N; i++)
502 - reftable_free(names[i]);
503 - reftable_free(names);
499 + free_names(names);
500 reader_close(&rd);
501 }
502