I'm not terribly familiar with the uthash library, but it looks like the way UT_string is being used is leaking memory in several locations. For example, there are a number of places that call ustring_new and never call ustring_free to free the underlying struct:
So, it seems like all of these locations should dupe the char* returned from ustring_body so that the actual UT_string can be freed using ustring_free before the function returns.
I'm not terribly familiar with the uthash library, but it looks like the way
UT_string
is being used is leaking memory in several locations. For example, there are a number of places that callustring_new
and never callustring_free
to free the underlying struct:ustring_new
without ever callingustring_free
. The underlyingchar *
is returned to the caller and the actualUT_string
is left to leak memory. For example, in https://github.com/gjtorikian/mtex2MML/blob/a9b1517f46dfda7922e2d2d955c95f23c22b5c5f/src/parse_extras.c#L286 the underlyingchar *
is returned to the caller. The caller then frees that string in https://github.com/gjtorikian/mtex2MML/blob/a9b1517f46dfda7922e2d2d955c95f23c22b5c5f/src/mtex2MML.y#L2514. But, that doesn't free the entireUT_string
struct. The actual struct is composed of the underlyingchar *
data as well as some additional metadata: https://github.com/gjtorikian/mtex2MML/blob/a9b1517f46dfda7922e2d2d955c95f23c22b5c5f/src/deps/uthash/utstring.h#L43-L47.ustring_free
makes sure to free thechar *
as well as the memory allocated for the struct itself.ustring_new
withoutustring_free
. This one does a dupe, so it should be safe to free the original string.usring_new
withoutustring_free
. This one is similar to the original example, where the underlingchar *
is returned without ever deleting the originalUT_string
.So, it seems like all of these locations should dupe the
char*
returned fromustring_body
so that the actualUT_string
can be freed usingustring_free
before the function returns.