changeset 110:e9dbedc4d5e4

Improve error handling.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 15 Feb 2016 10:35:37 +0200
parents 59b5b99f4280
children c7ecf56d23e7
files sidinfo.c
diffstat 1 files changed, 15 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/sidinfo.c	Mon Feb 15 10:35:22 2016 +0200
+++ b/sidinfo.c	Mon Feb 15 10:35:37 2016 +0200
@@ -602,23 +602,27 @@
     if (setSLDBPath != NULL)
     {
         // Initialize SLDB
-        int ret;
-        th_ioctx *ctx;
+        int ret = THERR_OK;
+        th_ioctx *ctx = NULL;
         if ((ctx = th_io_fopen(&th_stdio_io_ops, setSLDBPath, "r")) == NULL)
         {
             THERR("Could not open SLDB '%s'.\n",
                 setSLDBPath);
-            goto out;
+            goto err;
         }
 
         THMSG(0, "Reading SLDB.\n");
-        if ((sidSLDB = si_sldb_new()) == NULL ||
-            (ret = si_sldb_read(ctx, sidSLDB)) != THERR_OK)
+        if ((sidSLDB = si_sldb_new()) == NULL)
+        {
+            THERR("Could not allocate SLDB structure!\n");
+            goto err;
+        }
+
+        if ((ret = si_sldb_read(ctx, sidSLDB)) != THERR_OK)
         {
             THERR("Error parsing SLDB: %d, %s\n",
                 ret, th_error_str(ret));
-            th_io_close(ctx);
-            goto out;
+            goto err;
         }
         th_io_close(ctx);
 
@@ -626,8 +630,11 @@
         {
             THERR("Error building SLDB index: %d, %s.\n",
                 ret, th_error_str(ret));
-            goto out;
+            goto err;
         }
+
+err:
+        th_io_close(ctx);
     }
 
     // Process files