From b865c0bc123df3561ce7cde70af8d08e8f1055a3 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 15 Nov 2022 15:21:54 -0500 Subject: Fix potential crash when writing state files fails --- src/state.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/state.c') diff --git a/src/state.c b/src/state.c index 58aebf6..a662b8d 100644 --- a/src/state.c +++ b/src/state.c @@ -997,15 +997,15 @@ add_state_to_manifest(LilvWorld* lworld, LILV_ERRORF( "Failed to open %s for writing (%s)\n", manifest_path, strerror(errno)); r = 1; + } else { + SerdWriter* writer = ttl_file_writer(wfd, &manifest, &env); + zix_file_lock(wfd, ZIX_FILE_LOCK_BLOCK); + sord_write(model, writer, NULL); + zix_file_unlock(wfd, ZIX_FILE_LOCK_BLOCK); + serd_writer_free(writer); + fclose(wfd); } - SerdWriter* writer = ttl_file_writer(wfd, &manifest, &env); - zix_file_lock(wfd, ZIX_FILE_LOCK_BLOCK); - sord_write(model, writer, NULL); - zix_file_unlock(wfd, ZIX_FILE_LOCK_BLOCK); - serd_writer_free(writer); - fclose(wfd); - sord_free(model); serd_node_free(&file); serd_node_free(&manifest); -- cgit v1.2.1