diff --git a/Geo/ExtractContour.cpp b/Geo/ExtractContour.cpp
index 1f34c16945cd672894e0834a3222c17c8d28c22e..746ec4890e8bede8088acc08948087be5f793250 100644
--- a/Geo/ExtractContour.cpp
+++ b/Geo/ExtractContour.cpp
@@ -1,4 +1,4 @@
-// $Id: ExtractContour.cpp,v 1.6 2005-01-01 19:35:28 geuzaine Exp $
+// $Id: ExtractContour.cpp,v 1.7 2005-03-15 20:13:27 geuzaine Exp $
 //
 // Copyright (C) 1997-2005 C. Geuzaine, J.-F. Remacle
 //
@@ -86,7 +86,7 @@ void recurFindLinkedEdges(int ed, List_T * edges, Tree_T * points, Tree_T * link
   }
 }
 
-void createEdgeLinks(Tree_T *links)
+int createEdgeLinks(Tree_T *links)
 {
   lnk li, *pli;
   nxa na;
@@ -96,6 +96,11 @@ void createEdgeLinks(Tree_T *links)
 
   for(int i = 0; i < List_Nbr(temp); i++) {
     List_Read(temp, i, &c);
+    if(!c->beg || !c->end){
+      List_Delete(temp);
+      Msg(GERROR, "Cannot link curves with no begin or end points");
+      return 0;
+    }
     if(c->Num > 0) {
       na.a = c->Num;
       int ip[2];
@@ -115,6 +120,7 @@ void createEdgeLinks(Tree_T *links)
     }
   }
   List_Delete(temp);
+  return 1;
 }
 
 void orientAndSortEdges(List_T *edges, Tree_T *links)
@@ -176,7 +182,8 @@ int allEdgesLinked(int ed, List_T * edges)
   Tree_T *links = Tree_Create(sizeof(lnk), complink);
   Tree_T *points = Tree_Create(sizeof(int), fcmp_int);
 
-  createEdgeLinks(links);
+  if(!createEdgeLinks(links))
+    return 0;
 
   // initialize point tree with all hanging points
   for(int i = 0; i < List_Nbr(edges); i++){
diff --git a/benchmarks/2d/discrete_curve.geo b/benchmarks/2d/discrete_curve.geo
new file mode 100644
index 0000000000000000000000000000000000000000..2beee96849e07661b422997e1174b13e5762be5f
--- /dev/null
+++ b/benchmarks/2d/discrete_curve.geo
@@ -0,0 +1,108 @@
+Discrete Line (1) = {12}
+{
+  0,0,0,
+  0.008666908357418674,0,0,
+  0.01741059051494093,0,0,
+  0.02623968793850377,0,0,
+  0.03515556989052919,0,0,
+  0.04415202866465823,0,0,
+  0.0532426446041934,0,0,
+  0.0624120060694025,0,0,
+  0.07167921785688836,0,0,
+  0.0810265391141614,0,0,
+  0.09047240713174502,0,0,
+  0.1,0,0
+};
+Discrete Line (2) = {34}
+{
+  0.1,0.3,0,
+  0.1,0.2909090909090913,0,
+  0.1,0.2818181818181826,0,
+  0.1,0.272727272727274,0,
+  0.1,0.2636363636363653,0,
+  0.1,0.2545454545454566,0,
+  0.1,0.245454545454548,0,
+  0.1,0.2363636363636393,0,
+  0.1,0.2272727272727306,0,
+  0.1,0.2181818181818216,0,
+  0.1,0.2090909090909125,0,
+  0.1,0.2000000000000035,0,
+  0.1,0.1909090909090944,0,
+  0.1,0.1818181818181853,0,
+  0.1,0.1727272727272762,0,
+  0.1,0.1636363636363671,0,
+  0.1,0.154545454545458,0,
+  0.1,0.1454545454545489,0,
+  0.1,0.1363636363636398,0,
+  0.1,0.1272727272727307,0,
+  0.1,0.1181818181818216,0,
+  0.1,0.1090909090909125,0,
+  0.1,0.1000000000000034,0,
+  0.1,0.09090909090909433,0,
+  0.1,0.08181818181818527,0,
+  0.1,0.07272727272727605,0,
+  0.1,0.06363636363636654,0,
+  0.1,0.05454545454545703,0,
+  0.1,0.04545454545454754,0,
+  0.1,0.03636363636363803,0,
+  0.1,0.02727272727272851,0,
+  0.1,0.018181818181819,0,
+  0.1,0.009090909090909483,0,
+  0.1,0,0
+};
+Discrete Line (3) = {12}
+{
+  0.1,0.3,0,
+  0.09090909090909115,0.3,0,
+  0.0818181818181823,0.3,0,
+  0.07272727272727345,0.3,0,
+  0.06363636363636459,0.3,0,
+  0.05454545454545573,0.3,0,
+  0.0454545454545468,0.3,0,
+  0.03636363636363778,0.3,0,
+  0.02727272727272877,0.3,0,
+  0.01818181818181929,0.3,0,
+  0.009090909090909639,0.3,0,
+  0,0.3,0
+};
+Discrete Line (4) = {36}
+{
+  0,0.3,0,
+  0,0.2909973636414624,0,
+  0,0.2819947272829249,0,
+  0.01,0.2730438656697747,0,
+  0.02,0.2640976732852516,0,
+  0.01,0.2551978447229378,0,
+  0.02,0.2463080963195167,0,
+  0.03,0.2374585496946034,0,
+  0.06,0.2286252452795079,0,
+  0.04,0.219825219879103,0,
+  0.02,0.2110483594596965,0,
+  0.01,0.2022970847862346,0,
+  0,0.1935766683700231,0,
+  0,0.1848733639512526,0,
+  0,0.176209391545889,0,
+  0,0.167553266739908,0,
+  0,0.1589457383531955,0,
+  0,0.1503382099664829,0,
+  0,0.1417849077882686,0,
+  0,0.1332338234281653,0,
+  0,0.1247260882725001,0,
+  0,0.1162314479471221,0,
+  0,0.1077605053582608,0,
+  0,0.09932087161239131,0,
+  0,0.09090627422926471,0,
+  0,0.08251660763823583,0,
+  0,0.07415176555653609,0,
+  0,0.06581227474114783,0,
+  0,0.05750037195565337,0,
+  0,0.04921307894911468,0,
+  0,0.04095028725862424,0,
+  0,0.03271188767963543,0,
+  0,0.0244977702583297,0,
+  0,0.01630782428387874,0,
+  0,0.008141938280599425,0,
+  0,0,0
+};
+Line Loop(1) = {4,1,-2,3};
+Plane Surface(1) = {1};