diff --git a/sys/src/cmd/jpg/writejpg.c b/sys/src/cmd/jpg/writejpg.c index 737f44780..c5649014e 100644 --- a/sys/src/cmd/jpg/writejpg.c +++ b/sys/src/cmd/jpg/writejpg.c @@ -823,7 +823,6 @@ static void writetrailer(Biobuf *fd) { Bputs(fd, 0xffd9); - Bflush(fd); } static char * @@ -857,8 +856,10 @@ writedata(Biobuf *fd, Image *i, Memimage *m, int gflag, int sflag) else ndata = unloadimage(i, r, data, ndata); if(ndata < 0) { - if((err = malloc(ERRMAX)) == nil) + if((err = malloc(ERRMAX)) == nil) { + free(data); return "WriteJPG: malloc failed"; + } snprint(err, ERRMAX, "WriteJPG: %r"); } else err = encode(fd, r, data, chan, ndata, gflag, sflag); diff --git a/sys/src/cmd/jpg/writeppm.c b/sys/src/cmd/jpg/writeppm.c index dd716cf46..6e2010c24 100644 --- a/sys/src/cmd/jpg/writeppm.c +++ b/sys/src/cmd/jpg/writeppm.c @@ -106,7 +106,7 @@ writedata(Biobuf *fd, Image *image, Memimage *memimage, int rflag) if(col >= MAXLINE-(2+1)){ Bprint(fd, "\n"); col = 0; - }else + }else if(y < r.max.y-1 || x < r.max.x-1) col += Bprint(fd, " "); } if(rflag) @@ -123,7 +123,7 @@ writedata(Biobuf *fd, Image *image, Memimage *memimage, int rflag) if(col >= MAXLINE-(4+1)){ Bprint(fd, "\n"); col = 0; - }else + }else if(i < ndata-1) col += Bprint(fd, " "); } break; @@ -139,7 +139,7 @@ writedata(Biobuf *fd, Image *image, Memimage *memimage, int rflag) if(col >= MAXLINE-(4+4+4+1)){ Bprint(fd, "\n"); col = 0; - }else + }else if(i < ndata-3) col += Bprint(fd, " "); } break;