Skip to content
Snippets Groups Projects
Commit 13de1fc4 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Fix memory leak in default movetext implementation

Reported by @anonymouspage, closes !211
Clean up  formatting in the touched functions while we're here.
parent 5ebaea2b
Branches
Tags
No related merge requests found
...@@ -549,34 +549,34 @@ CIOLIBEXPORT int ciolib_movetext(int sx, int sy, int ex, int ey, int dx, int dy) ...@@ -549,34 +549,34 @@ CIOLIBEXPORT int ciolib_movetext(int sx, int sy, int ex, int ey, int dx, int dy)
{ {
int width; int width;
int height; int height;
void *buf; void *buf = NULL;
CIOLIB_INIT(); CIOLIB_INIT();
if(cio_api.movetext != NULL) if (cio_api.movetext != NULL)
return(cio_api.movetext(sx, sy, ex, ey, dx, dy)); return cio_api.movetext(sx, sy, ex, ey, dx, dy);
width=ex-sx; width = ex - sx;
height=ey-sy; height = ey - sy;
if (cio_api.vmem_gettext) { if (cio_api.vmem_gettext != NULL) {
buf=malloc((width+1)*(height+1)*sizeof(struct vmem_cell)); buf = malloc((width + 1) * (height + 1) * sizeof(struct vmem_cell));
if (buf == NULL) if (buf == NULL)
return 0;
if(!ciolib_vmem_gettext(sx,sy,ex,ey,buf))
goto fail; goto fail;
if(!ciolib_vmem_puttext(dx,dy,dx+width,dy+height,buf)) if (ciolib_vmem_gettext(sx, sy, ex, ey, buf) == 0)
goto fail;
if (ciolib_vmem_puttext(dx, dy, dx+width, dy+height, buf) == 0)
goto fail; goto fail;
} }
else { else {
buf=malloc((width+1)*(height+1)*2); buf = malloc((width + 1) * (height + 1) * 2);
if (buf == NULL) if (buf == NULL)
return 0;
if(!ciolib_gettext(sx,sy,ex,ey,buf))
goto fail; goto fail;
if(!ciolib_puttext(dx,dy,dx+width,dy+height,buf)) if (ciolib_gettext(sx, sy, ex, ey, buf) == 0)
goto fail;
if (ciolib_puttext(dx, dy, dx + width, dy + height, buf) == 0)
goto fail; goto fail;
} }
free(buf);
return(1); return(1);
fail: fail:
...@@ -1169,14 +1169,9 @@ CIOLIBEXPORT void ciolib_normvideo(void) ...@@ -1169,14 +1169,9 @@ CIOLIBEXPORT void ciolib_normvideo(void)
*/ */
CIOLIBEXPORT int ciolib_puttext(int a,int b,int c,int d,void *e) CIOLIBEXPORT int ciolib_puttext(int a,int b,int c,int d,void *e)
{ {
char *buf=e;
int ret;
CIOLIB_INIT(); CIOLIB_INIT();
ret = cio_api.puttext(a,b,c,d,(void *)buf); return cio_api.puttext(a, b, c, d, (void *)buf);
if (buf != e)
free(buf);
return ret;
} }
/* **MUST** be implemented */ /* **MUST** be implemented */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment