From d655c2004280fbb4fcd8537d5a4b554f8fa3846a Mon Sep 17 00:00:00 2001
From: Mayo Roettger <mayo.roettger@uni-duesseldorf.de>
Date: Thu, 13 Sep 2018 16:17:35 +0200
Subject: [PATCH] fixed PROTECT bug

---
 DESCRIPTION  | 6 +++---
 inst/NEWS.Rd | 4 +++-
 src/glpkR.h  | 3 ++-
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/DESCRIPTION b/DESCRIPTION
index 212a305..f0adf34 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -2,7 +2,7 @@ Package: glpkAPI
 Type: Package
 Title: R Interface to C API of GLPK
 Version: 1.3.1
-Date: 2018-09-03
+Date: 2018-09-13
 Authors@R: c(person("Mayo", "Roettger", email = "mayo.roettger@hhu.de", role = "cre"),
     person("Gabriel", "Gelius-Dietrich", role = "aut", email = "geliudie@uni-duesseldorf.de"),
     person("Louis", "Luangkesorn", email = "lugerpitt@gmail.com", role = "ctb" ))
@@ -13,7 +13,7 @@ SystemRequirements: GLPK (>= 4.42)
 License: GPL-3
 LazyLoad: yes
 Collate: generics.R glpk_ptrClass.R glpk.R glpkAPI.R zzz.R
-Packaged: 2018-09-03 08:30:00 UTC; mayo
+Packaged: 2018-09-13 14:05:00 UTC; mayo
 NeedsCompilation: yes
 Repository: CRAN
-Date/Publication: 2018-09-03 08:30:00
+Date/Publication: 2018-09-13 14:05:00
diff --git a/inst/NEWS.Rd b/inst/NEWS.Rd
index 7553ea0..65f7d13 100644
--- a/inst/NEWS.Rd
+++ b/inst/NEWS.Rd
@@ -5,8 +5,10 @@
 \encoding{UTF-8}
 
 % ---------------------------------------------------------------------------- %
-\section{Changes in version 1.3.1 2018-08-22}{
+\section{Changes in version 1.3.1 2018-09-13}{
   \itemize{
+    \item{fixed a bug where an allocating function was called with an unprotected
+        allocated R object in a makro funtion defined in \file{glpkAPI.h}.}
     \item{changed package maintainer}
   }
 }
diff --git a/src/glpkR.h b/src/glpkR.h
index d8265ff..bad42a5 100644
--- a/src/glpkR.h
+++ b/src/glpkR.h
@@ -145,7 +145,7 @@
     const int *rm = INTEGER(m); \
     const int *rn = INTEGER(n); \
     oind = R_Calloc(Rf_asInteger(ne), int); \
-    R_orderVector(oind, Rf_asInteger(ne), Rf_lang2(m, n), TRUE, FALSE); \
+    R_orderVector(oind, Rf_asInteger(ne), PROTECT(Rf_lang2(m, n)), TRUE, FALSE); \
     while (y < Rf_asInteger(ne)) { \
         if ( (rm[oind[y-1]] == rm[oind[y]]) && (rn[oind[y-1]] == rn[oind[y]]) ) { \
             dupA = oind[y-1]; \
@@ -158,6 +158,7 @@
     if (dupB) { \
         Rf_error("Duplicate indices 'ia[%i] = ia[%i] = %i' and 'ja[%i] = ja[%i] = %i' not allowed!", dupA+1, dupB+1, rm[dupA], dupA+1, dupB+1, rn[dupB]); \
     } \
+    UNPROTECT(1)
 } while (0)
 #else
 #define checkDupIndices(m, n, ne)
-- 
GitLab