From: Tollef Fog Heen Date: Mon, 12 Oct 2009 06:46:41 +0000 (+0200) Subject: Better error handling in split_otp X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f8f7e38ee7247bc25850224f5ea3e40b827435a;p=yubikey-server-c Better error handling in split_otp --- diff --git a/src/main.c b/src/main.c index 2d450b7..59a498e 100644 --- a/src/main.c +++ b/src/main.c @@ -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)