@@ -416,6 +416,10 @@ monitor_print_nodes_as_json(Monitor *monitor, char *formation, int groupId)
416416 log_error ("Failed to get the nodes from the monitor while running "
417417 "\"%s\" with formation %s and group %d" ,
418418 sql , formation , groupId );
419+ if (context .strVal )
420+ {
421+ free (context .strVal );
422+ }
419423 return false;
420424 }
421425
@@ -429,10 +433,15 @@ monitor_print_nodes_as_json(Monitor *monitor, char *formation, int groupId)
429433 "it returned an unexpected result. "
430434 "See previous line for details." ,
431435 sql , formation , groupId );
436+ if (context .strVal )
437+ {
438+ free (context .strVal );
439+ }
432440 return false;
433441 }
434442
435443 fformat (stdout , "%s\n" , context .strVal );
444+ free (context .strVal );
436445
437446 return true;
438447}
@@ -559,6 +568,10 @@ monitor_print_other_nodes_as_json(Monitor *monitor,
559568 {
560569 log_error ("Failed to get the other nodes from the monitor while running "
561570 "\"%s\" with node id %d" , sql , myNodeId );
571+ if (context .strVal )
572+ {
573+ free (context .strVal );
574+ }
562575 return false;
563576 }
564577
@@ -571,10 +584,15 @@ monitor_print_other_nodes_as_json(Monitor *monitor,
571584 "\"%s\" with node id %d because it returned an "
572585 "unexpected result. See previous line for details." ,
573586 sql , myNodeId );
587+ if (context .strVal )
588+ {
589+ free (context .strVal );
590+ }
574591 return false;
575592 }
576593
577594 fformat (stdout , "%s\n" , context .strVal );
595+ free (context .strVal );
578596
579597 return true;
580598}
@@ -1977,10 +1995,15 @@ monitor_print_state_as_json(Monitor *monitor, char *formation, int group)
19771995 {
19781996 log_error ("Failed to parse current state from the monitor" );
19791997 log_error ("%s" , context .strVal );
1998+ if (context .strVal )
1999+ {
2000+ free (context .strVal );
2001+ }
19802002 return false;
19812003 }
19822004
19832005 fformat (stdout , "%s\n" , context .strVal );
2006+ free (context .strVal );
19842007
19852008 return true;
19862009}
@@ -2142,10 +2165,15 @@ monitor_print_last_events_as_json(Monitor *monitor,
21422165 {
21432166 log_error ("Failed to parse %d last events from the monitor" , count );
21442167 log_error ("%s" , context .strVal );
2168+ if (context .strVal )
2169+ {
2170+ free (context .strVal );
2171+ }
21452172 return false;
21462173 }
21472174
21482175 fformat (stream , "%s\n" , context .strVal );
2176+ free (context .strVal );
21492177
21502178 return true;
21512179}
@@ -2379,17 +2407,26 @@ monitor_formation_uri(Monitor *monitor,
23792407 if (!context .parsedOk )
23802408 {
23812409 /* errors have already been logged */
2410+ if (context .strVal )
2411+ {
2412+ free (context .strVal );
2413+ }
23822414 return false;
23832415 }
23842416
23852417 if (context .strVal == NULL || strcmp (context .strVal , "" ) == 0 )
23862418 {
23872419 log_error ("Formation \"%s\" currently has no nodes in group 0" ,
23882420 formation );
2421+ if (context .strVal )
2422+ {
2423+ free (context .strVal );
2424+ }
23892425 return false;
23902426 }
23912427
23922428 strlcpy (connectionString , context .strVal , size );
2429+ free (context .strVal );
23932430
23942431 /* disconnect from PostgreSQL now */
23952432 pgsql_finish (& monitor -> pgsql );
@@ -2490,13 +2527,18 @@ monitor_print_every_formation_uri_as_json(Monitor *monitor,
24902527 if (!context .parsedOk )
24912528 {
24922529 /* errors have already been logged */
2530+ if (context .strVal )
2531+ {
2532+ free (context .strVal );
2533+ }
24932534 return false;
24942535 }
24952536
24962537 /* disconnect from PostgreSQL now */
24972538 pgsql_finish (& monitor -> pgsql );
24982539
24992540 fformat (stream , "%s\n" , context .strVal );
2541+ free (context .strVal );
25002542
25012543 return true;
25022544}
@@ -2752,10 +2794,15 @@ monitor_print_formation_settings_as_json(Monitor *monitor, char *formation)
27522794 {
27532795 log_error ("Failed to parse formation settings from the monitor "
27542796 "for formation \"%s\"" , formation );
2797+ if (context .strVal )
2798+ {
2799+ free (context .strVal );
2800+ }
27552801 return false;
27562802 }
27572803
27582804 fformat (stdout , "%s\n" , context .strVal );
2805+ free (context .strVal );
27592806
27602807 return true;
27612808}
@@ -2794,6 +2841,10 @@ monitor_synchronous_standby_names(Monitor *monitor,
27942841 log_error ("Failed to get the synchronous_standby_names setting value "
27952842 " from the monitor for formation %s and group %d" ,
27962843 formation , groupId );
2844+ if (context .strVal )
2845+ {
2846+ free (context .strVal );
2847+ }
27972848 return false;
27982849 }
27992850
@@ -2803,10 +2854,15 @@ monitor_synchronous_standby_names(Monitor *monitor,
28032854 " from the monitor for formation %s and group %d,"
28042855 "see above for details" ,
28052856 formation , groupId );
2857+ if (context .strVal )
2858+ {
2859+ free (context .strVal );
2860+ }
28062861 return false;
28072862 }
28082863
28092864 strlcpy (synchronous_standby_names , context .strVal , size );
2865+ free (context .strVal );
28102866
28112867 return true;
28122868}
0 commit comments