diff options
Diffstat (limited to 'src/common.c')
-rw-r--r-- | src/common.c | 6 |
1 files changed, 4 insertions, 2 deletions
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; } |