mirror of
https://github.com/lxsang/ant-http
synced 2025-07-15 05:19:55 +02:00
fix memory leak on the new non blocking system
This commit is contained in:
@ -52,18 +52,25 @@ association __put_el_with_key(dictionary dic, const char* key)
|
||||
if(dic == NULL) return NULL;
|
||||
if ((np = dlookup(dic,key)) == NULL) { /* not found */
|
||||
np = (association) malloc(sizeof(*np));
|
||||
np->value = NULL;
|
||||
if (np == NULL || (np->key = strdup(key)) == NULL)
|
||||
return NULL;
|
||||
hashval = hash(key, DHASHSIZE);
|
||||
np->next = dic[hashval];
|
||||
dic[hashval] = np;
|
||||
}
|
||||
// found
|
||||
return np;
|
||||
}
|
||||
association dput(dictionary dic,const char* key, void* value)
|
||||
{
|
||||
association np = __put_el_with_key(dic,key);
|
||||
if(np == NULL) return NULL;
|
||||
if(np == NULL)
|
||||
{
|
||||
if(value) free(value);
|
||||
return NULL;
|
||||
}
|
||||
if(np->value && value) free(np->value);
|
||||
np->value = value;
|
||||
return np;
|
||||
}
|
||||
|
@ -46,6 +46,5 @@ void* dvalue(dictionary, const char*);
|
||||
association dput(dictionary,const char*, void*);
|
||||
int dremove(dictionary, const char*);
|
||||
void freedict(dictionary);
|
||||
void stest(const char* );
|
||||
|
||||
#endif
|
@ -1,5 +1,4 @@
|
||||
#include "handle.h"
|
||||
config_t server_config;
|
||||
#include "handle.h"
|
||||
#ifdef USE_OPENSSL
|
||||
int usessl()
|
||||
{
|
||||
@ -133,10 +132,7 @@ int antd_close(void* src)
|
||||
#endif
|
||||
//printf("Close sock %d\n", source->sock);
|
||||
int ret = close(source->sock);
|
||||
if(source->ip) free(source->ip);
|
||||
// TODO remove this when using nonblocking
|
||||
server_config.connection--;
|
||||
LOG("Remaining connection %d\n", server_config.connection);
|
||||
if(source->ip) free(source->ip);
|
||||
free(src);
|
||||
src = NULL;
|
||||
return ret;
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include "list.h"
|
||||
#include "ini.h"
|
||||
|
||||
#define SERVER_NAME "antd"
|
||||
#define SERVER_NAME "Antd"
|
||||
#define IS_POST(method) (strcmp(method,"POST")== 0)
|
||||
#define IS_GET(method) (strcmp(method,"GET")== 0)
|
||||
#define R_STR(d,k) ((char*)dvalue(d,k))
|
||||
@ -28,6 +28,18 @@
|
||||
#ifdef USE_OPENSSL
|
||||
int __attribute__((weak)) usessl();
|
||||
#endif
|
||||
//extern config_t server_config;
|
||||
typedef struct{
|
||||
int sock;
|
||||
void* ssl;
|
||||
char* ip;
|
||||
} antd_client_t;
|
||||
|
||||
typedef struct {
|
||||
antd_client_t* client;
|
||||
dictionary request;
|
||||
} antd_request_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
int port;
|
||||
@ -41,23 +53,13 @@ typedef struct {
|
||||
int backlog;
|
||||
int maxcon;
|
||||
int connection;
|
||||
int n_workers;
|
||||
#ifdef USE_OPENSSL
|
||||
int usessl;
|
||||
char* sslcert;
|
||||
char* sslkey;
|
||||
#endif
|
||||
}config_t;
|
||||
//extern config_t server_config;
|
||||
typedef struct{
|
||||
int sock;
|
||||
void* ssl;
|
||||
char* ip;
|
||||
} antd_client_t;
|
||||
|
||||
typedef struct {
|
||||
antd_client_t* client;
|
||||
dictionary request;
|
||||
} antd_request_t;
|
||||
|
||||
int response(void*, const char*);
|
||||
void ctype(void*,const char*);
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "plugin.h"
|
||||
|
||||
plugin_header __plugin__;
|
||||
plugin_header_t __plugin__;
|
||||
// private function
|
||||
void __init_plugin__(const char* pl,config_t* conf){
|
||||
__plugin__.name = strdup(pl);
|
||||
@ -40,7 +40,10 @@ int usessl()
|
||||
return __plugin__.usessl;
|
||||
}
|
||||
#endif*/
|
||||
|
||||
plugin_header_t* meta()
|
||||
{
|
||||
return &__plugin__;
|
||||
}
|
||||
char* route(const char* repath)
|
||||
{
|
||||
int len = strlen(__plugin__.name) + 2;
|
||||
@ -74,8 +77,9 @@ char* config_dir()
|
||||
return path;
|
||||
}
|
||||
|
||||
void __release()
|
||||
void __release__()
|
||||
{
|
||||
destroy();
|
||||
printf("Releasing plugin\n");
|
||||
if(__plugin__.name) free(__plugin__.name);
|
||||
if(__plugin__.dbpath) free(__plugin__.dbpath);
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "dbhelper.h"
|
||||
#endif
|
||||
#include "ws.h"
|
||||
#include "scheduler.h"
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
@ -15,7 +16,7 @@ typedef struct {
|
||||
#ifdef USE_OPENSSL
|
||||
int usessl;
|
||||
#endif
|
||||
} plugin_header;
|
||||
} plugin_header_t;
|
||||
|
||||
|
||||
|
||||
@ -23,17 +24,6 @@ typedef struct {
|
||||
#ifdef USE_DB
|
||||
typedef sqlite3* sqldb;
|
||||
#endif
|
||||
/*
|
||||
Two server,
|
||||
Two configuration different
|
||||
Does it work
|
||||
Replace this by a accessing function
|
||||
that execute the set value to
|
||||
the header, instead of
|
||||
exporting global variables
|
||||
*/
|
||||
extern plugin_header __plugin__;
|
||||
//extern call __init__;
|
||||
|
||||
|
||||
#ifdef USE_DB
|
||||
@ -47,6 +37,7 @@ char* config_dir();
|
||||
/*Default function for plugin*/
|
||||
// init the plugin
|
||||
void init();
|
||||
void handle(void*, const char*,const char*,dictionary);
|
||||
void __release();
|
||||
void destroy();
|
||||
void* handle(void*);
|
||||
plugin_header_t* meta();
|
||||
#endif
|
||||
|
@ -165,6 +165,7 @@ void antd_scheduler_destroy(antd_scheduler_t* scheduler)
|
||||
{
|
||||
// free all the chains
|
||||
stop(scheduler);
|
||||
LOG("Destroy remaining queue\n");
|
||||
for(int i=0; i < N_PRIORITY; i++)
|
||||
{
|
||||
destroy_queue(scheduler->task_queue[i]);
|
||||
|
@ -145,7 +145,11 @@ char* ext(const char* file)
|
||||
if(file == NULL) return NULL;
|
||||
char* str_cpy = strdup(file);
|
||||
char* str_org = str_cpy;
|
||||
if(strstr(str_cpy,".")<= 0) return strdup("");
|
||||
if(strstr(str_cpy,".")<= 0)
|
||||
{
|
||||
free(str_org);
|
||||
return NULL;
|
||||
}
|
||||
if(*file == '.')
|
||||
trim(str_cpy,'.');
|
||||
|
||||
@ -184,6 +188,7 @@ mime_t mime_from_type(const char* type)
|
||||
char* mime(const char* file)
|
||||
{
|
||||
char * ex = ext(file);
|
||||
if(!ex) return "application/octet-stream";
|
||||
mime_t m = mime_from_ext(ex);
|
||||
if(ex)
|
||||
free(ex);
|
||||
|
Reference in New Issue
Block a user