memory-stream: Add memory_stream_cleanup helper

Signed-off-by: Joshua Ashton <joshua@froggi.es>
This commit is contained in:
Joshua Ashton 2022-11-17 11:37:54 +00:00 committed by Pekka Paalanen
parent a10c478558
commit c63ca40ef7
2 changed files with 14 additions and 0 deletions

View file

@ -21,4 +21,12 @@ memory_stream_open(struct memory_stream *m);
char * char *
memory_stream_close(struct memory_stream *m); memory_stream_close(struct memory_stream *m);
/**
* A small cleanup helper that simply
* calls free(memory_stream_close(m)) to avoid
* any dangling string pointers in cleanup/error paths.
*/
void
memory_stream_cleanup(struct memory_stream *m);
#endif #endif

View file

@ -28,3 +28,9 @@ memory_stream_close(struct memory_stream *m)
return str; return str;
} }
void
memory_stream_cleanup(struct memory_stream *m)
{
free(memory_stream_close(m));
}