diff --git a/src/poly.c b/src/poly.c index 722c8e5..e057f9e 100644 --- a/src/poly.c +++ b/src/poly.c @@ -110,9 +110,7 @@ void poly_new(fmpz_poly_t new_poly, /** * This deletes the internal structure of a polynomial, - * and frees the pointer. Don't call this on stack variables, - * this is intended for use after ntru_ functions, that - * return a polynomial pointer. + * and frees the pointer. * * @param poly the polynomial to delete */ @@ -121,11 +119,26 @@ void poly_delete(fmpz_poly_t poly) fmpz_poly_clear(poly); } +/** + * Delete the internal structure of a polynomial + * array which must be NULL terminated. + * + * @param poly_array the polynomial array + */ +void poly_delete_array(fmpz_poly_t **poly_array) +{ + unsigned int i = 0; + + while(poly_array[i]) { + poly_delete(*(poly_array[i])); + free(*(poly_array[i])); + i++; + } +} + /** * This deletes the internal structure of all polynomials, - * and frees the pointers. Don't call this on stack variables, - * this is intended for use after ntru_ functions, that - * return a polynomial pointer. + * and frees the pointers. * You must call this with NULL as last argument! * * @param poly the polynomial to delete diff --git a/src/poly.h b/src/poly.h index 61667d1..50d3600 100644 --- a/src/poly.h +++ b/src/poly.h @@ -44,6 +44,8 @@ void poly_new(fmpz_poly_t new_poly, void poly_delete(fmpz_poly_t poly); +void poly_delete_array(fmpz_poly_t **poly_array); + void poly_delete_all(fmpz_poly_t poly, ...); void fmpz_poly_mod_unsigned(fmpz_poly_t a,