diff --git a/caca/driver_network.c b/caca/driver_network.c index 8e2e8dd..0d2657e 100644 --- a/caca/driver_network.c +++ b/caca/driver_network.c @@ -167,7 +167,7 @@ static void network_display(caca_t *kk) { int size; char *to_send = cucul_get_ansi(kk->qq, 0, &size);; - to_send = realloc(to_send, kk->qq->width * kk->qq->height * 15 * 3); + /* ANSI code for move(0,0)*/ if (send(kk->drv.p->new_fd, "\033[1,1H", 6, 0) == -1) { @@ -179,10 +179,6 @@ static void network_display(caca_t *kk) perror("send"); return; } - - if(to_send) { - free(to_send); - } } static void network_handle_resize(caca_t *kk) diff --git a/cucul/cucul.c b/cucul/cucul.c index be69736..781580e 100644 --- a/cucul/cucul.c +++ b/cucul/cucul.c @@ -72,6 +72,8 @@ cucul_t * cucul_init(void) return NULL; } + qq->ansi_buffer = NULL; + return qq; } @@ -270,6 +272,9 @@ void cucul_end(cucul_t *qq) free(qq->chars); free(qq->attr); + if(qq->ansi_buffer) + free(qq->ansi_buffer); + free(qq); } diff --git a/cucul/cucul_internals.h b/cucul/cucul_internals.h index adb3bfa..3e33ce0 100644 --- a/cucul/cucul_internals.h +++ b/cucul/cucul_internals.h @@ -45,6 +45,10 @@ struct cucul_context enum cucul_feature background, antialiasing, dithering; unsigned int refcount; + + /* Exporters facilities */ + unsigned char *ansi_buffer; + }; /* Initialisation functions */ diff --git a/cucul/export.c b/cucul/export.c index 12d5d77..e5a7da0 100644 --- a/cucul/export.c +++ b/cucul/export.c @@ -275,13 +275,15 @@ char * cucul_get_ansi(cucul_t *qq, int trailing, int *size) 30, 34, 32, 36, 31, 35, 33, 37, /* light colors handling is done later */ }; - char *buffer, *cur; + char *cur; unsigned int x, y; /* 20 bytes assumed for max length per pixel. * Add height*9 to that (zeroes color at the end and jump to next line) */ - buffer = malloc(((qq->height*9) + (qq->width * qq->height * 20)) * sizeof(char)); - cur = buffer; + if(qq->ansi_buffer) + free(qq->ansi_buffer); + qq->ansi_buffer = malloc(((qq->height*9) + (qq->width * qq->height * 20)) * sizeof(char)); + cur = qq->ansi_buffer; // *cur++ = ''; @@ -321,9 +323,9 @@ char * cucul_get_ansi(cucul_t *qq, int trailing, int *size) } /* Crop to really used size */ - *size = (strlen(buffer) + 1)* sizeof(char); - buffer = realloc(buffer, *size); + *size = (strlen(qq->ansi_buffer) + 1)* sizeof(char); + qq->ansi_buffer = realloc(qq->ansi_buffer, *size); - return buffer; + return qq->ansi_buffer; }