]> err.no Git - yubikey-server-c/commitdiff
Better error handling in split_otp
authorTollef Fog Heen <tfheen@err.no>
Mon, 12 Oct 2009 06:46:41 +0000 (08:46 +0200)
committerTollef Fog Heen <tfheen@err.no>
Mon, 12 Oct 2009 06:46:41 +0000 (08:46 +0200)
src/main.c

index 2d450b71556bb459ee6085f091d05f4447e9879f..59a498ecda22fc7ee14d5a2f800c32a05c274376 100644 (file)
@@ -222,6 +222,7 @@ static int set_data_for_uid(char *uid, struct ykc_stats *stats)
        PGresult *res;
        const char *paramValues[3];
        char ctr[10], use[10];
+       int r = 0;
 
        paramValues[0] = uid;
 
@@ -242,13 +243,14 @@ static int set_data_for_uid(char *uid, struct ykc_stats *stats)
 
        if (PQresultStatus(res) != PGRES_COMMAND_OK) {
                fprintf(stderr, "UPDATE failed: %s\n", PQerrorMessage(db_conn));
-               PQclear(res);
-               return -1;
-               /* XXX Better error handling.*/
+               r = -1;
+               goto free_mem;
        }
        assert(PQntuples(res) == 0);
+
+free_mem:
        PQclear(res);
-       return 0;
+       return r;
 }
 
 static int get_data_for_uid(char *uid, struct ykc_stats *stats)