Index: texlive/texlive-20170520-source/texk/web2c/luatexdir/lua/lepdflib.cc
===================================================================
--- texlive.orig/texlive-20170520-source/texk/web2c/luatexdir/lua/lepdflib.cc
+++ texlive/texlive-20170520-source/texk/web2c/luatexdir/lua/lepdflib.cc
@@ -130,7 +130,7 @@ static int l_open_PDFDoc(lua_State * L)
         lua_pushnil(L);
     else {
       if (!(globalParams)) // globalParams could be already created
-          globalParams = new GlobalParams();
+          globalParams = std::make_unique<GlobalParams>();
         uout = new_PDFDoc_userdata(L);
         uout->d = d;
         uout->atype = ALLOC_LEPDF;
@@ -184,7 +184,7 @@ static int l_open_MemStreamPDFDoc(lua_St
     }
     else {
       if (!(globalParams)) // globalParams could be already created
-        globalParams = new GlobalParams();
+        globalParams = std::make_unique<GlobalParams>();
       uout = new_PDFDoc_userdata(L);
       uout->d = d;
       uout->atype = ALLOC_LEPDF;
@@ -516,12 +516,11 @@ static int m_##in##_##function(lua_State
 #define m_poppler_get_GOOSTRING(in, function)                  \
 static int m_##in##_##function(lua_State * L)                  \
 {                                                              \
-    const GooString *gs;                                       \
     udstruct *uin;                                             \
     uin = (udstruct *) luaL_checkudata(L, 1, M_##in);          \
     if (uin->pd != NULL && uin->pd->pc != uin->pc)             \
         pdfdoc_changed_error(L);                               \
-    gs = ((in *) uin->d)->function();                          \
+    auto gs = ((in *) uin->d)->function();                     \
     if (gs != NULL)                                            \
         lua_pushlstring(L, gs->c_str(), gs->getLength());      \
     else                                                       \
@@ -855,7 +854,6 @@ static int m_Catalog_findPage(lua_State
 static int m_Catalog_findDest(lua_State * L)
 {
     GooString *name;
-    LinkDest *dest;
     const char *s;
     size_t len;
     udstruct *uin, *uout;
@@ -864,10 +862,10 @@ static int m_Catalog_findDest(lua_State
         pdfdoc_changed_error(L);
     s = luaL_checklstring(L, 2, &len);
     name = new GooString(s, len);
-    dest = ((Catalog *) uin->d)->findDest(name);
+    std::unique_ptr<LinkDest> dest = ((Catalog *) uin->d)->findDest(name);
     if (dest != NULL) {
         uout = new_LinkDest_userdata(L);
-        uout->d = dest;
+        uout->d = new LinkDest(*dest);
         uout->pc = uin->pc;
         uout->pd = uin->pd;
     } else
@@ -1589,7 +1587,7 @@ m_Object_isType(isName);
 m_poppler_get_BOOL(Object, isNull);
 m_poppler_get_BOOL(Object, isArray);
 m_Object_isType(isDict);
-m_Object_isType_nonconst(isStream);
+m_poppler_get_BOOL(Object, isStream);
 m_poppler_get_BOOL(Object, isRef);
 m_Object_isType(isCmd);
 m_poppler_get_BOOL(Object, isError);
@@ -2026,6 +2024,7 @@ static int m_Object_dictGetValNF(lua_Sta
     return 1;
 }
 
+/*
 static int m_Object_streamIs(lua_State * L)
 {
     const char *s;
@@ -2043,7 +2042,7 @@ static int m_Object_streamIs(lua_State *
         lua_pushnil(L);
     return 1;
 }
-
+*/
 static int m_Object_streamReset(lua_State * L)
 {
     udstruct *uin;
@@ -2070,6 +2069,7 @@ static int m_Object_streamGetChar(lua_St
     return 1;
 }
 
+/*
 static int m_Object_streamLookChar(lua_State * L)
 {
     int i;
@@ -2099,6 +2099,7 @@ static int m_Object_streamGetPos(lua_Sta
         lua_pushnil(L);
     return 1;
 }
+*/
 
 static int m_Object_streamSetPos(lua_State * L)
 {
@@ -2206,13 +2207,13 @@ static const struct luaL_Reg Object_m[]
     {"dictGetKey", m_Object_dictGetKey},
     {"dictGetVal", m_Object_dictGetVal},
     {"dictGetValNF", m_Object_dictGetValNF},
-    {"streamIs", m_Object_streamIs},
+    // {"streamIs", m_Object_streamIs},
     {"streamReset", m_Object_streamReset},
     // {"streamClose", m_Object_streamClose},
     {"streamGetChar", m_Object_streamGetChar},
-    {"streamLookChar", m_Object_streamLookChar},
+    // {"streamLookChar", m_Object_streamLookChar},
     // {"streamGetLine", m_Object_streamGetLine},
-    {"streamGetPos", m_Object_streamGetPos},
+    // {"streamGetPos", m_Object_streamGetPos},
     {"streamSetPos", m_Object_streamSetPos},
     {"streamGetDict", m_Object_streamGetDict},
     {"__tostring", m_Object__tostring},
@@ -2399,15 +2400,14 @@ m_PDFDoc_INT(getNumPages);
 
 static int m_PDFDoc_readMetadata(lua_State * L)
 {
-    const GooString *gs;
     udstruct *uin;
     uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc);
     if (uin->pd != NULL && uin->pd->pc != uin->pc)
         pdfdoc_changed_error(L);
     if (((PdfDocument *) uin->d)->doc->getCatalog()->isOk()) {
-        gs = ((PdfDocument *) uin->d)->doc->readMetadata();
-        if (gs != NULL)
-            lua_pushlstring(L, gs->c_str(), gs->getLength());
+	std::unique_ptr<GooString> gs = ((PdfDocument *) uin->d)->doc->readMetadata();
+        if (gs)
+            lua_pushlstring(L, gs->c_str(), gs->getLength());
         else
             lua_pushnil(L);
     } else
@@ -2452,11 +2452,10 @@ static int m_PDFDoc_findPage(lua_State *
         lua_pushnil(L);
     return 1;
 }
-
+/*
 static int m_PDFDoc_getLinks(lua_State * L)
 {
     int i, pages;
-    Links *links;
     udstruct *uin, *uout;
     uin = (udstruct *) luaL_checkudata(L, 1, M_PDFDoc);
     if (uin->pd != NULL && uin->pd->pc != uin->pc)
@@ -2464,8 +2463,8 @@ static int m_PDFDoc_getLinks(lua_State *
     i = luaL_checkint(L, 2);
     pages = ((PdfDocument *) uin->d)->doc->getNumPages();
     if (i > 0 && i <= pages) {
-        links = ((PdfDocument *) uin->d)->doc->getLinks(i);
-        if (links != NULL) {
+        std::unique_ptr<Links> links = ((PdfDocument *) uin->d)->doc->getLinks(i);
+        if (links) {
             uout = new_Links_userdata(L);
             uout->d = links;
             uout->pc = uin->pc;
@@ -2476,11 +2475,10 @@ static int m_PDFDoc_getLinks(lua_State *
         lua_pushnil(L);
     return 1;
 }
-
+*/
 static int m_PDFDoc_findDest(lua_State * L)
 {
     GooString *name;
-    LinkDest *dest;
     const char *s;
     size_t len;
     udstruct *uin, *uout;
@@ -2490,10 +2488,10 @@ static int m_PDFDoc_findDest(lua_State *
     s = luaL_checklstring(L, 2, &len);
     name = new GooString(s, len);
     if (((PdfDocument *) uin->d)->doc->getCatalog()->isOk()) {
-        dest = ((PdfDocument *) uin->d)->doc->findDest(name);
-        if (dest != NULL) {
+        std::unique_ptr<LinkDest> dest = ((PdfDocument *) uin->d)->doc->findDest(name);
+        if (dest) {
             uout = new_LinkDest_userdata(L);
-            uout->d = dest;
+            uout->d = dest->copy();
             uout->pc = uin->pc;
             uout->pd = uin->pd;
         } else
@@ -2583,7 +2581,7 @@ static const struct luaL_Reg PDFDoc_m[]
     {"readMetadata", m_PDFDoc_readMetadata},
     {"getStructTreeRoot", m_PDFDoc_getStructTreeRoot},
     {"findPage", m_PDFDoc_findPage},
-    {"getLinks", m_PDFDoc_getLinks},
+    // {"getLinks", m_PDFDoc_getLinks},
     {"findDest", m_PDFDoc_findDest},
     {"isEncrypted", m_PDFDoc_isEncrypted},
     {"okToPrint", m_PDFDoc_okToPrint},
Index: texlive/texlive-20170520-source/texk/web2c/luatexdir/lua/lpdfscannerlib.cc
===================================================================
--- texlive.orig/texlive-20170520-source/texk/web2c/luatexdir/lua/lpdfscannerlib.cc
+++ texlive/texlive-20170520-source/texk/web2c/luatexdir/lua/lpdfscannerlib.cc
@@ -219,7 +219,7 @@ static int streamGetChar (scannerdata *s
 }
 
 static int streamLookChar (scannerdata *self) {
-  int i= self->_stream->streamLookChar();
+  int i= self->_stream->getStream()->lookChar();
   if (i<0 && self->_streams) {
     _nextStream(self);
     i = streamLookChar(self);
