You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
art(11490,0x7000070ec000) malloc: *** error for object 0x10fcb0efc: pointer being freed was not allocated
dart(11490,0x7000070ec000) malloc: *** set a breakpoint in malloc_error_break to debug
I guess the error occurs when the function returns an empty string(password = "";) and I try to free memory.(for strings without malloc)
How can I understand when I need to free up memory, and when not?(password = conn->pgpass; with malloc)
then you could just check in dart if the pointer equals nullptr and only free if it does not.
Note that is perfectly possible to free "" if it is actually allocated in the program. "" will still be 1 byte long, and contain the termination byte as first byte, which still needs to be freed when allocated. However, in your code the "" will be a constant which is part of your compiled program and cannot be freed at runtime.
I completely missed that this is the Postgres API (thanks @mraleph for pointing that out)!
When using an existing library, the existing library has a policy about its resource management. The postgres documentation on the function does not mention resource management at all: https://www.postgresql.org/docs/12/libpq-status.html. However, given that the implementation directly returns conn->connhost[conn->whichhost].password without any copying, freeing that value would likely lead to undefined behavior as well. So I'd infer from this that the callee never has to free a string returned from this function.
I am facing a problem when working with strings. For example:
https://github.com/postgres/postgres/blob/8a15e735be00f156a7227741c0ce88702e6de099/src/interfaces/libpq/fe-connect.c#L6535
when I use dart-lang/native#508
I get an error
I guess the error occurs when the function returns an empty string(
password = "";
) and I try to free memory.(for strings withoutmalloc
)How can I understand when I need to free up memory, and when not?(
password = conn->pgpass;
withmalloc
)Originally posted by @listepo in #34452 (comment)
@dcharkes can you help me? thanks in advance
The text was updated successfully, but these errors were encountered: