diff --git a/include/Mw/Core.h b/include/Mw/Core.h index bf1c6f0..37cbc9f 100644 --- a/include/Mw/Core.h +++ b/include/Mw/Core.h @@ -375,6 +375,14 @@ MWDECL void MWAPI MwSetUser(MwWidget handle, void* user); */ MWDECL void* MWAPI MwGetUser(MwWidget handle); +/*! + * @brief Free the widget + * @param handle Widget + * @warning This is used internally! + * @note You can call this on toplevel widget safely if you're sure no event loops will be ran, e.g. after `MwLoop`. + */ +MWDECL void MWAPI MwFreeWidget(MwWidget handle); + #ifdef _MILSKO MWDECL void MwForceRender_Internal(MwWidget handle); MWDECL void MwForceRender2_Internal(MwWidget handle, void* ptr); diff --git a/milsko.xml b/milsko.xml index c3d26b3..e5165a4 100644 --- a/milsko.xml +++ b/milsko.xml @@ -518,6 +518,25 @@ + + + + + + + + + + + + + + + + + + +
diff --git a/src/backend/x11.c b/src/backend/x11.c index b8f68f5..500ef7d 100644 --- a/src/backend/x11.c +++ b/src/backend/x11.c @@ -1164,6 +1164,9 @@ Cursor MwLLX11CreateCursor(Display* display, MwCursor* image, MwCursor* mask) { XDestroyImage(cimage); XDestroyImage(cmask); + XFreeGC(display, imagegc); + XFreeGC(display, maskgc); + return cur; } diff --git a/src/core.c b/src/core.c index e0c018f..0a125da 100644 --- a/src/core.c +++ b/src/core.c @@ -278,8 +278,10 @@ static MwWidget MwCreateWidget_Internal(MwClass widget_class, const char* name, } else #endif { - h->root_font = NULL; - h->root_boldfont = NULL; + h->root_font = NULL; + h->root_boldfont = NULL; + h->root_monofont = NULL; + h->root_boldmonofont = NULL; } if(h->parent != NULL) MwDispatch(h->parent, children_update); @@ -324,7 +326,7 @@ MwWidget MwVaListCreateWidget(MwClass widget_class, const char* name, MwWidget p return h; } -static void MwFreeWidget(MwWidget handle) { +void MwFreeWidget(MwWidget handle) { int i; MwWidget root = handle; MwWidget w; @@ -351,6 +353,7 @@ static void MwFreeWidget(MwWidget handle) { for(i = 0; i < arrlen(handle->children); i++) { MwFreeWidget(handle->children[i]); } + arrfree(handle->children); while(root->parent != NULL) root = root->parent; for(i = 0; i < arrlen(root->tick_list); i++) { @@ -384,6 +387,8 @@ static void MwFreeWidget(MwWidget handle) { if(handle->root_font != NULL) MwFontFree(handle->root_font); if(handle->root_boldfont != NULL) MwFontFree(handle->root_boldfont); + if(handle->root_monofont != NULL) MwFontFree(handle->root_monofont); + if(handle->root_boldmonofont != NULL) MwFontFree(handle->root_boldmonofont); free(handle); } diff --git a/src/widget/label.c b/src/widget/label.c index 29e63e9..64cfcbd 100644 --- a/src/widget/label.c +++ b/src/widget/label.c @@ -309,6 +309,8 @@ static void draw(MwWidget handle) { r.width = w; MwLLDrawPixmap(handle->lowlevel, &r, px); + free(raw); + MwLLDestroyPixmap(px); } else { r.width -= MwGetInteger(handle, MwNleftPadding); diff --git a/tools/fuzzer.c b/tools/fuzzer.c index b64ba1d..bacfd74 100644 --- a/tools/fuzzer.c +++ b/tools/fuzzer.c @@ -15,7 +15,7 @@ char* int_params[] = {/*MwNx, MwNy, MwNwidth, MwNheight,*/ MwNorientation, unsigned long maxxes[] = {UINT8_MAX, UINT16_MAX, UINT32_MAX, UINT64_MAX}; int main() { - int i; + int i, j = 0; char input; MwWidget window, widget; unsigned long upper_limit; @@ -49,14 +49,14 @@ get_input: window = MwCreateWidget(MwWindowClass, "window", NULL, 0, 0, 400, 400); - while(MwPending(window)) { + while(MwPending(window) && j < 50) { int class_num = rand() % (sizeof(classes) / sizeof(cls_pair_t)); widget = MwCreateWidget(*classes[class_num].cls, classes[class_num].name, window, 0, 0, 100, 100); printf("%s\n", classes[class_num].name); /* apply int params with random scale */ for(i = 0; i < (sizeof(int_params) / sizeof(void*)); i++) { - unsigned long number = rand() % UINT8_MAX; + unsigned long number = rand() % upper_limit; printf("> %s = %lu\n", int_params[i], number); MwVaApply(widget, int_params[i], number, NULL); } @@ -65,5 +65,9 @@ get_input: MwDestroyWidget(widget); printf("\n"); + + j++; } + + MwFreeWidget(window); }