diff --git a/include/memory-stream.h b/include/memory-stream.h index d14e48f..21dc03a 100644 --- a/include/memory-stream.h +++ b/include/memory-stream.h @@ -21,4 +21,12 @@ memory_stream_open(struct memory_stream *m); char * 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 diff --git a/memory-stream.c b/memory-stream.c index 571fc69..ba72eb1 100644 --- a/memory-stream.c +++ b/memory-stream.c @@ -28,3 +28,9 @@ memory_stream_close(struct memory_stream *m) return str; } + +void +memory_stream_cleanup(struct memory_stream *m) +{ + free(memory_stream_close(m)); +}