@@ -404,22 +404,21 @@ static int parse_name(
404404static int parse_variable (git_config_parser * reader , char * * var_name , char * * var_value )
405405{
406406 const char * value_start = NULL ;
407- char * line ;
408- int quote_count ;
407+ char * line = NULL , * name = NULL , * value = NULL ;
408+ int quote_count , error ;
409409 bool multiline ;
410410
411+ * var_name = NULL ;
412+ * var_value = NULL ;
413+
411414 git_parse_advance_ws (& reader -> ctx );
412415 line = git__strndup (reader -> ctx .line , reader -> ctx .line_len );
413- if (line == NULL )
414- return -1 ;
416+ GITERR_CHECK_ALLOC (line );
415417
416418 quote_count = strip_comments (line , 0 );
417419
418- /* If there is no value, boolean true is assumed */
419- * var_value = NULL ;
420-
421- if (parse_name (var_name , & value_start , reader , line ) < 0 )
422- goto on_error ;
420+ if ((error = parse_name (& name , & value_start , reader , line )) < 0 )
421+ goto out ;
423422
424423 /*
425424 * Now, let's try to parse the value
@@ -428,30 +427,34 @@ static int parse_variable(git_config_parser *reader, char **var_name, char **var
428427 while (git__isspace (value_start [0 ]))
429428 value_start ++ ;
430429
431- if (unescape_line (var_value , & multiline , value_start , 0 ) < 0 )
432- goto on_error ;
430+ if (( error = unescape_line (& value , & multiline , value_start , 0 ) ) < 0 )
431+ goto out ;
433432
434433 if (multiline ) {
435434 git_buf multi_value = GIT_BUF_INIT ;
436- git_buf_attach (& multi_value , * var_value , 0 );
435+ git_buf_attach (& multi_value , value , 0 );
437436
438437 if (parse_multiline_variable (reader , & multi_value , quote_count ) < 0 ||
439- git_buf_oom (& multi_value )) {
438+ git_buf_oom (& multi_value )) {
439+ error = -1 ;
440440 git_buf_dispose (& multi_value );
441- goto on_error ;
441+ goto out ;
442442 }
443443
444- * var_value = git_buf_detach (& multi_value );
444+ value = git_buf_detach (& multi_value );
445445 }
446446 }
447447
448- git__free (line );
449- return 0 ;
448+ * var_name = name ;
449+ * var_value = value ;
450+ name = NULL ;
451+ value = NULL ;
450452
451- on_error :
452- git__free (* var_name );
453+ out :
454+ git__free (name );
455+ git__free (value );
453456 git__free (line );
454- return -1 ;
457+ return error ;
455458}
456459
457460int git_config_parse (
@@ -463,7 +466,7 @@ int git_config_parse(
463466 void * data )
464467{
465468 git_parse_ctx * ctx ;
466- char * current_section = NULL , * var_name , * var_value ;
469+ char * current_section = NULL , * var_name = NULL , * var_value = NULL ;
467470 int result = 0 ;
468471
469472 ctx = & parser -> ctx ;
@@ -508,7 +511,10 @@ int git_config_parse(
508511 default : /* assume variable declaration */
509512 if ((result = parse_variable (parser , & var_name , & var_value )) == 0 && on_variable ) {
510513 result = on_variable (parser , current_section , var_name , var_value , line_start , line_len , data );
514+ git__free (var_name );
515+ git__free (var_value );
511516 }
517+
512518 break ;
513519 }
514520
0 commit comments