Added methods to free buffers allocated by ModSecurity APIs

- The following methods are introduced to allow clients of
  libModSecurity that are not able to link and call the C/C++ standard
  library to be able to free the buffers allocated by libModSecurity.
- msc_intervention_cleanup: Frees the buffers in a
  ModSecurityIntervention structure that have been allocated by calls to
  msc_intervention.
- msc_rules_error_cleanup: Frees an error message buffer allocated by
  the msc_rules_xxx functions to detail the condition that triggered
  the error.
This commit is contained in:
Eduardo Arias
2024-05-03 14:33:02 -03:00
parent f04dcc0262
commit dab9bb6a11
5 changed files with 37 additions and 0 deletions

View File

@@ -311,6 +311,21 @@ extern "C" int msc_rules_add(RulesSet *rules, const char *plain_rules,
}
/**
* @name msc_rules_error_cleanup
* @brief Deallocates an error message buffer returned by a msc_rules_xxx function.
*
* This is a helper function to free the error message buffer allocated
* by a msc_rules_xxx function.
*
* @param error Error message pointer.
*
*/
extern "C" void msc_rules_error_cleanup(const char *error) {
free((void*) error);
}
extern "C" int msc_rules_cleanup(RulesSet *rules) {
delete rules;
return true;

View File

@@ -2273,6 +2273,22 @@ extern "C" int msc_intervention(Transaction *transaction,
}
/**
* @name msc_intervention_cleanup
* @brief Removes all the resources allocated by a given Intervention.
*
* This is a helper function to free any allocated buffers owned by the
* intervention.
*
* @param it ModSecurity intervention.
*
*/
extern "C" void msc_intervention_cleanup(ModSecurityIntervention *it) {
intervention::free(it);
intervention::clean(it);
}
/**
* @name msc_get_response_body
* @brief Retrieve a buffer with the updated response body.