Skip to contentSkip to conversation

Optimise nfq_queue_cb

PATCH In review Paul Aitken 2 participants 5 messages Jun 1, 2015 – Jun 4, 2015 1 message not in the archive netfilter

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): md5:KJl5IfCAjtPWb+o93HAjWA==

#1 lore raw

PATCH 1/1 Optimise nfq_queue_cb

ct and myct have both already been checked for non-NULL, so there's no need to check either of them again later.

---
 src/cthelper.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
src/cthelper.c +3 -5
index 15d5126..6537515 100644
@@ -325,14 +325,12 @@ static int nfq_queue_cb(const struct nlmsghdr *nlh, void *data)
 	if (pkt_verdict_issue(helper, myct, queue_num, id, verdict, pktb) < 0)
 		goto err_pktb;
 
-	if (ct != NULL)
-		nfct_destroy(ct);
+	nfct_destroy(ct);
 	if (myct->exp != NULL)
 		nfexp_destroy(myct->exp);
-	if (myct && myct->priv_data != NULL)
+	if (myct->priv_data != NULL)
 		free(myct->priv_data);
-	if (myct != NULL)
-		free(myct);
+	free(myct);
 
 	return MNL_CB_OK;
 err_pktb:
Signature · 1 line
1.9.1
#2 lore raw
Quoted 13 lines · Paul Aitken

ct and myct have both already been checked for non-NULL, so there's no need to check either of them again later.

---
 src/cthelper.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
src/cthelper.c +0 -0
index 15d5126..6537515 100644

src/cthelper.c static int nfq_queue_cb(const struct nlmsghdr *nlh, void *data) · line 327

Quoted 5 lines
src/cthelper.c +1 -2
@@ -325,14 +325,12 @@ static int nfq_queue_cb(const struct nlmsghdr *nlh, void *data)
 	if (pkt_verdict_issue(helper, myct, queue_num, id, verdict, pktb) < 0)
 		goto err_pktb;
-	if (ct != NULL)
-		nfct_destroy(ct);
+	nfct_destroy(ct);

void nfct_destroy(struct nf_conntrack *ct)

