diff options
author | bptato <nincsnevem662@gmail.com> | 2021-03-05 14:44:44 +0000 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2021-03-05 14:44:44 +0000 |
commit | 60fd20597c4e6b3b4372ba05c4394874dd8223d6 (patch) | |
tree | 70aa8d24fabc8cb991a87851f2024af1db2e0690 /terms.c | |
parent | Update ChangeLog (diff) | |
download | w3m-60fd20597c4e6b3b4372ba05c4394874dd8223d6.tar.gz w3m-60fd20597c4e6b3b4372ba05c4394874dd8223d6.zip |
Fix file handle leaks in kitty and iTerm2 image display
Diffstat (limited to 'terms.c')
-rw-r--r-- | terms.c | 25 |
1 files changed, 16 insertions, 9 deletions
@@ -520,12 +520,12 @@ put_image_iterm2(char *url, int x, int y, int w, int h) cbuf = GC_MALLOC_ATOMIC(3072); i = 0; while ((c = fgetc(fp)) != EOF) { - cbuf[i] = c; - ++i; + cbuf[i++] = c; if (i == 3072) { base64 = base64_encode(cbuf, i); if (!base64) { writestr("\a"); + fclose(fp); return; } writestr(base64); @@ -533,6 +533,8 @@ put_image_iterm2(char *url, int x, int y, int w, int h) } } + fclose(fp); + if (i) { base64 = base64_encode(cbuf, i); if (!base64) { @@ -634,13 +636,14 @@ put_image_kitty(char *url, int x, int y, int w, int h, int sx, int sy, int sw, j = buf->length; while (buf->length + i / 3 * 4 < 4096 && (c = fgetc(fp)) != EOF) { - cbuf[i] = c; - ++i; + cbuf[i++] = c; } base64 = base64_encode(cbuf, i); - if (!base64) + if (!base64) { + fclose(fp); return; + } if (c == EOF) buf = Sprintf("\x1b_Gf=100,s=%d,v=%d,a=T,m=0,x=%d,y=%d," @@ -659,12 +662,13 @@ put_image_kitty(char *url, int x, int y, int w, int h, int sx, int sy, int sw, buf = Sprintf("\x1b_Gm=1;%s\x1b\\", base64); writestr(buf->ptr); } - cbuf[i] = c; - ++i; + cbuf[i++] = c; if (i == 3072) { base64 = base64_encode(cbuf, i); - if (!base64) + if (!base64) { + fclose(fp); return; + } i = 0; } @@ -672,8 +676,10 @@ put_image_kitty(char *url, int x, int y, int w, int h, int sx, int sy, int sw, if (i) { base64 = base64_encode(cbuf, i); - if (!base64) + if (!base64) { + fclose(fp); return; + } } if (base64) { @@ -681,6 +687,7 @@ put_image_kitty(char *url, int x, int y, int w, int h, int sx, int sy, int sw, writestr(buf->ptr); } } + fclose(fp); MOVE(Currentbuf->cursorY, Currentbuf->cursorX); } |