@@ -30,10 +30,10 @@ struct mailinfo {
3030 int patch_lines ;
3131 int filter_stage ; /* still reading log or are we copying patch? */
3232 int header_stage ; /* still checking in-body headers? */
33+ struct strbuf * * p_hdr_data ;
34+ struct strbuf * * s_hdr_data ;
3335};
3436
35- static struct strbuf * * p_hdr_data , * * s_hdr_data ;
36-
3737#define MAX_BOUNDARIES 5
3838
3939static void cleanup_space (struct strbuf * sb )
@@ -663,7 +663,7 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
663663 }
664664
665665 if (mi -> use_inbody_headers && mi -> header_stage ) {
666- mi -> header_stage = check_header (mi , line , s_hdr_data , 0 );
666+ mi -> header_stage = check_header (mi , line , mi -> s_hdr_data , 0 );
667667 if (mi -> header_stage )
668668 return 0 ;
669669 } else
@@ -688,9 +688,9 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
688688 * them to give ourselves a clean restart.
689689 */
690690 for (i = 0 ; header [i ]; i ++ ) {
691- if (s_hdr_data [i ])
692- strbuf_release (s_hdr_data [i ]);
693- s_hdr_data [i ] = NULL ;
691+ if (mi -> s_hdr_data [i ])
692+ strbuf_release (mi -> s_hdr_data [i ]);
693+ mi -> s_hdr_data [i ] = NULL ;
694694 }
695695 return 0 ;
696696 }
@@ -840,7 +840,7 @@ static int handle_boundary(struct mailinfo *mi, struct strbuf *line)
840840
841841 /* slurp in this section's info */
842842 while (read_one_header_line (line , mi -> input ))
843- check_header (mi , line , p_hdr_data , 0 );
843+ check_header (mi , line , mi -> p_hdr_data , 0 );
844844
845845 strbuf_release (& newline );
846846 /* replenish line */
@@ -941,10 +941,10 @@ static void handle_info(struct mailinfo *mi)
941941
942942 for (i = 0 ; header [i ]; i ++ ) {
943943 /* only print inbody headers if we output a patch file */
944- if (mi -> patch_lines && s_hdr_data [i ])
945- hdr = s_hdr_data [i ];
946- else if (p_hdr_data [i ])
947- hdr = p_hdr_data [i ];
944+ if (mi -> patch_lines && mi -> s_hdr_data [i ])
945+ hdr = mi -> s_hdr_data [i ];
946+ else if (mi -> p_hdr_data [i ])
947+ hdr = mi -> p_hdr_data [i ];
948948 else
949949 continue ;
950950
@@ -984,8 +984,8 @@ static int mailinfo(struct mailinfo *mi, const char *msg, const char *patch)
984984 return -1 ;
985985 }
986986
987- p_hdr_data = xcalloc (MAX_HDR_PARSED , sizeof (* p_hdr_data ));
988- s_hdr_data = xcalloc (MAX_HDR_PARSED , sizeof (* s_hdr_data ));
987+ mi -> p_hdr_data = xcalloc (MAX_HDR_PARSED , sizeof (* ( mi -> p_hdr_data ) ));
988+ mi -> s_hdr_data = xcalloc (MAX_HDR_PARSED , sizeof (* ( mi -> s_hdr_data ) ));
989989
990990 do {
991991 peek = fgetc (mi -> input );
@@ -994,7 +994,7 @@ static int mailinfo(struct mailinfo *mi, const char *msg, const char *patch)
994994
995995 /* process the email header */
996996 while (read_one_header_line (& line , mi -> input ))
997- check_header (mi , & line , p_hdr_data , 1 );
997+ check_header (mi , & line , mi -> p_hdr_data , 1 );
998998
999999 handle_body (mi , & line );
10001000 fclose (mi -> patchfile );
@@ -1031,10 +1031,19 @@ static void setup_mailinfo(struct mailinfo *mi)
10311031
10321032static void clear_mailinfo (struct mailinfo * mi )
10331033{
1034+ int i ;
1035+
10341036 strbuf_release (& mi -> name );
10351037 strbuf_release (& mi -> email );
10361038 strbuf_release (& mi -> charset );
10371039 free (mi -> message_id );
1040+
1041+ for (i = 0 ; mi -> p_hdr_data [i ]; i ++ )
1042+ strbuf_release (mi -> p_hdr_data [i ]);
1043+ free (mi -> p_hdr_data );
1044+ for (i = 0 ; mi -> s_hdr_data [i ]; i ++ )
1045+ strbuf_release (mi -> s_hdr_data [i ]);
1046+ free (mi -> s_hdr_data );
10381047}
10391048
10401049static const char mailinfo_usage [] =
0 commit comments