[ovs-dev] ovn-trace: Fix small error condition memory leak in trace().
diff mbox

Message ID 1482357872-111103-1-git-send-email-jpettit@ovn.org
State Accepted
Headers show

Commit Message

Justin Pettit Dec. 21, 2016, 10:04 p.m. UTC
Signed-off-by: Justin Pettit <jpettit@ovn.org>
---
 ovn/utilities/ovn-trace.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Ben Pfaff Dec. 21, 2016, 10:12 p.m. UTC | #1
On Wed, Dec 21, 2016 at 02:04:32PM -0800, Justin Pettit wrote:
> Signed-off-by: Justin Pettit <jpettit@ovn.org>
> ---
>  ovn/utilities/ovn-trace.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/ovn/utilities/ovn-trace.c b/ovn/utilities/ovn-trace.c
> index 71798f8..6d8e514 100644
> --- a/ovn/utilities/ovn-trace.c
> +++ b/ovn/utilities/ovn-trace.c
> @@ -1447,7 +1447,9 @@ trace(const char *dp_s, const char *flow_s)
>      char *error = expr_parse_microflow(flow_s, &symtab, &address_sets,
>                                         ovntrace_lookup_port, dp, &uflow);
>      if (error) {
> -        return xasprintf("error parsing flow: %s\n", error);
> +        char *s = xasprintf("error parsing flow: %s\n", error);
> +        free(error);
> +        return s;
>      }

I've often wished for a %s-like format specifier that frees the string
after it prints it.

Acked-by: Ben Pfaff <blp@ovn.org>
Justin Pettit Dec. 22, 2016, 1:13 a.m. UTC | #2
> On Dec 21, 2016, at 2:12 PM, Ben Pfaff <blp@ovn.org> wrote:
> 
> On Wed, Dec 21, 2016 at 02:04:32PM -0800, Justin Pettit wrote:
>> Signed-off-by: Justin Pettit <jpettit@ovn.org>
>> ---
>> ovn/utilities/ovn-trace.c | 4 +++-
>> 1 file changed, 3 insertions(+), 1 deletion(-)
>> 
>> diff --git a/ovn/utilities/ovn-trace.c b/ovn/utilities/ovn-trace.c
>> index 71798f8..6d8e514 100644
>> --- a/ovn/utilities/ovn-trace.c
>> +++ b/ovn/utilities/ovn-trace.c
>> @@ -1447,7 +1447,9 @@ trace(const char *dp_s, const char *flow_s)
>>     char *error = expr_parse_microflow(flow_s, &symtab, &address_sets,
>>                                        ovntrace_lookup_port, dp, &uflow);
>>     if (error) {
>> -        return xasprintf("error parsing flow: %s\n", error);
>> +        char *s = xasprintf("error parsing flow: %s\n", error);
>> +        free(error);
>> +        return s;
>>     }
> 
> I've often wished for a %s-like format specifier that frees the string
> after it prints it.
> 
> Acked-by: Ben Pfaff <blp@ovn.org>

Thanks.  I pushed this to master and branch-2.6.

--Justin

Patch
diff mbox

diff --git a/ovn/utilities/ovn-trace.c b/ovn/utilities/ovn-trace.c
index 71798f8..6d8e514 100644
--- a/ovn/utilities/ovn-trace.c
+++ b/ovn/utilities/ovn-trace.c
@@ -1447,7 +1447,9 @@  trace(const char *dp_s, const char *flow_s)
     char *error = expr_parse_microflow(flow_s, &symtab, &address_sets,
                                        ovntrace_lookup_port, dp, &uflow);
     if (error) {
-        return xasprintf("error parsing flow: %s\n", error);
+        char *s = xasprintf("error parsing flow: %s\n", error);
+        free(error);
+        return s;
     }
 
     uint32_t in_key = uflow.regs[MFF_LOG_INPORT - MFF_REG0];