diff mbox series

[ovs-dev,1/4] ofproto-dpif-xlate: Fix bad memory free.

Message ID 1509384475-27951-2-git-send-email-u9012063@gmail.com
State Changes Requested
Headers show
Series Fix clang static checker errors. | expand

Commit Message

William Tu Oct. 30, 2017, 5:27 p.m. UTC
Clang reports possibly bad free of 'ofm' when it comes from the stack
instead of malloc because Clang is not able to verify whether the previous
if condition 'ctx->xin->xcache' still hold the same.  Fix it by
adding additional condition.

Signed-off-by: William Tu <u9012063@gmail.com>
---
 ofproto/ofproto-dpif-xlate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Ben Pfaff Oct. 30, 2017, 7:39 p.m. UTC | #1
On Mon, Oct 30, 2017 at 10:27:52AM -0700, William Tu wrote:
> Clang reports possibly bad free of 'ofm' when it comes from the stack
> instead of malloc because Clang is not able to verify whether the previous
> if condition 'ctx->xin->xcache' still hold the same.  Fix it by
> adding additional condition.
> 
> Signed-off-by: William Tu <u9012063@gmail.com>
> ---
>  ofproto/ofproto-dpif-xlate.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c
> index ddcaf059ded2..b8a4986061a9 100644
> --- a/ofproto/ofproto-dpif-xlate.c
> +++ b/ofproto/ofproto-dpif-xlate.c
> @@ -5128,7 +5128,7 @@ xlate_learn_action(struct xlate_ctx *ctx, const struct ofpact_learn *learn)
>              }
>          }
>  
> -        if (ctx->xin->xcache) {
> +        if (ctx->xin->xcache && ofm != &ofm__) {
>              free(ofm);
>          }

Hmm, this is interesting.  Can we just change this to:
        if (ofm != &ofm__)
though?  (free(NULL) is harmless.)

Thanks,

Ben.
diff mbox series

Patch

diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c
index ddcaf059ded2..b8a4986061a9 100644
--- a/ofproto/ofproto-dpif-xlate.c
+++ b/ofproto/ofproto-dpif-xlate.c
@@ -5128,7 +5128,7 @@  xlate_learn_action(struct xlate_ctx *ctx, const struct ofpact_learn *learn)
             }
         }
 
-        if (ctx->xin->xcache) {
+        if (ctx->xin->xcache && ofm != &ofm__) {
             free(ofm);
         }