From: Arran Cudbard-Bell Date: Thu, 25 Jan 2018 03:11:29 +0000 (-0700) Subject: Rename cursor free functions to make it clearer what they do X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b0b5c0f2255ce1ff894cd9fbf774f4fa73a867d;p=thirdparty%2Ffreeradius-server.git Rename cursor free functions to make it clearer what they do --- diff --git a/src/include/cursor.h b/src/include/cursor.h index bcf660d5d39..b39ba175cfd 100644 --- a/src/include/cursor.h +++ b/src/include/cursor.h @@ -81,7 +81,7 @@ void *fr_cursor_remove(fr_cursor_t *cursor) CC_HINT(nonnull); void *fr_cursor_replace(fr_cursor_t *cursor, void *r) CC_HINT(nonnull); -void fr_cursor_list_free(fr_cursor_t *cursor) CC_HINT(nonnull); +void fr_cursor_free_list(fr_cursor_t *cursor) CC_HINT(nonnull); /** Initialise a cursor with runtime talloc type safety checks and a custom iterator * @@ -138,14 +138,14 @@ void fr_cursor_list_free(fr_cursor_t *cursor) CC_HINT(nonnull); void *_fr_cursor_init(fr_cursor_t *cursor, void * const *head, size_t offset, fr_cursor_iter_t iter, void const *ctx, char const *type); -/** talloc_free the current item, and all subsequent items +/** talloc_free the current item * * @param[in] cursor to free items from. */ -static inline void fr_cursor_free(fr_cursor_t *cursor) +static inline void fr_cursor_free_item(fr_cursor_t *cursor) { - void *v; if (!cursor) return; - while ((v = fr_cursor_remove(cursor))) talloc_free(v); + + talloc_free(fr_cursor_remove(cursor)); } #endif diff --git a/src/lib/util/cursor.c b/src/lib/util/cursor.c index 278a16ea28d..3fdd08f5e31 100644 --- a/src/lib/util/cursor.c +++ b/src/lib/util/cursor.c @@ -521,11 +521,11 @@ void * CC_HINT(hot) fr_cursor_replace(fr_cursor_t *cursor, void *r) * * @param[in] cursor to free items in. */ -void fr_cursor_list_free(fr_cursor_t *cursor) +void fr_cursor_free_list(fr_cursor_t *cursor) { void *v; - if (!*cursor->head) return; /* noop */ + if (!*(cursor->head)) return; /* noop */ do { v = fr_cursor_remove(cursor); @@ -1670,7 +1670,7 @@ void test_cursor_free(void) fr_cursor_append(&cursor, item3); fr_cursor_next(&cursor); - fr_cursor_list_free(&cursor); + fr_cursor_free_list(&cursor); TEST_CHECK(fr_cursor_current(&cursor) == NULL); TEST_CHECK(!fr_cursor_list_prev_peek(&cursor)); diff --git a/src/main/map.c b/src/main/map.c index 5e565d47a32..3166838f5c5 100644 --- a/src/main/map.c +++ b/src/main/map.c @@ -937,10 +937,10 @@ int map_to_list_mod(TALLOC_CTX *ctx, vp_list_mod_t **out, if (!n_vb) { xlat_error: fr_cursor_head(&from); - fr_cursor_free(&from); + fr_cursor_free_list(&from); fr_cursor_head(&values); - fr_cursor_free(&values); + fr_cursor_free_list(&values); goto error; } @@ -1005,7 +1005,7 @@ int map_to_list_mod(TALLOC_CTX *ctx, vp_list_mod_t **out, if (!n_vb) { attr_error: fr_cursor_head(&values); - fr_cursor_free(&values); + fr_cursor_free_list(&values); goto error; } @@ -1045,7 +1045,7 @@ int map_to_list_mod(TALLOC_CTX *ctx, vp_list_mod_t **out, if (!n_vb) { data_error: fr_cursor_head(&values); - fr_cursor_free(&values); + fr_cursor_free_list(&values); goto error; } /* @@ -1201,7 +1201,7 @@ static VALUE_PAIR *map_list_mod_to_vps(TALLOC_CTX *ctx, vp_list_mod_t const *vlm vp = map_list_mod_to_vp(ctx, mod->lhs, vb); if (!vp) { fr_cursor_head(&cursor); - fr_cursor_free(&cursor); + fr_cursor_free_list(&cursor); return NULL; } fr_cursor_insert(&cursor, vp); diff --git a/src/main/xlat_eval.c b/src/main/xlat_eval.c index 4ce56650a02..3dcf84169e9 100644 --- a/src/main/xlat_eval.c +++ b/src/main/xlat_eval.c @@ -741,7 +741,7 @@ xlat_action_t xlat_frame_eval(TALLOC_CTX *ctx, fr_cursor_t *out, xlat_exp_t cons node->fmt); if (xlat_eval_one_letter(ctx, out, request, node->fmt[0]) == XLAT_ACTION_FAIL) { fail: - fr_cursor_free(out); /* Only frees what we've added during this call */ + fr_cursor_free_list(out); /* Only frees what we've added during this call */ xa = XLAT_ACTION_FAIL; goto finish; } @@ -884,11 +884,11 @@ static char *xlat_aprint(TALLOC_CTX *ctx, REQUEST *request, xlat_exp_t const * c */ if (fr_value_box_cast(ctx, &string, FR_TYPE_STRING, NULL, head) < 0) { RPERROR("Casting one letter expansion to string failed"); - fr_cursor_free(&cursor); + fr_cursor_free_list(&cursor); return NULL; } memcpy(&str, &string.vb_strvalue, sizeof(str)); - fr_cursor_free(&cursor); + fr_cursor_free_list(&cursor); break; case XLAT_ATTRIBUTE: @@ -907,7 +907,7 @@ static char *xlat_aprint(TALLOC_CTX *ctx, REQUEST *request, xlat_exp_t const * c if (!str) { attr_error: RPERROR("Printing box to string failed"); - fr_cursor_free(&cursor); + fr_cursor_free_list(&cursor); return NULL; } @@ -925,7 +925,7 @@ static char *xlat_aprint(TALLOC_CTX *ctx, REQUEST *request, xlat_exp_t const * c str = talloc_strdup_append_buffer(str, more); talloc_free(more); } - fr_cursor_free(&cursor); + fr_cursor_free_list(&cursor); break; case XLAT_VIRTUAL: diff --git a/src/modules/rlm_eap/types/rlm_eap_ttls/ttls.c b/src/modules/rlm_eap/types/rlm_eap_ttls/ttls.c index 5feff3c1b86..c8c1a9b6bdf 100644 --- a/src/modules/rlm_eap/types/rlm_eap_ttls/ttls.c +++ b/src/modules/rlm_eap/types/rlm_eap_ttls/ttls.c @@ -158,7 +158,7 @@ static ssize_t eap_ttls_decode_pair(TALLOC_CTX *ctx, fr_cursor_t *cursor, fr_dic if ((end - p) < 8) { fr_strerror_printf("Malformed diameter VPs. Needed at least 8 bytes, got %zu bytes", end - p); error: - fr_cursor_list_free(cursor); + fr_cursor_free_list(cursor); return -1; }