# HG changeset patch # User Matti Hamalainen # Date 1455525337 -7200 # Node ID e9dbedc4d5e478c3a05cdf1e666b1e9d8b6890f9 # Parent 59b5b99f4280e2c997dd239cca06322bde53dfdb Improve error handling. diff -r 59b5b99f4280 -r e9dbedc4d5e4 sidinfo.c --- 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