mirror of
https://github.com/simon987/sist2.git
synced 2025-04-20 02:36:43 +00:00
Fix some memory leaks
This commit is contained in:
parent
2943ca9365
commit
130fb78787
@ -213,8 +213,10 @@ cJSON *elastic_get_document(const char *uuid_str) {
|
|||||||
snprintf(url, 4096, "%s/sist2/_doc/%s", WebCtx.es_url, uuid_str);
|
snprintf(url, 4096, "%s/sist2/_doc/%s", WebCtx.es_url, uuid_str);
|
||||||
|
|
||||||
response_t *r = web_get(url);
|
response_t *r = web_get(url);
|
||||||
|
cJSON *json = NULL;
|
||||||
if (r->status_code == 200) {
|
if (r->status_code == 200) {
|
||||||
return cJSON_Parse(r->body);
|
json = cJSON_Parse(r->body);
|
||||||
}
|
}
|
||||||
return NULL;
|
free_response(r);
|
||||||
|
return json;
|
||||||
}
|
}
|
||||||
|
@ -49,18 +49,19 @@ response_t *web_post(const char *url, const char *data, const char *header) {
|
|||||||
curl_easy_setopt(curl, CURLOPT_POST, 1);
|
curl_easy_setopt(curl, CURLOPT_POST, 1);
|
||||||
curl_easy_setopt(curl, CURLOPT_USERAGENT, "sist2");
|
curl_easy_setopt(curl, CURLOPT_USERAGENT, "sist2");
|
||||||
|
|
||||||
if (header != NULL) {
|
|
||||||
struct curl_slist *headers = NULL;
|
struct curl_slist *headers = NULL;
|
||||||
|
if (header != NULL) {
|
||||||
headers = curl_slist_append(headers, header);
|
headers = curl_slist_append(headers, header);
|
||||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
|
||||||
|
|
||||||
int r1 = curl_easy_perform(curl);
|
curl_easy_perform(curl);
|
||||||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &resp->status_code);
|
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &resp->status_code);
|
||||||
|
|
||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
|
curl_slist_free_all(headers);
|
||||||
|
|
||||||
resp->body = buffer.buf;
|
resp->body = buffer.buf;
|
||||||
resp->size = buffer.cur;
|
resp->size = buffer.cur;
|
||||||
|
@ -291,6 +291,7 @@ void incremental_copy(store_t *store, store_t *dst_store, const char *filepath,
|
|||||||
size_t buf_len;
|
size_t buf_len;
|
||||||
char *buf = store_read(store, (char *) line.uuid, 16, &buf_len);
|
char *buf = store_read(store, (char *) line.uuid, 16, &buf_len);
|
||||||
store_write(dst_store, (char *) line.uuid, 16, buf, buf_len);
|
store_write(dst_store, (char *) line.uuid, 16, buf, buf_len);
|
||||||
|
free(buf);
|
||||||
|
|
||||||
char c;
|
char c;
|
||||||
while ((c = (char) getc(file))) {
|
while ((c = (char) getc(file))) {
|
||||||
|
@ -64,7 +64,7 @@ void store_write(store_t *store, char *key, size_t key_len, char *buf, size_t bu
|
|||||||
// Cannot resize when there is a opened transaction.
|
// Cannot resize when there is a opened transaction.
|
||||||
// Resize take effect on the next commit.
|
// Resize take effect on the next commit.
|
||||||
pthread_rwlock_wrlock(&store->lock);
|
pthread_rwlock_wrlock(&store->lock);
|
||||||
store->size += 1024 * 1024 * 5;
|
store->size += 1024 * 1024 * 50;
|
||||||
mdb_env_set_mapsize(store->env, store->size);
|
mdb_env_set_mapsize(store->env, store->size);
|
||||||
mdb_txn_begin(store->env, NULL, 0, &txn);
|
mdb_txn_begin(store->env, NULL, 0, &txn);
|
||||||
put_ret = mdb_put(txn, store->dbi, &mdb_key, &mdb_value, 0);
|
put_ret = mdb_put(txn, store->dbi, &mdb_key, &mdb_value, 0);
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#define EPILOG "Made by simon987 <me@simon987.net>. Released under GPL-3.0"
|
#define EPILOG "Made by simon987 <me@simon987.net>. Released under GPL-3.0"
|
||||||
|
|
||||||
|
|
||||||
static const char *const Version = "1.0.9";
|
static const char *const Version = "1.0.10";
|
||||||
static const char *const usage[] = {
|
static const char *const usage[] = {
|
||||||
"sist2 scan [OPTION]... PATH",
|
"sist2 scan [OPTION]... PATH",
|
||||||
"sist2 index [OPTION]... INDEX",
|
"sist2 index [OPTION]... INDEX",
|
||||||
|
@ -156,7 +156,11 @@ void parse_font(const char *buf, size_t buf_len, document_t *doc) {
|
|||||||
char font_name[1024];
|
char font_name[1024];
|
||||||
|
|
||||||
if (face->style_name == NULL || *(face->style_name) == '?') {
|
if (face->style_name == NULL || *(face->style_name) == '?') {
|
||||||
|
if (face->family_name == NULL) {
|
||||||
|
strcpy(font_name, "(null)");
|
||||||
|
} else {
|
||||||
strcpy(font_name, face->family_name);
|
strcpy(font_name, face->family_name);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
snprintf(font_name, sizeof(font_name), "%s %s", face->family_name, face->style_name);
|
snprintf(font_name, sizeof(font_name), "%s %s", face->family_name, face->style_name);
|
||||||
}
|
}
|
||||||
|
@ -349,20 +349,26 @@ int file(void *p, onion_request *req, onion_response *res) {
|
|||||||
cJSON *source = cJSON_GetObjectItem(doc, "_source");
|
cJSON *source = cJSON_GetObjectItem(doc, "_source");
|
||||||
cJSON *index_id = cJSON_GetObjectItem(source, "index");
|
cJSON *index_id = cJSON_GetObjectItem(source, "index");
|
||||||
if (index_id == NULL) {
|
if (index_id == NULL) {
|
||||||
|
cJSON_Delete(doc);
|
||||||
return OCS_NOT_PROCESSED;
|
return OCS_NOT_PROCESSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
index_t *idx = get_index_by_id(index_id->valuestring);
|
index_t *idx = get_index_by_id(index_id->valuestring);
|
||||||
|
|
||||||
if (idx == NULL) {
|
if (idx == NULL) {
|
||||||
|
cJSON_Delete(doc);
|
||||||
return OCS_NOT_PROCESSED;
|
return OCS_NOT_PROCESSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ret;
|
||||||
if (strlen(idx->desc.rewrite_url) == 0) {
|
if (strlen(idx->desc.rewrite_url) == 0) {
|
||||||
return serve_file_from_disk(source, idx, req, res);
|
ret =serve_file_from_disk(source, idx, req, res);
|
||||||
} else {
|
} else {
|
||||||
return serve_file_from_url(source, idx, req, res);
|
ret = serve_file_from_url(source, idx, req, res);
|
||||||
}
|
}
|
||||||
|
cJSON_Delete(doc);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void serve(const char *hostname, const char *port) {
|
void serve(const char *hostname, const char *port) {
|
||||||
|
File diff suppressed because one or more lines are too long
@ -31,7 +31,7 @@ $.jsonPost("i").then(resp => {
|
|||||||
.attr("value", idx.id)
|
.attr("value", idx.id)
|
||||||
.append(idx.name);
|
.append(idx.name);
|
||||||
if (!idx.name.includes("(nsfw)")) {
|
if (!idx.name.includes("(nsfw)")) {
|
||||||
opt.attr("selected", !idx.name.includes("(nsfw)"))
|
opt.attr("selected", !idx.name.includes("(nsfw)"));
|
||||||
selectedIndices.push(idx.id);
|
selectedIndices.push(idx.id);
|
||||||
}
|
}
|
||||||
$("#indices").append(opt);
|
$("#indices").append(opt);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user