Browse Source

Leak fix

master
Kirill Nikolaev 6 months ago
parent
commit
1a82b44e24
4 changed files with 9 additions and 12 deletions
  1. +1
    -1
      .gitlab-ci.yml
  2. +1
    -1
      CMakeLists.txt
  3. +6
    -5
      http/http.c
  4. +1
    -5
      http/http.h

+ 1
- 1
.gitlab-ci.yml View File

@@ -4,7 +4,7 @@ stages:

Build:
stage: build
image: registry.oceancraft.ru/yak/env/lmon:v.1.3
image: registry.oceancraft.ru/yak/env/lmon:v.1.4
before_script:
# SysMetricsLib
- git clone https://git.oceancraft.ru/yak/sysmetricslib.git


+ 1
- 1
CMakeLists.txt View File

@@ -3,7 +3,7 @@ project(lmon C)

set(CMAKE_C_STANDARD 99)

SET(CMAKE_EXE_LINKER_FLAGS "-static -Wall -Os -O3")
SET(CMAKE_EXE_LINKER_FLAGS "-Wall -Os -O3")

add_executable(lmon main.c agent/json/json.c agent/json/json.h main.h http/http.h agent/agent.c agent/agent.h server/server.c server/server.h log/log.c log/log.h server/agent.h server/fetch/fetch.c server/fetch/fetch.h http/http.c utils/utils.c utils/utils.h)



+ 6
- 5
http/http.c View File

@@ -6,9 +6,10 @@
int send_page(struct MHD_Connection *connection,
char *text,
char *content_type,
unsigned int status_code) {
unsigned int status_code,
enum MHD_ResponseMemoryMode mode) {

struct MHD_Response *response = MHD_create_response_from_buffer(strlen(text), text, MHD_RESPMEM_MUST_FREE);
struct MHD_Response *response = MHD_create_response_from_buffer(strlen(text), text, mode);
MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_TYPE, content_type);
int ret = MHD_queue_response(connection, status_code, response);
MHD_destroy_response(response);
@@ -16,13 +17,13 @@ int send_page(struct MHD_Connection *connection,
}

int send_json(struct MHD_Connection *connection, char *json) {
return send_page(connection, json, CONTENT_TYPE_JSON, MHD_HTTP_OK);
return send_page(connection, json, CONTENT_TYPE_JSON, MHD_HTTP_OK, MHD_RESPMEM_MUST_FREE);
}

int bad_request(struct MHD_Connection *connection) {
return send_page(connection, BAD_REQUEST, CONTENT_TYPE_TEXT, MHD_HTTP_BAD_REQUEST);
return send_page(connection, BAD_REQUEST, CONTENT_TYPE_TEXT, MHD_HTTP_BAD_REQUEST, MHD_RESPMEM_PERSISTENT);
}

int not_found(struct MHD_Connection *connection) {
return send_page(connection, NOT_FOUND, CONTENT_TYPE_TEXT, MHD_HTTP_NOT_FOUND);
return send_page(connection, NOT_FOUND, CONTENT_TYPE_TEXT, MHD_HTTP_NOT_FOUND, MHD_RESPMEM_PERSISTENT);
}

+ 1
- 5
http/http.h View File

@@ -7,17 +7,13 @@

#include <microhttpd.h>
#include <string.h>
#include <malloc.h>

#define NOT_FOUND "404 page not found"
#define BAD_REQUEST "Bad request"
#define CONTENT_TYPE_JSON "application/json; charset=utf-8"
#define CONTENT_TYPE_TEXT "text/plain; charset=utf-8"

int send_page(struct MHD_Connection *connection,
char *text,
char *content_type,
unsigned int status_code);

int send_json(struct MHD_Connection *connection, char *json);

int bad_request(struct MHD_Connection *connection);


Loading…
Cancel
Save