From c0739e5701637a383d14684bf84dfe9e3c9c60c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Tue, 8 Jun 2021 00:17:42 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=86=E8=8A=82=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmoe.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmoe.c b/cmoe.c index 9092b88..2bb83f5 100644 --- a/cmoe.c +++ b/cmoe.c @@ -33,7 +33,7 @@ static void http_error(char* type, char* msg) { } static char* get_arg(char* query) { - uint32_t len = 0; + int len = 0; while(query[len] && query[len] != '&') len++; if(len > 0) { char* name = malloc(len+1); @@ -162,6 +162,8 @@ static int name_exist(char* name) { SIMPLE_PB *spb = get_pb(fp); COUNTER *d = (COUNTER *)spb->target; if (!strcmp(name, d->name)) { + free(spb); + fclose(fp); return 1; } else free(spb); @@ -175,7 +177,6 @@ static int name_exist(char* name) { //Usage: cmoe method query_string int main(int argc, char **argv) { if(argc == 3) { - uint32_t data_len = 0; char* name = strstr(QS, "name="); items_len = align_struct(sizeof(COUNTER), 2, &counter.name, &counter.count); if(!items_len) http_error(HTTP500, "Align Struct Error."); @@ -190,7 +191,7 @@ int main(int argc, char **argv) { if(reg) { reg = get_arg(reg + 4); if(reg) { - if(strcmp(reg, "fumiama")) http_error(HTTP400, "Token Error."); + if(strcmp(reg, TOKEN)) http_error(HTTP400, "Token Error."); else if(!name_exist(name)) { FILE* fp = fopen(DATFILE, "ab+"); if(fp) {