Merge branch 'ma/pkt-line-leakfix'
authorJunio C Hamano <gitster@pobox.com>
Tue, 19 Sep 2017 01:47:52 +0000 (10:47 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 19 Sep 2017 01:47:52 +0000 (10:47 +0900)
A leakfix.

* ma/pkt-line-leakfix:
pkt-line: re-'static'-ify buffer in packet_write_fmt_1()

1  2 
pkt-line.c
diff --combined pkt-line.c
index 7db9119573abe2c8308bd37c670c027c07b425c8,bfee02bbf633d183c8f2ff79eebcfba740f1963c..f364944b931a756b3b4819fb49ff5e9e01daf676
@@@ -136,9 -136,10 +136,10 @@@ static void format_packet(struct strbu
  static int packet_write_fmt_1(int fd, int gently,
                              const char *fmt, va_list args)
  {
-       struct strbuf buf = STRBUF_INIT;
+       static struct strbuf buf = STRBUF_INIT;
        ssize_t count;
  
+       strbuf_reset(&buf);
        format_packet(&buf, fmt, args);
        count = write_in_full(fd, buf.buf, buf.len);
        if (count == buf.len)
@@@ -315,7 -316,7 +316,7 @@@ static char *packet_read_line_generic(i
                              PACKET_READ_CHOMP_NEWLINE);
        if (dst_len)
                *dst_len = len;
 -      return len ? packet_buffer : NULL;
 +      return (len > 0) ? packet_buffer : NULL;
  }
  
  char *packet_read_line(int fd, int *len_p)
        return packet_read_line_generic(fd, NULL, NULL, len_p);
  }
  
 +int packet_read_line_gently(int fd, int *dst_len, char **dst_line)
 +{
 +      int len = packet_read(fd, NULL, NULL,
 +                            packet_buffer, sizeof(packet_buffer),
 +                            PACKET_READ_CHOMP_NEWLINE|PACKET_READ_GENTLE_ON_EOF);
 +      if (dst_len)
 +              *dst_len = len;
 +      if (dst_line)
 +              *dst_line = (len > 0) ? packet_buffer : NULL;
 +      return len;
 +}
 +
  char *packet_read_line_buf(char **src, size_t *src_len, int *dst_len)
  {
        return packet_read_line_generic(-1, src, src_len, dst_len);