@@ -113,6 +113,20 @@ strlist_copy(InfoMessage__StringList *strlist)
113113 debug_return_ptr (NULL );
114114}
115115
116+ /*
117+ * Free a NULL-terminated string vector.
118+ */
119+ static void
120+ strvec_free (char * vec [])
121+ {
122+ if (vec != NULL ) {
123+ char * * vp ;
124+ for (vp = vec ; * vp != NULL ; vp ++ )
125+ free (* vp );
126+ free (vec );
127+ }
128+ }
129+
116130/*
117131 * Fill in eventlog details from an AcceptMessage
118132 * Caller is responsible for freeing strings in struct eventlog.
@@ -180,6 +194,7 @@ evlog_new(TimeSpec *submit_time, InfoMessage **info_msgs, size_t infolen,
180194 }
181195 if (strcmp (key , "command" ) == 0 ) {
182196 if (type_matches (info , source , INFO_MESSAGE__VALUE_STRVAL )) {
197+ free (evlog -> command );
183198 if ((evlog -> command = strdup (info -> u .strval )) == NULL ) {
184199 sudo_warnx (U_ ("%s: %s" ), __func__ ,
185200 U_ ("unable to allocate memory" ));
@@ -205,6 +220,7 @@ evlog_new(TimeSpec *submit_time, InfoMessage **info_msgs, size_t infolen,
205220 case 'r' :
206221 if (strcmp (key , "runargv" ) == 0 ) {
207222 if (type_matches (info , source , INFO_MESSAGE__VALUE_STRLISTVAL )) {
223+ strvec_free (evlog -> runargv );
208224 evlog -> runargv = strlist_copy (info -> u .strlistval );
209225 if (evlog -> runargv == NULL )
210226 goto bad ;
@@ -213,6 +229,7 @@ evlog_new(TimeSpec *submit_time, InfoMessage **info_msgs, size_t infolen,
213229 }
214230 if (strcmp (key , "runchroot" ) == 0 ) {
215231 if (type_matches (info , source , INFO_MESSAGE__VALUE_STRVAL )) {
232+ free (evlog -> runchroot );
216233 if ((evlog -> runchroot = strdup (info -> u .strval )) == NULL ) {
217234 sudo_warnx (U_ ("%s: %s" ), __func__ ,
218235 U_ ("unable to allocate memory" ));
@@ -223,6 +240,7 @@ evlog_new(TimeSpec *submit_time, InfoMessage **info_msgs, size_t infolen,
223240 }
224241 if (strcmp (key , "runcwd" ) == 0 ) {
225242 if (type_matches (info , source , INFO_MESSAGE__VALUE_STRVAL )) {
243+ free (evlog -> runcwd );
226244 if ((evlog -> runcwd = strdup (info -> u .strval )) == NULL ) {
227245 sudo_warnx (U_ ("%s: %s" ), __func__ ,
228246 U_ ("unable to allocate memory" ));
@@ -233,6 +251,7 @@ evlog_new(TimeSpec *submit_time, InfoMessage **info_msgs, size_t infolen,
233251 }
234252 if (strcmp (key , "runenv" ) == 0 ) {
235253 if (type_matches (info , source , INFO_MESSAGE__VALUE_STRLISTVAL )) {
254+ strvec_free (evlog -> runenv );
236255 evlog -> runenv = strlist_copy (info -> u .strlistval );
237256 if (evlog -> runenv == NULL )
238257 goto bad ;
@@ -252,6 +271,7 @@ evlog_new(TimeSpec *submit_time, InfoMessage **info_msgs, size_t infolen,
252271 }
253272 if (strcmp (key , "rungroup" ) == 0 ) {
254273 if (type_matches (info , source , INFO_MESSAGE__VALUE_STRVAL )) {
274+ free (evlog -> rungroup );
255275 if ((evlog -> rungroup = strdup (info -> u .strval )) == NULL ) {
256276 sudo_warnx (U_ ("%s: %s" ), __func__ ,
257277 U_ ("unable to allocate memory" ));
@@ -273,6 +293,7 @@ evlog_new(TimeSpec *submit_time, InfoMessage **info_msgs, size_t infolen,
273293 }
274294 if (strcmp (key , "runuser" ) == 0 ) {
275295 if (type_matches (info , source , INFO_MESSAGE__VALUE_STRVAL )) {
296+ free (evlog -> runuser );
276297 if ((evlog -> runuser = strdup (info -> u .strval )) == NULL ) {
277298 sudo_warnx (U_ ("%s: %s" ), __func__ ,
278299 U_ ("unable to allocate memory" ));
@@ -285,6 +306,7 @@ evlog_new(TimeSpec *submit_time, InfoMessage **info_msgs, size_t infolen,
285306 case 's' :
286307 if (strcmp (key , "source" ) == 0 ) {
287308 if (type_matches (info , source , INFO_MESSAGE__VALUE_STRVAL )) {
309+ free (evlog -> source );
288310 if ((evlog -> source = strdup (info -> u .strval )) == NULL ) {
289311 sudo_warnx (U_ ("%s: %s" ), __func__ ,
290312 U_ ("unable to allocate memory" ));
@@ -295,6 +317,7 @@ evlog_new(TimeSpec *submit_time, InfoMessage **info_msgs, size_t infolen,
295317 }
296318 if (strcmp (key , "submitcwd" ) == 0 ) {
297319 if (type_matches (info , source , INFO_MESSAGE__VALUE_STRVAL )) {
320+ free (evlog -> cwd );
298321 if ((evlog -> cwd = strdup (info -> u .strval )) == NULL ) {
299322 sudo_warnx (U_ ("%s: %s" ), __func__ ,
300323 U_ ("unable to allocate memory" ));
@@ -305,6 +328,7 @@ evlog_new(TimeSpec *submit_time, InfoMessage **info_msgs, size_t infolen,
305328 }
306329 if (strcmp (key , "submitenv" ) == 0 ) {
307330 if (type_matches (info , source , INFO_MESSAGE__VALUE_STRLISTVAL )) {
331+ strvec_free (evlog -> submitenv );
308332 evlog -> submitenv = strlist_copy (info -> u .strlistval );
309333 if (evlog -> submitenv == NULL )
310334 goto bad ;
@@ -313,6 +337,7 @@ evlog_new(TimeSpec *submit_time, InfoMessage **info_msgs, size_t infolen,
313337 }
314338 if (strcmp (key , "submitgroup" ) == 0 ) {
315339 if (type_matches (info , source , INFO_MESSAGE__VALUE_STRVAL )) {
340+ free (evlog -> submitgroup );
316341 if ((evlog -> submitgroup = strdup (info -> u .strval )) == NULL ) {
317342 sudo_warnx (U_ ("%s: %s" ), __func__ ,
318343 U_ ("unable to allocate memory" ));
@@ -323,6 +348,7 @@ evlog_new(TimeSpec *submit_time, InfoMessage **info_msgs, size_t infolen,
323348 }
324349 if (strcmp (key , "submithost" ) == 0 ) {
325350 if (type_matches (info , source , INFO_MESSAGE__VALUE_STRVAL )) {
351+ free (evlog -> submithost );
326352 if ((evlog -> submithost = strdup (info -> u .strval )) == NULL ) {
327353 sudo_warnx (U_ ("%s: %s" ), __func__ ,
328354 U_ ("unable to allocate memory" ));
@@ -333,6 +359,7 @@ evlog_new(TimeSpec *submit_time, InfoMessage **info_msgs, size_t infolen,
333359 }
334360 if (strcmp (key , "submituser" ) == 0 ) {
335361 if (type_matches (info , source , INFO_MESSAGE__VALUE_STRVAL )) {
362+ free (evlog -> submituser );
336363 if ((evlog -> submituser = strdup (info -> u .strval )) == NULL ) {
337364 sudo_warnx (U_ ("%s: %s" ), __func__ ,
338365 U_ ("unable to allocate memory" ));
@@ -345,6 +372,7 @@ evlog_new(TimeSpec *submit_time, InfoMessage **info_msgs, size_t infolen,
345372 case 't' :
346373 if (strcmp (key , "ttyname" ) == 0 ) {
347374 if (type_matches (info , source , INFO_MESSAGE__VALUE_STRVAL )) {
375+ free (evlog -> ttyname );
348376 if ((evlog -> ttyname = strdup (info -> u .strval )) == NULL ) {
349377 sudo_warnx (U_ ("%s: %s" ), __func__ ,
350378 U_ ("unable to allocate memory" ));
0 commit comments