Skip to content

Commit 630751e

Browse files
authored
Merge pull request #3209 from eduar-hte/cleanup_api
Add cleanup methods to complete C based ABI
2 parents 8ec69be + 0dce460 commit 630751e

File tree

6 files changed

+40
-1
lines changed

6 files changed

+40
-1
lines changed

examples/simple_example_using_c/test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ int main (int argc, char **argv)
6868
msc_process_response_body(transaction);
6969
msc_process_logging(transaction);
7070
end:
71+
if(error != NULL)
72+
msc_rules_error_cleanup(error);
7173
msc_rules_cleanup(rules);
7274
msc_cleanup(modsec);
7375

headers/modsecurity/rules_set.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ int msc_rules_add_remote(RulesSet *rules, const char *key, const char *uri,
9999
const char **error);
100100
int msc_rules_add_file(RulesSet *rules, const char *file, const char **error);
101101
int msc_rules_add(RulesSet *rules, const char *plain_rules, const char **error);
102+
void msc_rules_error_cleanup(const char *error);
102103
int msc_rules_cleanup(RulesSet *rules);
103104

104105
#ifdef __cplusplus

headers/modsecurity/transaction.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,9 @@ void msc_transaction_cleanup(Transaction *transaction);
723723
/** @ingroup ModSecurity_C_API */
724724
int msc_intervention(Transaction *transaction, ModSecurityIntervention *it);
725725

726+
/** @ingroup ModSecurity_C_API */
727+
void msc_intervention_cleanup(ModSecurityIntervention *it);
728+
726729
/** @ingroup ModSecurity_C_API */
727730
int msc_process_logging(Transaction *transaction);
728731

src/rules_set.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,21 @@ extern "C" int msc_rules_add(RulesSet *rules, const char *plain_rules,
311311
}
312312

313313

314+
/**
315+
* @name msc_rules_error_cleanup
316+
* @brief Deallocates an error message buffer returned by a msc_rules_xxx function.
317+
*
318+
* This is a helper function to free the error message buffer allocated
319+
* by a msc_rules_xxx function.
320+
*
321+
* @param error Error message pointer.
322+
*
323+
*/
324+
extern "C" void msc_rules_error_cleanup(const char *error) {
325+
free((void*) error);
326+
}
327+
328+
314329
extern "C" int msc_rules_cleanup(RulesSet *rules) {
315330
delete rules;
316331
return true;

src/transaction.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,6 +2273,22 @@ extern "C" int msc_intervention(Transaction *transaction,
22732273
}
22742274

22752275

2276+
/**
2277+
* @name msc_intervention_cleanup
2278+
* @brief Removes all the resources allocated by a given Intervention.
2279+
*
2280+
* This is a helper function to free any allocated buffers owned by the
2281+
* intervention.
2282+
*
2283+
* @param it ModSecurity intervention.
2284+
*
2285+
*/
2286+
extern "C" void msc_intervention_cleanup(ModSecurityIntervention *it) {
2287+
intervention::free(it);
2288+
intervention::clean(it);
2289+
}
2290+
2291+
22762292
/**
22772293
* @name msc_get_response_body
22782294
* @brief Retrieve a buffer with the updated response body.

test/benchmark/benchmark.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ int main(int argc, char *argv[]) {
7373
modsecurity::ModSecurity *modsec;
7474
modsecurity::RulesSet *rules;
7575
modsecurity::ModSecurityIntervention it;
76-
modsecurity::intervention::reset(&it);
76+
modsecurity::intervention::clean(&it);
7777
modsec = new modsecurity::ModSecurity();
7878
modsec->setConnectorInformation("ModSecurity-benchmark v0.0.1-alpha" \
7979
" (ModSecurity benchmark utility)");
@@ -167,6 +167,8 @@ int main(int argc, char *argv[]) {
167167
next_request:
168168
modsecTransaction->processLogging();
169169
delete modsecTransaction;
170+
modsecurity::intervention::free(&it);
171+
modsecurity::intervention::clean(&it);
170172
}
171173

172174
delete rules;

0 commit comments

Comments
 (0)