Parcourir la source

Fix segfault when updating non-existing resource.

scossu il y a 2 semaines
Parent
commit
9df4872bc0
1 fichiers modifiés avec 6 ajouts et 3 suppressions
  1. 6 3
      src/desc.c

+ 6 - 3
src/desc.c

@@ -129,7 +129,8 @@ LSUP_rc
 LSR_desc_store (const LSR_Desc *rsrc)
 {
     LSR_Desc *old_rsrc;
-    PRCCK (LSR_desc_get (rsrc->id, &old_rsrc));
+    LSUP_rc rc = LSR_desc_get (rsrc->id, &old_rsrc);
+    PRCCK (rc);
 
     /*
      * BEGIN txn
@@ -137,7 +138,7 @@ LSR_desc_store (const LSR_Desc *rsrc)
     void *txn;
     LSUP_store_begin (LSR_store, 0, &txn);
     // Remove all existing user graphs.
-    if (old_rsrc) {
+    if (rc == LSUP_OK) {
         // TODO Handle managed preds and types.
         // TODO Handle conflict between disjoint managed types.
         // TODO Retain created and created_by.
@@ -162,7 +163,7 @@ LSR_desc_store (const LSR_Desc *rsrc)
 
     LSUP_Graph *tmp_gr;
     // Add new triples.
-    LSUP_rc rc = LSUP_NOACTION;
+    rc = LSUP_NOACTION;
     for (size_t i = 0; rsrc->user_data[i] != NULL; i++) {
         tmp_gr = LSUP_graph_new (
                 LSR_store, LSUP_graph_uri (rsrc->user_data[i]), NULL);
@@ -350,6 +351,8 @@ LSR_desc_update (
     for (size_t i = 0; i < ct; i++) {
         LSUP_Term *gr_uri = LSUP_graph_uri (add_data[i]);
 
+        log_debug ("Adding graph #%lu with uri: %s", i, gr_uri->data);
+
         LSUP_Term *rel_uri = LSUP_iriref_relative (rsrc_uri, gr_uri);
         if (strstr (rel_uri->data, "#__") == rel_uri->data) {
             log_error ("Fragment URI cannot start with double underscore.");