2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-25 15:07:05 +00:00

ofp-print: Fix memory leak at ofp_print_bundle_add().

Call ds_put_and_free_cstr instead of ds_put_cstr to free msg.
Reported by test cases: 325, 326
    ofp_print_bundle_add (ofp-print.c:3027)
    ofp_to_string__ (ofp-print.c:3410)
    ofp_to_string (ofp-print.c:3465)
    ofp_print (ofp-print.c:3497)
    ofctl_ofp_print (ovs-ofctl.c:3818)
    ovs_cmdl_run_command (command-line.c:121)
    main (ovs-ofctl.c:135)

Signed-off-by: William Tu <u9012063@gmail.com>
Signed-off-by: Daniele Di Proietto <diproiettod@vmware.com>
Co-authored-by: Daniele Di Proietto <diproiettod@vmware.com>
[blp@ovn.org simplified the code slightly]
Signed-off-by: Ben Pfaff <blp@ovn.org>

Signed-off-by: Ben Pfaff <blp@ovn.org>
This commit is contained in:
William Tu
2015-12-24 10:28:40 -08:00
committed by Ben Pfaff
parent 39cc5c4ade
commit cf8fbeaa1c

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc. * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -3010,7 +3010,6 @@ ofp_print_bundle_add(struct ds *s, const struct ofp_header *oh, int verbosity)
{ {
int error; int error;
struct ofputil_bundle_add_msg badd; struct ofputil_bundle_add_msg badd;
char *msg;
error = ofputil_decode_bundle_add(oh, &badd, NULL); error = ofputil_decode_bundle_add(oh, &badd, NULL);
if (error) { if (error) {
@@ -3024,10 +3023,8 @@ ofp_print_bundle_add(struct ds *s, const struct ofp_header *oh, int verbosity)
ofp_print_bit_names(s, badd.flags, bundle_flags_to_name, ' '); ofp_print_bit_names(s, badd.flags, bundle_flags_to_name, ' ');
ds_put_char(s, '\n'); ds_put_char(s, '\n');
msg = ofp_to_string(badd.msg, ntohs(badd.msg->length), verbosity); char *msg = ofp_to_string(badd.msg, ntohs(badd.msg->length), verbosity);
if (msg) { ds_put_and_free_cstr(s, msg);
ds_put_cstr(s, msg);
}
} }
static void static void