Commit f5809a18 authored by mark@mpc1685's avatar mark@mpc1685
Browse files

Fixed memory leaks in picoserverli

parent 8c2c4827
......@@ -110,27 +110,32 @@ static void SetGenerator(long freq, float ampl)
void picoBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf)
{
size_t pSize;
if(suggested_size > 8192){
if(suggested_size > 256){
pSize = suggested_size;
} else {
pSize = 8192;
pSize = 256;
}
*buf = uv_buf_init(malloc(pSize),pSize);
}
/*--------------------------------------------------------------------*/
static void picoWriteCallback(uv_write_t *req, int status)
{
uv_buf_t *buf = (uv_buf_t*)req->data;
free(buf->base);
free(buf);
free(req);
}
/*---------------------------------------------------------------------*/
static void picoSendReply(uv_stream_t *stream, char *reply)
{
uv_write_t *wreq;
uv_buf_t buf;
uv_buf_t *buf;
wreq = malloc(sizeof(uv_write_t));
buf = uv_buf_init(malloc(strlen(reply)+1),strlen(reply)+1);
strcpy(buf.base,reply);
uv_write((uv_write_t*)wreq,stream,&buf,1,picoWriteCallback);
buf = malloc(sizeof(uv_buf_t));
*buf = uv_buf_init(malloc(strlen(reply)+1),strlen(reply)+1);
strcpy(buf->base,reply);
wreq->data = buf;
uv_write((uv_write_t*)wreq,stream,buf,1,picoWriteCallback);
}
/*----------------------------------------------------------------------*/
void picoRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
......@@ -176,11 +181,11 @@ void picoRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
}
picoSendReply(stream,reply);
} else {
snprintf(reply,sizeof(reply),"Command %s not understood. use freq, ampl\n", command);
snprintf(reply,sizeof(reply),"Command %s not understood, use freq, ampl\n", command);
picoSendReply(stream,reply);
}
free(buf->base);
free(buf->base);
}
}
/*----------------------------------------------------------------------*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment