]> err.no Git - yubikey-server-c/commitdiff
Free alloced memory
authorTollef Fog Heen <tfheen@err.no>
Mon, 12 Oct 2009 06:17:54 +0000 (08:17 +0200)
committerTollef Fog Heen <tfheen@err.no>
Mon, 12 Oct 2009 06:17:54 +0000 (08:17 +0200)
src/main.c

index 2e8be42f830a0c00721fd270af8b1928e44a0685..1449ea94f1e785fa61ebd44f10861703e649e897 100644 (file)
@@ -310,8 +310,7 @@ static int handle_request(void * UNUSED(data),
                /* XXX: Something blew up, assume no such ID */
                status = "NO_SUCH_CLIENT";
                send_response(conn, NULL, status, NULL, timestamp);
-               /* XXX free memory */
-               return MHD_YES;
+               goto free_mem;
        }
 
        if (otp == NULL) {
@@ -320,8 +319,7 @@ static int handle_request(void * UNUSED(data),
                signature = sign_request(shared_secret, shared_secret_len,
                                         info, status, timestamp);
                send_response(conn, signature, status, NULL, timestamp);
-               /* XXX free memory */
-               return MHD_YES;
+               goto free_mem;
        }
 
        if (! yubikey_modhex_p(otp)) {
@@ -329,8 +327,7 @@ static int handle_request(void * UNUSED(data),
                signature = sign_request(shared_secret, shared_secret_len,
                                         NULL, status, timestamp);
                send_response(conn, signature, status, NULL, timestamp);
-               /* XXX free memory */
-               return MHD_YES;
+               goto free_mem;
        }
 
        /* XXX: If h exists, verify. FIXME */
@@ -350,8 +347,7 @@ static int handle_request(void * UNUSED(data),
                                         NULL, status, timestamp);
                send_response(conn, signature, status, NULL, timestamp);
 
-               /* XXX FIXME free memory */
-               fprintf(stderr, "BAD TOKEN\n");
+               goto free_mem;
                return MHD_YES;
        }
        if (yubikey_counter(token.ctr) < stats.session_counter ||
@@ -362,12 +358,14 @@ static int handle_request(void * UNUSED(data),
                signature = sign_request(shared_secret, shared_secret_len,
                                         NULL, status, timestamp);
                send_response(conn, signature, status, NULL, timestamp);
-               /* XXX FIXME free memory */
                fprintf(stderr, "replay\n");
-               return MHD_YES;
+               goto free_mem;
        }
 
        /* Update status, if appropriate */
+       free(stats.public_id);
+       free(stats.secret_uid);
+       free(stats.secret_key);
        memset(&stats, 0, sizeof(struct ykc_stats));
        stats.session_counter = yubikey_counter(token.ctr);
        stats.session_use = token.use;
@@ -378,6 +376,15 @@ static int handle_request(void * UNUSED(data),
        signature = sign_request(shared_secret, shared_secret_len,
                                 NULL, status, timestamp);
        send_response(conn, signature, status, NULL, timestamp);
+free_mem:
+       free(timestamp);
+       free(shared_secret);
+       free(signature);
+       free(stats.public_id);
+       free(stats.secret_uid);
+       free(stats.secret_key);
+       free(uid);
+       free(otp_token);
        return MHD_YES;
 }