mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-22 13:37:22 +00:00
[client/common] fixes for issues detected through static analysis.
This commit is contained in:
parent
a3820536ab
commit
3a8cb6a613
@ -57,6 +57,12 @@ void waylandWindowUpdateScale(void)
|
|||||||
static void wlSurfaceEnterHandler(void * data, struct wl_surface * surface, struct wl_output * output)
|
static void wlSurfaceEnterHandler(void * data, struct wl_surface * surface, struct wl_output * output)
|
||||||
{
|
{
|
||||||
struct SurfaceOutput * node = malloc(sizeof(*node));
|
struct SurfaceOutput * node = malloc(sizeof(*node));
|
||||||
|
if (!node)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
node->output = output;
|
node->output = output;
|
||||||
wl_list_insert(&wlWm.surfaceOutputs, &node->link);
|
wl_list_insert(&wlWm.surfaceOutputs, &node->link);
|
||||||
waylandWindowUpdateScale();
|
waylandWindowUpdateScale();
|
||||||
|
@ -152,6 +152,12 @@ static void x11CBReplyFn(void * opaque, LG_ClipboardData type,
|
|||||||
static void x11CBSelectionRequest(const XSelectionRequestEvent e)
|
static void x11CBSelectionRequest(const XSelectionRequestEvent e)
|
||||||
{
|
{
|
||||||
XEvent * s = malloc(sizeof(*s));
|
XEvent * s = malloc(sizeof(*s));
|
||||||
|
if (!s)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
s->xselection.type = SelectionNotify;
|
s->xselection.type = SelectionNotify;
|
||||||
s->xselection.requestor = e.requestor;
|
s->xselection.requestor = e.requestor;
|
||||||
s->xselection.selection = e.selection;
|
s->xselection.selection = e.selection;
|
||||||
|
@ -793,7 +793,7 @@ static bool egl_renderStartup(LG_Renderer * renderer, bool useDMA)
|
|||||||
else if (debug)
|
else if (debug)
|
||||||
DEBUG_WARN("Cannot create debug contexts before EGL 1.5 without EGL_KHR_create_context");
|
DEBUG_WARN("Cannot create debug contexts before EGL 1.5 without EGL_KHR_create_context");
|
||||||
|
|
||||||
ctxattr[ctxidx++] = EGL_NONE;
|
ctxattr[ctxidx] = EGL_NONE;
|
||||||
|
|
||||||
this->context = eglCreateContext(this->display, this->configs, EGL_NO_CONTEXT, ctxattr);
|
this->context = eglCreateContext(this->display, this->configs, EGL_NO_CONTEXT, ctxattr);
|
||||||
if (this->context == EGL_NO_CONTEXT)
|
if (this->context == EGL_NO_CONTEXT)
|
||||||
|
@ -124,10 +124,31 @@ void egl_modelSetDefault(EGL_Model * model, bool flipped)
|
|||||||
void egl_modelAddVerts(EGL_Model * model, const GLfloat * verticies, const GLfloat * uvs, const size_t count)
|
void egl_modelAddVerts(EGL_Model * model, const GLfloat * verticies, const GLfloat * uvs, const size_t count)
|
||||||
{
|
{
|
||||||
struct FloatList * fl = malloc(sizeof(*fl));
|
struct FloatList * fl = malloc(sizeof(*fl));
|
||||||
|
if (!fl)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
fl->count = count;
|
fl->count = count;
|
||||||
|
|
||||||
fl->v = malloc(sizeof(GLfloat) * count * 3);
|
fl->v = malloc(sizeof(GLfloat) * count * 3);
|
||||||
|
if (!fl->v)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
free(fl);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
fl->u = malloc(sizeof(GLfloat) * count * 2);
|
fl->u = malloc(sizeof(GLfloat) * count * 2);
|
||||||
|
if (!fl->u)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
free(fl->v);
|
||||||
|
free(fl);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
memcpy(fl->v, verticies, sizeof(GLfloat) * count * 3);
|
memcpy(fl->v, verticies, sizeof(GLfloat) * count * 3);
|
||||||
|
|
||||||
if (uvs)
|
if (uvs)
|
||||||
|
@ -119,11 +119,16 @@ bool egl_shaderCompile(EGL_Shader * this, const char * vertex_code,
|
|||||||
if (logLength > 0)
|
if (logLength > 0)
|
||||||
{
|
{
|
||||||
char *log = malloc(logLength + 1);
|
char *log = malloc(logLength + 1);
|
||||||
|
if (!log)
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
else
|
||||||
|
{
|
||||||
glGetShaderInfoLog(vertexShader, logLength, NULL, log);
|
glGetShaderInfoLog(vertexShader, logLength, NULL, log);
|
||||||
log[logLength] = 0;
|
log[logLength] = 0;
|
||||||
DEBUG_ERROR("%s", log);
|
DEBUG_ERROR("%s", log);
|
||||||
free(log);
|
free(log);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
glDeleteShader(vertexShader);
|
glDeleteShader(vertexShader);
|
||||||
return false;
|
return false;
|
||||||
@ -145,11 +150,16 @@ bool egl_shaderCompile(EGL_Shader * this, const char * vertex_code,
|
|||||||
if (logLength > 0)
|
if (logLength > 0)
|
||||||
{
|
{
|
||||||
char *log = malloc(logLength + 1);
|
char *log = malloc(logLength + 1);
|
||||||
|
if (!log)
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
else
|
||||||
|
{
|
||||||
glGetShaderInfoLog(fragmentShader, logLength, NULL, log);
|
glGetShaderInfoLog(fragmentShader, logLength, NULL, log);
|
||||||
log[logLength] = 0;
|
log[logLength] = 0;
|
||||||
DEBUG_ERROR("%s", log);
|
DEBUG_ERROR("%s", log);
|
||||||
free(log);
|
free(log);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
glDeleteShader(fragmentShader);
|
glDeleteShader(fragmentShader);
|
||||||
glDeleteShader(vertexShader );
|
glDeleteShader(vertexShader );
|
||||||
@ -201,6 +211,12 @@ void egl_shaderSetUniforms(EGL_Shader * this, EGL_Uniform * uniforms, int count)
|
|||||||
{
|
{
|
||||||
free(this->uniforms);
|
free(this->uniforms);
|
||||||
this->uniforms = malloc(sizeof(*this->uniforms) * count);
|
this->uniforms = malloc(sizeof(*this->uniforms) * count);
|
||||||
|
if (!this->uniforms)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this->uniformCount = count;
|
this->uniformCount = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,7 +327,14 @@ bool opengl_onMouseShape(LG_Renderer * renderer, const LG_RendererCursor cursor,
|
|||||||
{
|
{
|
||||||
if (this->mouseData)
|
if (this->mouseData)
|
||||||
free(this->mouseData);
|
free(this->mouseData);
|
||||||
|
|
||||||
this->mouseData = malloc(size);
|
this->mouseData = malloc(size);
|
||||||
|
if (!this->mouseData)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
this->mouseDataSize = size;
|
this->mouseDataSize = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,6 +230,11 @@ void app_clipboardRequest(const LG_ClipboardReplyFn replyFn, void * opaque)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
struct CBRequest * cbr = malloc(sizeof(*cbr));
|
struct CBRequest * cbr = malloc(sizeof(*cbr));
|
||||||
|
if (!cbr)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
cbr->type = g_state.cbType;
|
cbr->type = g_state.cbType;
|
||||||
cbr->replyFn = replyFn;
|
cbr->replyFn = replyFn;
|
||||||
@ -666,6 +671,12 @@ KeybindHandle app_registerKeybind(int sc, KeybindFn callback, void * opaque, con
|
|||||||
}
|
}
|
||||||
|
|
||||||
KeybindHandle handle = malloc(sizeof(*handle));
|
KeybindHandle handle = malloc(sizeof(*handle));
|
||||||
|
if (!handle)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
handle->sc = sc;
|
handle->sc = sc;
|
||||||
handle->callback = callback;
|
handle->callback = callback;
|
||||||
handle->opaque = opaque;
|
handle->opaque = opaque;
|
||||||
@ -716,6 +727,12 @@ void app_registerOverlay(const struct LG_OverlayOps * ops, const void * params)
|
|||||||
ASSERT_LG_OVERLAY_VALID(ops);
|
ASSERT_LG_OVERLAY_VALID(ops);
|
||||||
|
|
||||||
struct Overlay * overlay = malloc(sizeof(*overlay));
|
struct Overlay * overlay = malloc(sizeof(*overlay));
|
||||||
|
if (!overlay)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of ram");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
overlay->ops = ops;
|
overlay->ops = ops;
|
||||||
overlay->params = params;
|
overlay->params = params;
|
||||||
overlay->udata = NULL;
|
overlay->udata = NULL;
|
||||||
@ -732,6 +749,7 @@ void app_initOverlays(void)
|
|||||||
ll_lock(g_state.overlays);
|
ll_lock(g_state.overlays);
|
||||||
ll_forEachNL(g_state.overlays, item, overlay)
|
ll_forEachNL(g_state.overlays, item, overlay)
|
||||||
{
|
{
|
||||||
|
DEBUG_ASSERT(overlay->ops);
|
||||||
if (!overlay->ops->init(&overlay->udata, overlay->params))
|
if (!overlay->ops->init(&overlay->udata, overlay->params))
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("Overlay `%s` failed to initialize", overlay->ops->name);
|
DEBUG_ERROR("Overlay `%s` failed to initialize", overlay->ops->name);
|
||||||
|
@ -505,8 +505,18 @@ bool config_load(int argc, char * argv[])
|
|||||||
|
|
||||||
// load config from user's home directory
|
// load config from user's home directory
|
||||||
struct passwd * pw = getpwuid(getuid());
|
struct passwd * pw = getpwuid(getuid());
|
||||||
|
if (!pw)
|
||||||
|
DEBUG_WARN("getpwuid failed, unable to load user configuration");
|
||||||
|
else
|
||||||
|
{
|
||||||
char * localFile;
|
char * localFile;
|
||||||
alloc_sprintf(&localFile, "%s/.looking-glass-client.ini", pw->pw_dir);
|
alloc_sprintf(&localFile, "%s/.looking-glass-client.ini", pw->pw_dir);
|
||||||
|
if (!localFile)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (stat(localFile, &st) >= 0 && S_ISREG(st.st_mode))
|
if (stat(localFile, &st) >= 0 && S_ISREG(st.st_mode))
|
||||||
{
|
{
|
||||||
DEBUG_INFO("Loading config from: %s", localFile);
|
DEBUG_INFO("Loading config from: %s", localFile);
|
||||||
@ -517,10 +527,16 @@ bool config_load(int argc, char * argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(localFile);
|
free(localFile);
|
||||||
|
}
|
||||||
|
|
||||||
// load config from XDG_CONFIG_HOME
|
// load config from XDG_CONFIG_HOME
|
||||||
char * xdgFile;
|
char * xdgFile;
|
||||||
alloc_sprintf(&xdgFile, "%s/client.ini", lgConfigDir());
|
alloc_sprintf(&xdgFile, "%s/client.ini", lgConfigDir());
|
||||||
|
if (!xdgFile)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (xdgFile && stat(xdgFile, &st) >= 0 && S_ISREG(st.st_mode))
|
if (xdgFile && stat(xdgFile, &st) >= 0 && S_ISREG(st.st_mode))
|
||||||
{
|
{
|
||||||
@ -714,6 +730,8 @@ static bool optRendererParse(struct Option * opt, const char * str)
|
|||||||
static StringList optRendererValues(struct Option * opt)
|
static StringList optRendererValues(struct Option * opt)
|
||||||
{
|
{
|
||||||
StringList sl = stringlist_new(false);
|
StringList sl = stringlist_new(false);
|
||||||
|
if (!sl)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
// this typecast is safe as the stringlist doesn't own the values
|
// this typecast is safe as the stringlist doesn't own the values
|
||||||
for(unsigned int i = 0; i < LG_RENDERER_COUNT; ++i)
|
for(unsigned int i = 0; i < LG_RENDERER_COUNT; ++i)
|
||||||
@ -756,6 +774,9 @@ static bool optPosParse(struct Option * opt, const char * str)
|
|||||||
static StringList optPosValues(struct Option * opt)
|
static StringList optPosValues(struct Option * opt)
|
||||||
{
|
{
|
||||||
StringList sl = stringlist_new(false);
|
StringList sl = stringlist_new(false);
|
||||||
|
if (!sl)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
stringlist_push(sl, "center");
|
stringlist_push(sl, "center");
|
||||||
stringlist_push(sl, "<left>x<top>, e.g. 100x100");
|
stringlist_push(sl, "<left>x<top>, e.g. 100x100");
|
||||||
return sl;
|
return sl;
|
||||||
@ -768,6 +789,11 @@ static char * optPosToString(struct Option * opt)
|
|||||||
|
|
||||||
int len = snprintf(NULL, 0, "%dx%d", g_params.x, g_params.y);
|
int len = snprintf(NULL, 0, "%dx%d", g_params.x, g_params.y);
|
||||||
char * str = malloc(len + 1);
|
char * str = malloc(len + 1);
|
||||||
|
if (!str)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
sprintf(str, "%dx%d", g_params.x, g_params.y);
|
sprintf(str, "%dx%d", g_params.x, g_params.y);
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
@ -791,6 +817,9 @@ static bool optSizeParse(struct Option * opt, const char * str)
|
|||||||
static StringList optSizeValues(struct Option * opt)
|
static StringList optSizeValues(struct Option * opt)
|
||||||
{
|
{
|
||||||
StringList sl = stringlist_new(false);
|
StringList sl = stringlist_new(false);
|
||||||
|
if (!sl)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
stringlist_push(sl, "<left>x<top>, e.g. 100x100");
|
stringlist_push(sl, "<left>x<top>, e.g. 100x100");
|
||||||
return sl;
|
return sl;
|
||||||
}
|
}
|
||||||
@ -799,6 +828,11 @@ static char * optSizeToString(struct Option * opt)
|
|||||||
{
|
{
|
||||||
int len = snprintf(NULL, 0, "%ux%u", g_params.w, g_params.h);
|
int len = snprintf(NULL, 0, "%ux%u", g_params.w, g_params.h);
|
||||||
char * str = malloc(len + 1);
|
char * str = malloc(len + 1);
|
||||||
|
if (!str)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
sprintf(str, "%ux%u", g_params.w, g_params.h);
|
sprintf(str, "%ux%u", g_params.w, g_params.h);
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
|
@ -641,6 +641,11 @@ int main_frameThread(void * unused)
|
|||||||
case FRAME_ROT_90 : lgrFormat.rotate = LG_ROTATE_90 ; break;
|
case FRAME_ROT_90 : lgrFormat.rotate = LG_ROTATE_90 ; break;
|
||||||
case FRAME_ROT_180: lgrFormat.rotate = LG_ROTATE_180; break;
|
case FRAME_ROT_180: lgrFormat.rotate = LG_ROTATE_180; break;
|
||||||
case FRAME_ROT_270: lgrFormat.rotate = LG_ROTATE_270; break;
|
case FRAME_ROT_270: lgrFormat.rotate = LG_ROTATE_270; break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
DEBUG_ERROR("Unsupported/invalid frame rotation");
|
||||||
|
lgrFormat.rotate = LG_ROTATE_0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
g_state.rotate = lgrFormat.rotate;
|
g_state.rotate = lgrFormat.rotate;
|
||||||
|
|
||||||
@ -1113,7 +1118,7 @@ static int lg_run(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// select and init a renderer
|
// select and init a renderer
|
||||||
bool needsOpenGL;
|
bool needsOpenGL = false;
|
||||||
LG_RendererParams lgrParams;
|
LG_RendererParams lgrParams;
|
||||||
lgrParams.quickSplash = g_params.quickSplash;
|
lgrParams.quickSplash = g_params.quickSplash;
|
||||||
|
|
||||||
|
@ -216,6 +216,12 @@ GraphHandle overlayGraph_register(const char * name, RingBuffer buffer,
|
|||||||
float min, float max, GraphFormatFn formatFn)
|
float min, float max, GraphFormatFn formatFn)
|
||||||
{
|
{
|
||||||
struct OverlayGraph * graph = malloc(sizeof(*graph));
|
struct OverlayGraph * graph = malloc(sizeof(*graph));
|
||||||
|
if (!graph)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
graph->name = name;
|
graph->name = name;
|
||||||
graph->buffer = buffer;
|
graph->buffer = buffer;
|
||||||
graph->enabled = true;
|
graph->enabled = true;
|
||||||
|
@ -152,6 +152,12 @@ MsgBoxHandle overlayMsg_show(
|
|||||||
const char * caption, const char * fmt, va_list args)
|
const char * caption, const char * fmt, va_list args)
|
||||||
{
|
{
|
||||||
struct Msg * msg = malloc(sizeof(*msg));
|
struct Msg * msg = malloc(sizeof(*msg));
|
||||||
|
if (!msg)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
msg->caption = strdup(caption);
|
msg->caption = strdup(caption);
|
||||||
msg->lines = stringlist_new(false);
|
msg->lines = stringlist_new(false);
|
||||||
valloc_sprintf(&msg->message, fmt, args);
|
valloc_sprintf(&msg->message, fmt, args);
|
||||||
|
@ -26,6 +26,12 @@
|
|||||||
struct ll * ll_new(void)
|
struct ll * ll_new(void)
|
||||||
{
|
{
|
||||||
struct ll * list = malloc(sizeof(*list));
|
struct ll * list = malloc(sizeof(*list));
|
||||||
|
if (!list)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
list->head = NULL;
|
list->head = NULL;
|
||||||
list->tail = NULL;
|
list->tail = NULL;
|
||||||
list->count = 0;
|
list->count = 0;
|
||||||
@ -45,6 +51,12 @@ void ll_free(struct ll * list)
|
|||||||
void ll_push(struct ll * list, void * data)
|
void ll_push(struct ll * list, void * data)
|
||||||
{
|
{
|
||||||
struct ll_item * item = malloc(sizeof(*item));
|
struct ll_item * item = malloc(sizeof(*item));
|
||||||
|
if (!item)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
item->data = data;
|
item->data = data;
|
||||||
item->next = NULL;
|
item->next = NULL;
|
||||||
|
|
||||||
|
@ -88,6 +88,12 @@ static char * int_toString(struct Option * opt)
|
|||||||
{
|
{
|
||||||
int len = snprintf(NULL, 0, "%d", opt->value.x_int);
|
int len = snprintf(NULL, 0, "%d", opt->value.x_int);
|
||||||
char * ret = malloc(len + 1);
|
char * ret = malloc(len + 1);
|
||||||
|
if (!ret)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
sprintf(ret, "%d", opt->value.x_int);
|
sprintf(ret, "%d", opt->value.x_int);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -101,6 +107,12 @@ static char * float_toString(struct Option * opt)
|
|||||||
{
|
{
|
||||||
int len = snprintf(NULL, 0, "%f", opt->value.x_float);
|
int len = snprintf(NULL, 0, "%f", opt->value.x_float);
|
||||||
char * ret = malloc(len + 1);
|
char * ret = malloc(len + 1);
|
||||||
|
if (!ret)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
sprintf(ret, "%f", opt->value.x_float);
|
sprintf(ret, "%f", opt->value.x_float);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -124,10 +136,22 @@ bool option_register(struct Option options[])
|
|||||||
sizeof(*state.options) * (state.oCount + new)
|
sizeof(*state.options) * (state.oCount + new)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!state.options)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
for(int i = 0; options[i].type != OPTION_TYPE_NONE; ++i)
|
for(int i = 0; options[i].type != OPTION_TYPE_NONE; ++i)
|
||||||
{
|
{
|
||||||
|
struct Option * o =
|
||||||
state.options[state.oCount + i] = malloc(sizeof(**state.options));
|
state.options[state.oCount + i] = malloc(sizeof(**state.options));
|
||||||
struct Option * o = state.options[state.oCount + i];
|
if (!o)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
memcpy(o, &options[i], sizeof(*o));
|
memcpy(o, &options[i], sizeof(*o));
|
||||||
|
|
||||||
if (!o->parser)
|
if (!o->parser)
|
||||||
@ -186,7 +210,14 @@ bool option_register(struct Option options[])
|
|||||||
if (o->type == OPTION_TYPE_STRING)
|
if (o->type == OPTION_TYPE_STRING)
|
||||||
{
|
{
|
||||||
if (o->value.x_string)
|
if (o->value.x_string)
|
||||||
|
{
|
||||||
o->value.x_string = strdup(o->value.x_string);
|
o->value.x_string = strdup(o->value.x_string);
|
||||||
|
if (!o->value.x_string)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the option to the correct group for help printout
|
// add the option to the correct group for help printout
|
||||||
@ -202,6 +233,11 @@ bool option_register(struct Option options[])
|
|||||||
group->options,
|
group->options,
|
||||||
sizeof(*group->options) * (group->count + 1)
|
sizeof(*group->options) * (group->count + 1)
|
||||||
);
|
);
|
||||||
|
if (!group->options)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
group->options[group->count] = o;
|
group->options[group->count] = o;
|
||||||
|
|
||||||
int len = strlen(o->name);
|
int len = strlen(o->name);
|
||||||
@ -218,6 +254,11 @@ bool option_register(struct Option options[])
|
|||||||
state.groups,
|
state.groups,
|
||||||
sizeof(*state.groups) * (state.gCount + 1)
|
sizeof(*state.groups) * (state.gCount + 1)
|
||||||
);
|
);
|
||||||
|
if (!state.groups)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
struct OptionGroup * group = &state.groups[state.gCount];
|
struct OptionGroup * group = &state.groups[state.gCount];
|
||||||
++state.gCount;
|
++state.gCount;
|
||||||
@ -239,7 +280,7 @@ void option_free(void)
|
|||||||
for(int i = 0; i < state.oCount; ++i)
|
for(int i = 0; i < state.oCount; ++i)
|
||||||
{
|
{
|
||||||
struct Option * o = state.options[i];
|
struct Option * o = state.options[i];
|
||||||
if (o->type == OPTION_TYPE_STRING)
|
if (o->type == OPTION_TYPE_STRING && o->value.x_string)
|
||||||
free(o->value.x_string);
|
free(o->value.x_string);
|
||||||
free(o);
|
free(o);
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ bool ivshmemOpenDev(struct IVSHMEM * dev, const char * shmDevice)
|
|||||||
DEBUG_ASSERT(dev);
|
DEBUG_ASSERT(dev);
|
||||||
|
|
||||||
unsigned int devSize;
|
unsigned int devSize;
|
||||||
int devFd = -1;
|
int devFd;
|
||||||
bool hasDMA;
|
bool hasDMA;
|
||||||
|
|
||||||
dev->opaque = NULL;
|
dev->opaque = NULL;
|
||||||
|
@ -44,6 +44,12 @@ static void * threadWrapper(void * opaque)
|
|||||||
bool lgCreateThread(const char * name, LGThreadFunction function, void * opaque, LGThread ** handle)
|
bool lgCreateThread(const char * name, LGThreadFunction function, void * opaque, LGThread ** handle)
|
||||||
{
|
{
|
||||||
*handle = malloc(sizeof(**handle));
|
*handle = malloc(sizeof(**handle));
|
||||||
|
if (!*handle)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
(*handle)->name = name;
|
(*handle)->name = name;
|
||||||
(*handle)->function = function;
|
(*handle)->function = function;
|
||||||
(*handle)->opaque = opaque;
|
(*handle)->opaque = opaque;
|
||||||
|
@ -42,6 +42,12 @@ RingBuffer ringbuffer_newInternal(int length, size_t valueSize,
|
|||||||
DEBUG_ASSERT(valueSize > 0 && valueSize < UINT32_MAX);
|
DEBUG_ASSERT(valueSize > 0 && valueSize < UINT32_MAX);
|
||||||
|
|
||||||
struct RingBuffer * rb = calloc(1, sizeof(*rb) + valueSize * length);
|
struct RingBuffer * rb = calloc(1, sizeof(*rb) + valueSize * length);
|
||||||
|
if (!rb)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
rb->length = length;
|
rb->length = length;
|
||||||
rb->valueSize = valueSize;
|
rb->valueSize = valueSize;
|
||||||
atomic_store(&rb->readPos , 0);
|
atomic_store(&rb->readPos , 0);
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "common/runningavg.h"
|
#include "common/runningavg.h"
|
||||||
|
#include "common/debug.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@ -33,6 +34,12 @@ struct RunningAvg
|
|||||||
RunningAvg runningavg_new(int length)
|
RunningAvg runningavg_new(int length)
|
||||||
{
|
{
|
||||||
struct RunningAvg * ra = calloc(1, sizeof(*ra) + sizeof(*ra->values) * length);
|
struct RunningAvg * ra = calloc(1, sizeof(*ra) + sizeof(*ra->values) * length);
|
||||||
|
if (!ra)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
ra->length = length;
|
ra->length = length;
|
||||||
return ra;
|
return ra;
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "common/stringlist.h"
|
#include "common/stringlist.h"
|
||||||
#include "common/vector.h"
|
#include "common/vector.h"
|
||||||
|
#include "common/debug.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@ -32,6 +33,12 @@ struct StringList
|
|||||||
StringList stringlist_new(bool owns_strings)
|
StringList stringlist_new(bool owns_strings)
|
||||||
{
|
{
|
||||||
StringList sl = malloc(sizeof(*sl));
|
StringList sl = malloc(sizeof(*sl));
|
||||||
|
if (!sl)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("out of memory");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
sl->owns_strings = owns_strings;
|
sl->owns_strings = owns_strings;
|
||||||
|
|
||||||
if (!vector_create(&sl->vector, sizeof(char *), 32))
|
if (!vector_create(&sl->vector, sizeof(char *), 32))
|
||||||
|
Loading…
Reference in New Issue
Block a user