[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-smalltalk] memleak from _gst_make_string_constant?
From: |
Holger Hans Peter Freyther |
Subject: |
[Help-smalltalk] memleak from _gst_make_string_constant? |
Date: |
Sun, 9 Feb 2014 19:58:22 +0100 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Hi,
I was starting to debug a GTK/gst-sunit issue and started to use
valgrind and noticed that there are some memory leaks in the code.
The only part I am not comfortable with is the obstack_copy0 part
as I have never used that API.
The only "leaks/reachable" left are from with-in gst_initialize.
Comments?
holger
diff --git a/libgst/input.c b/libgst/input.c
index 62cdc8b..9872a50 100644
--- a/libgst/input.c
+++ b/libgst/input.c
@@ -106,6 +106,7 @@ typedef struct input_stream
const char *prompt;
OOP fileOOP; /* the object stored in FileSegments */
+ mst_Boolean freeFileName;
const char *fileName;
off_t fileOffset;
@@ -240,6 +241,8 @@ _gst_pop_stream (mst_Boolean closeIt)
break;
}
+ if (stream->freeFileName)
+ xfree ((char *) stream->fileName);
xfree (stream);
}
@@ -335,6 +338,7 @@ push_new_stream (stream_type type)
newStream->column = 0;
newStream->fileOffset = -1;
newStream->type = type;
+ newStream->freeFileName = false;
newStream->fileName = NULL;
newStream->prompt = NULL;
newStream->fileOOP = _gst_nil_oop;
@@ -358,7 +362,10 @@ _gst_set_stream_info (int line,
in_stream->fileOffset = fileOffset;
if (!IS_NIL (fileNameOOP))
- in_stream->fileName = _gst_to_cstring (fileNameOOP);
+ {
+ in_stream->fileName = _gst_to_cstring (fileNameOOP);
+ in_stream->freeFileName = true;
+ }
}
void
@@ -407,7 +414,10 @@ my_getc (input_stream stream)
char *buf;
_gst_msg_sendf(&buf, "%s %o nextAvailable: %i", stream->st_oop.oop,
1024);
if (!buf || !*buf)
- return EOF;
+ {
+ xfree (buf);
+ return EOF;
+ }
refill_stream (stream, buf, false);
}
@@ -558,7 +568,7 @@ _gst_get_source_string (off_t startPos, off_t endPos)
OOP
get_cur_file (void)
{
- const char *fullFileName;
+ char *fullFileName;
if (!in_stream)
return _gst_nil_oop;
@@ -576,6 +586,7 @@ get_cur_file (void)
_gst_get_full_file_name (in_stream->fileName);
in_stream->fileOOP = _gst_string_new (fullFileName);
+ xfree (fullFileName);
_gst_register_oop (in_stream->fileOOP);
return (in_stream->fileOOP);
}
diff --git a/libgst/lex.c b/libgst/lex.c
index a8e230e..c16409b 100644
--- a/libgst/lex.c
+++ b/libgst/lex.c
@@ -645,7 +645,7 @@ scan_bin_op_1 (int c,
buf[1] = 0;
}
- lvalp->sval = xstrdup (buf);
+ lvalp->sval = obstack_copy0(_gst_compilation_obstack, buf, strlen(buf));
if ((buf[0] == '|' || buf[0] == '<' || buf[0] == '>' || buf[0] == '-')
&& buf[1] == '\0')
diff --git a/libgst/oop.h b/libgst/oop.h
index 76a5977..7e12aba 100644
--- a/libgst/oop.h
+++ b/libgst/oop.h
@@ -62,9 +62,9 @@
/* #define NO_SIGSEGV_HANDLING */
/* ... but always define it if libsigsegv does not support this platform. */
-#if !defined HAVE_SIGSEGV_RECOVERY || !(HAVE_SIGSEGV_RECOVERY-0)
+//#if !defined HAVE_SIGSEGV_RECOVERY || !(HAVE_SIGSEGV_RECOVERY-0)
#define NO_SIGSEGV_HANDLING
-#endif
+//#endif
#define NUM_CHAR_OBJECTS 256
#define NUM_BUILTIN_OBJECTS 3
diff --git a/libgst/prims.def b/libgst/prims.def
index 72add2b..a67c3fd 100644
--- a/libgst/prims.def
+++ b/libgst/prims.def
@@ -5326,6 +5326,7 @@ primitive VMpr_CFuncDescriptor_addressOf [succeed,fail]
{
char *funcName = (char *) _gst_to_cstring (oop1);
void *funcAddr = _gst_lookup_function (funcName);
+ xfree (funcName);
if (funcAddr)
{
POP_N_OOPS (1);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Help-smalltalk] memleak from _gst_make_string_constant?,
Holger Hans Peter Freyther <=