Skip to contentSkip to conversation

pipeline: fix deallocate null pointer

PATCH NAK Min Hu (Connor) 2 participants 3 messages Apr 22, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pipeline: fix deallocate null pointer

From: HongBo Zheng <[email protected]>

Fix deallocate null pointer in instruction_config, while pointer 'data' or 'instr' may be null.

Fixes a1711f948dbf ("pipeline: add SWX Rx and extract instructions")
---
 lib/librte_pipeline/rte_swx_pipeline.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
lib/librte_pipeline/rte_swx_pipeline.c +4 -2
index 4455d91..6084635 100644
@@ -8015,8 +8015,10 @@ instruction_config(struct rte_swx_pipeline *p,
 	return 0;
 
 error:
-	free(data);
-	free(instr);
+	if (data)
+		free(data);
+	if (instr)
+		free(instr);
 	return err;
 }
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 43 lines

-----Original Message-----
From: Min Hu (Connor) <[email protected]>
Sent: Thursday, April 22, 2021 7:39 AM
To: [email protected]
Cc: Yigit, Ferruh <[email protected]>; Dumitrescu, Cristian <[email protected]>
Subject: [PATCH] pipeline: fix deallocate null pointer

From: HongBo Zheng <[email protected]>

Fix deallocate null pointer in instruction_config, while pointer 'data' or 'instr' may be null.

Fixes a1711f948dbf ("pipeline: add SWX Rx and extract instructions")
---
 lib/librte_pipeline/rte_swx_pipeline.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
lib/librte_pipeline/rte_swx_pipeline.c +4 -3
index 4455d91..6084635 100644
@@ -8015,8 +8015,10 @@ instruction_config(struct rte_swx_pipeline *p,
 	return 0;
 
 error:
-	free(data);
-	free(instr);
+	if (data)
+		free(data);
+	if (instr)
+		free(instr);
 	return err;
 }
 
--
Quoted 1 line

2.7.4

Hi,

NACK.

Thanks for the patch, but the tests for data and instr being non-NULL before calling free are not required, because:
1. Both data and instr are initialized to NULL.
2. free(NULL) is supported.

Regards,
Cristian

#2 lore raw
Quoted 47 lines · Cristian
Quoted 43 lines

-----Original Message-----
From: Min Hu (Connor) <[email protected]>
Sent: Thursday, April 22, 2021 7:39 AM
To: [email protected]
Cc: Yigit, Ferruh <[email protected]>; Dumitrescu, Cristian <[email protected]>
Subject: [PATCH] pipeline: fix deallocate null pointer

From: HongBo Zheng <[email protected]>

Fix deallocate null pointer in instruction_config, while pointer 'data' or 'instr' may be null.

Fixes a1711f948dbf ("pipeline: add SWX Rx and extract instructions")
---
  lib/librte_pipeline/rte_swx_pipeline.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
lib/librte_pipeline/rte_swx_pipeline.c +4 -3
index 4455d91..6084635 100644
@@ -8015,8 +8015,10 @@ instruction_config(struct rte_swx_pipeline *p,
  	return 0;
 
  error:
-	free(data);
-	free(instr);
+	if (data)
+		free(data);
+	if (instr)
+		free(instr);
  	return err;
  }
 
--
Quoted 1 line

2.7.4

Hi,

Quoted 6 lines

NACK.

Thanks for the patch, but the tests for data and instr being non-NULL before calling free are not required, because:
1. Both data and instr are initialized to NULL.
2. free(NULL) is supported.

Agreed, thanks Cristian, this patch can be abandoned.

Quoted 4 lines

Regards,
Cristian
.