shithub: pdffs

Download patch

ref: 61b5e458d92d9341a71fb038c4ffe529e69764a8
parent: 722d214beafe9907b9c44b4046c0378a2c29e1d2
author: Noam Preil <[email protected]>
date: Fri Apr 8 09:14:23 EDT 2022

gs: fix font ownership

--- a/op.c
+++ b/op.c
@@ -80,6 +80,14 @@
 	p->nGS += 1;
 	p->GSactive = &p->GS[p->nGS - 1];
 	*(p->GSactive) = p->GS[p->nGS - 2];
+	if(p->GSactive->Font.widths != nil){
+		p->GSactive->Font.widths = malloc(sizeof(int) * (p->GSactive->Font.last - p->GSactive->Font.first + 1));
+		if(p->GSactive->Font.widths == nil){
+			werrstr("gspush: out of memory allocating space for glyph widths");
+			return 0;
+		}
+		memcpy(p->GSactive->Font.widths, p->GS[p->nGS - 2].Font.widths, sizeof(int) * (p->GSactive->Font.last - p->GSactive->Font.first + 1));
+	}
 	return 1;
 }
 
@@ -1247,10 +1255,6 @@
 gsfree(GS gs)
 {
 	free(gs.Font.widths);
-	pdfobjfree(gs.Font.font);
-	gs.Font.font = nil;
-	gs.Font.enc = nil;
-	gs.Font.widths = nil;
 }
 
 void