{
const char *paramValues[1];
PGresult *res;
+ int r = 0;
/* Do query to grab shared secret, we need this later anyway */
paramValues[0] = id;
if (PQresultStatus(res) != PGRES_TUPLES_OK) {
fprintf(stderr, "SELECT failed: %s", PQerrorMessage(db_conn));
- PQclear(res);
- return -1;
+ r = -1;
+ goto free_mem;
/* XXX Return error object */
}
if (PQntuples(res) == 0) {
/* XXX Better handling */
fprintf(stderr, "No such secrets: %s\n", id);
- PQclear(res);
- return -1;
+ r = -1;
+ goto free_mem;
}
*shared_secret_len = PQgetlength(res, 0, 0);
*shared_secret = malloc(*shared_secret_len);
+ if (*shared_secret == NULL) {
+ *shared_secret_len = 0;
+ goto free_mem;
+ }
memcpy(*shared_secret, PQgetvalue(res, 0, 0), *shared_secret_len);
+
+free_mem:
PQclear(res);
- return 0;
+ return r;
}
static int split_otp(const char *otp, char **user, char **s_otp)