Fix file handle leaks in kitty and iTerm2 image display
This commit is contained in:
25
terms.c
25
terms.c
@@ -520,12 +520,12 @@ put_image_iterm2(char *url, int x, int y, int w, int h)
|
|||||||
cbuf = GC_MALLOC_ATOMIC(3072);
|
cbuf = GC_MALLOC_ATOMIC(3072);
|
||||||
i = 0;
|
i = 0;
|
||||||
while ((c = fgetc(fp)) != EOF) {
|
while ((c = fgetc(fp)) != EOF) {
|
||||||
cbuf[i] = c;
|
cbuf[i++] = c;
|
||||||
++i;
|
|
||||||
if (i == 3072) {
|
if (i == 3072) {
|
||||||
base64 = base64_encode(cbuf, i);
|
base64 = base64_encode(cbuf, i);
|
||||||
if (!base64) {
|
if (!base64) {
|
||||||
writestr("\a");
|
writestr("\a");
|
||||||
|
fclose(fp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
writestr(base64);
|
writestr(base64);
|
||||||
@@ -533,6 +533,8 @@ put_image_iterm2(char *url, int x, int y, int w, int h)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
if (i) {
|
if (i) {
|
||||||
base64 = base64_encode(cbuf, i);
|
base64 = base64_encode(cbuf, i);
|
||||||
if (!base64) {
|
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;
|
j = buf->length;
|
||||||
|
|
||||||
while (buf->length + i / 3 * 4 < 4096 && (c = fgetc(fp)) != EOF) {
|
while (buf->length + i / 3 * 4 < 4096 && (c = fgetc(fp)) != EOF) {
|
||||||
cbuf[i] = c;
|
cbuf[i++] = c;
|
||||||
++i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
base64 = base64_encode(cbuf, i);
|
base64 = base64_encode(cbuf, i);
|
||||||
if (!base64)
|
if (!base64) {
|
||||||
|
fclose(fp);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (c == EOF)
|
if (c == EOF)
|
||||||
buf = Sprintf("\x1b_Gf=100,s=%d,v=%d,a=T,m=0,x=%d,y=%d,"
|
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);
|
buf = Sprintf("\x1b_Gm=1;%s\x1b\\", base64);
|
||||||
writestr(buf->ptr);
|
writestr(buf->ptr);
|
||||||
}
|
}
|
||||||
cbuf[i] = c;
|
cbuf[i++] = c;
|
||||||
++i;
|
|
||||||
if (i == 3072) {
|
if (i == 3072) {
|
||||||
base64 = base64_encode(cbuf, i);
|
base64 = base64_encode(cbuf, i);
|
||||||
if (!base64)
|
if (!base64) {
|
||||||
|
fclose(fp);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
i = 0;
|
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) {
|
if (i) {
|
||||||
base64 = base64_encode(cbuf, i);
|
base64 = base64_encode(cbuf, i);
|
||||||
if (!base64)
|
if (!base64) {
|
||||||
|
fclose(fp);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (base64) {
|
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);
|
writestr(buf->ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fclose(fp);
|
||||||
MOVE(Currentbuf->cursorY, Currentbuf->cursorX);
|
MOVE(Currentbuf->cursorY, Currentbuf->cursorX);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user