@@ -230,7 +230,7 @@ static void
230230libyang_verbclb (LY_LOG_LEVEL level , const char * msg , const char * data_path , const char * schema_path , uint64_t line )
231231{
232232 const char * levstr ;
233- char * full_msg , * aux ;
233+ char * full_msg = NULL , * aux ;
234234
235235 switch (level ) {
236236 case LY_LLERR :
@@ -247,22 +247,33 @@ libyang_verbclb(LY_LOG_LEVEL level, const char *msg, const char *data_path, cons
247247 break ;
248248 }
249249
250- asprintf (& full_msg , "libyang %s %s" , levstr , msg );
250+ if (asprintf (& full_msg , "libyang %s %s" , levstr , msg ) == -1 ) {
251+ goto error ;
252+ }
251253
252254 if (data_path || schema_path ) {
253- asprintf (& aux , "%s (%s)" , full_msg , data_path ? data_path : schema_path );
255+ if (asprintf (& aux , "%s (%s)" , full_msg , data_path ? data_path : schema_path ) == -1 ) {
256+ goto error ;
257+ }
254258 free (full_msg );
255259 full_msg = aux ;
256260 }
257261
258262 if (line ) {
259- asprintf (& aux , "%s (line %" PRIu64 ")" , full_msg , line );
263+ if (asprintf (& aux , "%s (line %" PRIu64 ")" , full_msg , line ) == -1 ) {
264+ goto error ;
265+ }
260266 free (full_msg );
261267 full_msg = aux ;
262268 }
263269
264270 fprintf (stderr , "%s\n" , full_msg );
265271 free (full_msg );
272+ return ;
273+
274+ error :
275+ free (full_msg );
276+ fprintf (stderr , "libyang %s Memory allocation failed.\n" , levstr );
266277}
267278
268279static struct yl_schema_features *
0 commit comments