[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-gettext] [PATCH 5/6] Fix memory leak: string_list_append duplicates
From: |
Alexander Potashev |
Subject: |
[bug-gettext] [PATCH 5/6] Fix memory leak: string_list_append duplicates the string |
Date: |
Sat, 24 Aug 2013 20:55:22 +0400 |
string_list_append works like before.
string_list_append_nodup works almost like string_list_append, but
takes ownership of the string passed into it, i.e. it does not run
xstrdup() unlike string_list_append.
---
gettext-tools/src/po-gram-gen.y | 8 ++++----
gettext-tools/src/str-list.c | 11 +++++++++--
gettext-tools/src/str-list.h | 2 ++
3 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/gettext-tools/src/po-gram-gen.y b/gettext-tools/src/po-gram-gen.y
index aba98a7..ea2ceb8 100644
--- a/gettext-tools/src/po-gram-gen.y
+++ b/gettext-tools/src/po-gram-gen.y
@@ -411,7 +411,7 @@ string_list
: STRING
{
string_list_init (&$$.stringlist);
- string_list_append (&$$.stringlist, $1.string);
+ string_list_append_nodup (&$$.stringlist, $1.string);
$$.pos = $1.pos;
$$.obsolete = $1.obsolete;
}
@@ -419,7 +419,7 @@ string_list
{
check_obsolete ($1, $2);
$$.stringlist = $1.stringlist;
- string_list_append (&$$.stringlist, $2.string);
+ string_list_append_nodup (&$$.stringlist, $2.string);
$$.pos = $1.pos;
$$.obsolete = $1.obsolete;
}
@@ -429,7 +429,7 @@ prev_string_list
: PREV_STRING
{
string_list_init (&$$.stringlist);
- string_list_append (&$$.stringlist, $1.string);
+ string_list_append_nodup (&$$.stringlist, $1.string);
$$.pos = $1.pos;
$$.obsolete = $1.obsolete;
}
@@ -437,7 +437,7 @@ prev_string_list
{
check_obsolete ($1, $2);
$$.stringlist = $1.stringlist;
- string_list_append (&$$.stringlist, $2.string);
+ string_list_append_nodup (&$$.stringlist, $2.string);
$$.pos = $1.pos;
$$.obsolete = $1.obsolete;
}
diff --git a/gettext-tools/src/str-list.c b/gettext-tools/src/str-list.c
index 3f929c2..f3c5b07 100644
--- a/gettext-tools/src/str-list.c
+++ b/gettext-tools/src/str-list.c
@@ -57,7 +57,7 @@ string_list_alloc ()
/* Append a single string to the end of a list of strings. */
void
-string_list_append (string_list_ty *slp, const char *s)
+string_list_append_nodup (string_list_ty *slp, const char *s)
{
/* Grow the list. */
if (slp->nitems >= slp->nitems_max)
@@ -70,7 +70,14 @@ string_list_append (string_list_ty *slp, const char *s)
}
/* Add a copy of the string to the end of the list. */
- slp->item[slp->nitems++] = xstrdup (s);
+ slp->item[slp->nitems++] = s;
+}
+
+
+void
+string_list_append (string_list_ty *slp, const char *s)
+{
+ string_list_append_nodup (slp, xstrdup (s));
}
diff --git a/gettext-tools/src/str-list.h b/gettext-tools/src/str-list.h
index 5b7b75d..1d40dbb 100644
--- a/gettext-tools/src/str-list.h
+++ b/gettext-tools/src/str-list.h
@@ -48,6 +48,8 @@ extern void string_list_init (string_list_ty *slp);
extern string_list_ty *string_list_alloc (void);
/* Append a single string to the end of a list of strings. */
+extern void string_list_append_nodup (string_list_ty *slp, const char *s);
+
extern void string_list_append (string_list_ty *slp, const char *s);
/* Append a single string to the end of a list of strings, unless it is
--
1.8.1.5
- [bug-gettext] [PATCH 0/6] Fix various memory leaks in libgettextpo, Alexander Potashev, 2013/08/24
- [bug-gettext] [PATCH 1/6] Copy string from shared buffer, Alexander Potashev, 2013/08/24
- [bug-gettext] [PATCH 2/6] Fix memory leak: do not duplicate msgid_plural in message_alloc, Alexander Potashev, 2013/08/24
- [bug-gettext] [PATCH 3/6] Fix memory leak: free msgctxt in message_free, Alexander Potashev, 2013/08/24
- [bug-gettext] [PATCH 4/6] Fix memory leak: po_callback_comment_dispatcher does not take ownership of the string passed into it, Alexander Potashev, 2013/08/24
- [bug-gettext] [PATCH 5/6] Fix memory leak: string_list_append duplicates the string,
Alexander Potashev <=
- [bug-gettext] [PATCH 6/6] Fix memory leak: free gram_pos.file_name in lex_end(), Alexander Potashev, 2013/08/24
- Re: [bug-gettext] [PATCH 0/6] Fix various memory leaks in libgettextpo, Daiki Ueno, 2013/08/27