From 08403b616f9dad83cb1204eec83ba1252e3eb129 Mon Sep 17 00:00:00 2001 From: justanothercatgirl Date: Mon, 31 Mar 2025 15:44:36 +0300 Subject: Early working state. TODO: * /api/linkdel, /api/linkget * finish website --- src/common.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/common.c') diff --git a/src/common.c b/src/common.c index 7d8d836..f4e6cdb 100644 --- a/src/common.c +++ b/src/common.c @@ -17,14 +17,15 @@ char *duplicate(const char* x) { // either get a file in a directory %URL or www/%URL.html struct MHD_Response *get_from_file(const char* path) { int fd = open(path, O_RDONLY); + char *wwwdx = NULL; if (fd < 0) { size_t psz = strlen(path); - char *wwwdx = malloc(psz + 4 + 5 + 1); + wwwdx = malloc(psz + 4 + 5 + 1); strcpy(wwwdx, "www/"); strcpy(wwwdx + 4, path); strcpy(wwwdx + 4 + psz, ".html"); fd = open(wwwdx, O_RDONLY); - free(wwwdx); + path = wwwdx; if (fd < 0) return NULL; } struct stat st; @@ -36,5 +37,6 @@ struct MHD_Response *get_from_file(const char* path) { if (lastdot++) MHD_add_response_header(res, "Content-Type", mimetype_get(path + lastdot, len - lastdot)); LDEBUGF("mimetype = %s\n", mimetype_get(path + lastdot, len - lastdot)); + if (wwwdx) free(wwwdx); return res; } -- cgit v1.2.3-70-g09d2