@@ -132,8 +132,9 @@ static void obj_add_result(struct json_object *o, const char *v, ...)
132
132
{
133
133
va_list ap ;
134
134
135
+ _cleanup_free_ char * value = NULL ;
136
+
135
137
va_start (ap , v );
136
- char * value ;
137
138
138
139
if (vasprintf (& value , v , ap ) < 0 )
139
140
value = NULL ;
@@ -144,15 +145,15 @@ static void obj_add_result(struct json_object *o, const char *v, ...)
144
145
obj_add_str (o , "Result" , "Could not allocate string" );
145
146
146
147
va_end (ap );
147
- free (value );
148
148
}
149
149
150
150
static void obj_add_key (struct json_object * o , const char * k , const char * v , ...)
151
151
{
152
152
va_list ap ;
153
153
154
+ _cleanup_free_ char * value = NULL ;
155
+
154
156
va_start (ap , v );
155
- char * value ;
156
157
157
158
if (vasprintf (& value , v , ap ) < 0 )
158
159
value = NULL ;
@@ -163,7 +164,6 @@ static void obj_add_key(struct json_object *o, const char *k, const char *v, ...
163
164
obj_add_str (o , k , "Could not allocate string" );
164
165
165
166
va_end (ap );
166
- free (value );
167
167
}
168
168
169
169
static struct json_object * obj_create_array_obj (struct json_object * o , const char * k )
@@ -2085,10 +2085,11 @@ static void json_phy_rx_eom_descs(struct nvme_phy_rx_eom_log *log,
2085
2085
2086
2086
static void json_phy_rx_eom_log (struct nvme_phy_rx_eom_log * log , __u16 controller )
2087
2087
{
2088
- char * * allocated_eyes = NULL ;
2089
2088
int i ;
2090
2089
struct json_object * r = json_create_object ();
2091
2090
2091
+ _cleanup_free_ char * * allocated_eyes = NULL ;
2092
+
2092
2093
obj_add_uint (r , "lid" , log -> lid );
2093
2094
obj_add_uint (r , "eomip" , log -> eomip );
2094
2095
obj_add_uint (r , "hsize" , le16_to_cpu (log -> hsize ));
@@ -2121,7 +2122,6 @@ static void json_phy_rx_eom_log(struct nvme_phy_rx_eom_log *log, __u16 controlle
2121
2122
if (allocated_eyes [i ])
2122
2123
free (allocated_eyes [i ]);
2123
2124
}
2124
- free (allocated_eyes );
2125
2125
}
2126
2126
2127
2127
json_print (r );
@@ -4613,18 +4613,17 @@ static void json_output_error_status(int status, const char *msg, va_list ap)
4613
4613
{
4614
4614
struct json_object * r ;
4615
4615
char json_str [STR_LEN ];
4616
- char * value ;
4617
4616
int val ;
4618
4617
int type ;
4619
4618
4619
+ _cleanup_free_ char * value = NULL ;
4620
+
4620
4621
if (vasprintf (& value , msg , ap ) < 0 )
4621
4622
value = NULL ;
4622
4623
4623
4624
sprintf (json_str , "Error: %s" , value ? value : "Could not allocate string" );
4624
4625
r = obj_create (json_str );
4625
4626
4626
- free (value );
4627
-
4628
4627
if (status < 0 ) {
4629
4628
obj_add_str (r , "error" , nvme_strerror (errno ));
4630
4629
obj_print (r );
@@ -4656,22 +4655,22 @@ static void json_output_error_status(int status, const char *msg, va_list ap)
4656
4655
static void json_output_message (bool error , const char * msg , va_list ap )
4657
4656
{
4658
4657
struct json_object * r = json_r ? json_r : json_create_object ();
4659
- char * value ;
4658
+
4659
+ _cleanup_free_ char * value = NULL ;
4660
4660
4661
4661
if (vasprintf (& value , msg , ap ) < 0 )
4662
4662
value = NULL ;
4663
4663
4664
4664
obj_add_str (r , error ? "error" : "result" , value ? value : "Could not allocate string" );
4665
4665
4666
- free (value );
4667
-
4668
4666
obj_print (r );
4669
4667
}
4670
4668
4671
4669
static void json_output_perror (const char * msg )
4672
4670
{
4673
4671
struct json_object * r = json_create_object ();
4674
- char * error ;
4672
+
4673
+ _cleanup_free_ char * error = NULL ;
4675
4674
4676
4675
if (asprintf (& error , "%s: %s" , msg , strerror (errno )) < 0 )
4677
4676
error = NULL ;
@@ -4682,8 +4681,6 @@ static void json_output_perror(const char *msg)
4682
4681
obj_add_str (r , "error" , "Could not allocate string" );
4683
4682
4684
4683
json_output_object (r );
4685
-
4686
- free (error );
4687
4684
}
4688
4685
4689
4686
void json_show_init (void )
0 commit comments