If a transaction is rejected by the kernel (for instance due to a
semantic error), cache contents are potentially invalid. Release the
cache in that case to avoid the inconsistency.

The problem is easy to reproduce in an interactive session:

| nft> list ruleset
| table ip t {
|       chain c {
|       }
| }
| nft> flush ruleset; add rule ip t c accept
| Error: No such file or directory
| flush ruleset; add rule ip t c accept
|                            ^
| nft> list ruleset
| nft>

Signed-off-by: Phil Sutter <[email protected]>
---
 src/libnftables.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/libnftables.c b/src/libnftables.c
index d8de89ca509cd..e928ce476a90f 100644
--- a/src/libnftables.c
+++ b/src/libnftables.c
@@ -423,6 +423,8 @@ err:
            nft_output_json(&nft->output) &&
            nft_output_echo(&nft->output))
                json_print_echo(nft);
+       if (rc)
+               cache_release(&nft->cache);
        return rc;
 }
 
@@ -466,6 +468,8 @@ err:
            nft_output_json(&nft->output) &&
            nft_output_echo(&nft->output))
                json_print_echo(nft);
+       if (rc)
+               cache_release(&nft->cache);
        return rc;
 }
 
-- 
2.21.0

Reply via email to