{
        assert(ct != NULL);
        ...

the library doesn't allow NULL pointers.

Quoted 13 lines
src/cthelper.c +2 -3
 	if (myct->exp != NULL)
 		nfexp_destroy(myct->exp);
-	if (myct && myct->priv_data != NULL)
+	if (myct->priv_data != NULL)
 		free(myct->priv_data);
-	if (myct != NULL)
-		free(myct);
+	free(myct);
 	return MNL_CB_OK;
 err_pktb:
Signature · 1 line
1.9.1
#3 lore raw

Pablo,

Quoted 20 lines · Paul Aitken
Quoted 13 lines

ct and myct have both already been checked for non-NULL, so there's no need to check either of them again later.

---
  src/cthelper.c | 8 +++-----
  1 file changed, 3 insertions(+), 5 deletions(-)
src/cthelper.c +0 -0
index 15d5126..6537515 100644

src/cthelper.c static int nfq_queue_cb(const struct nlmsghdr *nlh, void *data) · line 327

Quoted 5 lines
src/cthelper.c +1 -2
@@ -325,14 +325,12 @@ static int nfq_queue_cb(const struct nlmsghdr *nlh, void *data)
  	if (pkt_verdict_issue(helper, myct, queue_num, id, verdict, pktb) < 0)
  		goto err_pktb;
-	if (ct != NULL)
-		nfct_destroy(ct);
+	nfct_destroy(ct);

void nfct_destroy(struct nf_conntrack *ct)

Quoted 5 lines
{
         assert(ct != NULL);
         ...

the library doesn't allow NULL pointers.

ct was already checked for non-NULL when it was assigned around line 297:

        ct = nfct_new();
        if (ct == NULL)
                goto err;

- so ct cannot be NULL at line 325.

P.

Quoted 13 lines
Quoted 13 lines
src/cthelper.c +2 -3
  	if (myct->exp != NULL)
  		nfexp_destroy(myct->exp);
-	if (myct && myct->priv_data != NULL)
+	if (myct->priv_data != NULL)
  		free(myct->priv_data);
-	if (myct != NULL)
-		free(myct);
+	free(myct);
  	return MNL_CB_OK;
  err_pktb:
Signature · 1 line
1.9.1
#4 lore raw
Quoted 28 lines · Paul Aitken

Pablo,

Quoted 20 lines · Paul Aitken
Quoted 13 lines

ct and myct have both already been checked for non-NULL, so there's no need to check either of them again later.

---
 src/cthelper.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
src/cthelper.c +0 -0
index 15d5126..6537515 100644

src/cthelper.c static int nfq_queue_cb(const struct nlmsghdr *nlh, void *data) · line 327

Quoted 5 lines
src/cthelper.c +1 -2
@@ -325,14 +325,12 @@ static int nfq_queue_cb(const struct nlmsghdr *nlh, void *data)
 	if (pkt_verdict_issue(helper, myct, queue_num, id, verdict, pktb) < 0)
 		goto err_pktb;
-	if (ct != NULL)
-		nfct_destroy(ct);
+	nfct_destroy(ct);

void nfct_destroy(struct nf_conntrack *ct)

Quoted 5 lines
{
        assert(ct != NULL);
        ...

the library doesn't allow NULL pointers.

Quoted 7 lines

ct was already checked for non-NULL when it was assigned around line 297:

        ct = nfct_new();
        if (ct == NULL)
                goto err;

- so ct cannot be NULL at line 325.

Right, makes sense. However, your patch doesn't apply here for some reason:

$ git am Optimise-nfq_queue_cb.patch
Applying: Optimise nfq_queue_cb
error: patch failed: src/cthelper.c:325
error: src/cthelper.c: patch does not apply
Patch failed at 0001 Optimise nfq_queue_cb
When you have resolved this problem run "git am --resolved".
If you would prefer to skip this patch, instead run "git am --skip".
To restore the original branch and stop patching run "git am --abort"
#5 lore raw

Pablo, somehow tabs had been converted to spaces.

Let me try again...

P.

Quoted 46 lines · Pablo Neira Ayuso
Quoted 26 lines · Paul Aitken

Pablo,

Quoted 24 lines · Paul Aitken
Quoted 13 lines

ct and myct have both already been checked for non-NULL, so there's no need to check either of them again later.

---
  src/cthelper.c | 8 +++-----
  1 file changed, 3 insertions(+), 5 deletions(-)
src/cthelper.c +0 -0
index 15d5126..6537515 100644

src/cthelper.c static int nfq_queue_cb(const struct nlmsghdr *nlh, void *data) · line 327

Quoted 5 lines
src/cthelper.c +1 -2
@@ -325,14 +325,12 @@ static int nfq_queue_cb(const struct nlmsghdr *nlh, void *data)
  	if (pkt_verdict_issue(helper, myct, queue_num, id, verdict, pktb) < 0)
  		goto err_pktb;
-	if (ct != NULL)
-		nfct_destroy(ct);
+	nfct_destroy(ct);

void nfct_destroy(struct nf_conntrack *ct)

{
         assert(ct != NULL);
         ...
Quoted 8 lines
Quoted 1 line

the library doesn't allow NULL pointers.

ct was already checked for non-NULL when it was assigned around line 297:

         ct = nfct_new();
         if (ct == NULL)
                 goto err;

- so ct cannot be NULL at line 325.

Right, makes sense. However, your patch doesn't apply here for some reason:

$ git am Optimise-nfq_queue_cb.patch
Applying: Optimise nfq_queue_cb
error: patch failed: src/cthelper.c:325
error: src/cthelper.c: patch does not apply
Patch failed at 0001 Optimise nfq_queue_cb
When you have resolved this problem run "git am --resolved".
If you would prefer to skip this patch, instead run "git am --skip".
To restore the original branch and stop patching run "git am --abort"