diff mbox series

[ovs-dev,4/7] ovsdb-server: Fix potential memory leak in parse_options().

Message ID 7e7ba27a887674df28bbc23b753b58b300981756.1749133911.git.echaudro@redhat.com
State Accepted
Commit b90304bfe75d22d380f81de8081a3813de136b7e
Delegated to: aaron conole
Headers show
Series Various Coverity fixes. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test fail github build: failed

Commit Message

Eelco Chaudron June 5, 2025, 2:51 p.m. UTC
When duplicate --config-file command-line arguments are passed,
the resources for previously specified file path were not freed.

This fix ensures unused resources are properly freed while
preserving the existing behavior of using the last configuration
file path specified.

Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
---
 ovsdb/ovsdb-server.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Aaron Conole June 5, 2025, 4:42 p.m. UTC | #1
Eelco Chaudron via dev <ovs-dev@openvswitch.org> writes:

> When duplicate --config-file command-line arguments are passed,
> the resources for previously specified file path were not freed.
>
> This fix ensures unused resources are properly freed while
> preserving the existing behavior of using the last configuration
> file path specified.
>
> Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
> ---

I got a bit of confusion with config_file_path variable itself, but
noticed it was static so should be always either initialized or NULL.

Acked-by: Aaron Conole <aconole@redhat.com>
Roi Dayan June 9, 2025, 12:12 p.m. UTC | #2
On 05/06/2025 17:51, Eelco Chaudron via dev wrote:
> When duplicate --config-file command-line arguments are passed,
> the resources for previously specified file path were not freed.
> 
> This fix ensures unused resources are properly freed while
> preserving the existing behavior of using the last configuration
> file path specified.
> 
> Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
> ---
>  ovsdb/ovsdb-server.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c
> index a247ae8f0..d322cdc3d 100644
> --- a/ovsdb/ovsdb-server.c
> +++ b/ovsdb/ovsdb-server.c
> @@ -2747,6 +2747,7 @@ parse_options(int argc, char *argv[],
>              break;
>  
>          case OPT_CONFIG_FILE:
> +            free(config_file_path);
>              config_file_path = abs_file_name(ovs_dbdir(), optarg);
>              add_default_db = false;
>              break;


thanks

Acked-by: Roi Dayan <roid@nvidia.com>
Eelco Chaudron June 10, 2025, 8:26 p.m. UTC | #3
On 9 Jun 2025, at 14:12, Roi Dayan wrote:

> On 05/06/2025 17:51, Eelco Chaudron via dev wrote:
>> When duplicate --config-file command-line arguments are passed,
>> the resources for previously specified file path were not freed.
>>
>> This fix ensures unused resources are properly freed while
>> preserving the existing behavior of using the last configuration
>> file path specified.
>>
>> Signed-off-by: Eelco Chaudron <echaudro@redhat.com>

> thanks
>
> Acked-by: Roi Dayan <roid@nvidia.com>

Thanks for the review Aaron and Roi! Applied to main.

//Eelco
diff mbox series

Patch

diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c
index a247ae8f0..d322cdc3d 100644
--- a/ovsdb/ovsdb-server.c
+++ b/ovsdb/ovsdb-server.c
@@ -2747,6 +2747,7 @@  parse_options(int argc, char *argv[],
             break;
 
         case OPT_CONFIG_FILE:
+            free(config_file_path);
             config_file_path = abs_file_name(ovs_dbdir(), optarg);
             add_default_db = false;
             break;