stream: Copy on stream_init_string
Just safer!
This commit is contained in:
5
stream.c
5
stream.c
@@ -12,6 +12,7 @@
|
|||||||
* Description: Stream implementation
|
* Description: Stream implementation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "./alisp.h"
|
#include "./alisp.h"
|
||||||
@@ -25,7 +26,7 @@ stream_err_t stream_init_string(stream_t *stream, char *name, sv_t contents)
|
|||||||
|
|
||||||
stream->type = STREAM_TYPE_STRING;
|
stream->type = STREAM_TYPE_STRING;
|
||||||
stream->name = name;
|
stream->name = name;
|
||||||
stream->string = contents;
|
stream->string = sv_copy(contents);
|
||||||
|
|
||||||
return STREAM_ERR_OK;
|
return STREAM_ERR_OK;
|
||||||
}
|
}
|
||||||
@@ -69,7 +70,7 @@ void stream_stop(stream_t *stream)
|
|||||||
switch (stream->type)
|
switch (stream->type)
|
||||||
{
|
{
|
||||||
case STREAM_TYPE_STRING:
|
case STREAM_TYPE_STRING:
|
||||||
// Nothing to do, all dealt with outside of stream
|
free(stream->string.data);
|
||||||
break;
|
break;
|
||||||
case STREAM_TYPE_PIPE:
|
case STREAM_TYPE_PIPE:
|
||||||
case STREAM_TYPE_FILE:
|
case STREAM_TYPE_FILE:
|
||||||
|
|||||||
Reference in New Issue
Block a user