bug-gettext
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-gettext] [PATCH 2/6] Fix memory leak: do not duplicate msgid_plural


From: Alexander Potashev
Subject: [bug-gettext] [PATCH 2/6] Fix memory leak: do not duplicate msgid_plural in message_alloc
Date: Sat, 24 Aug 2013 20:55:19 +0400

---
 gettext-tools/src/message.c  | 5 +++--
 gettext-tools/src/msgmerge.c | 3 ++-
 gettext-tools/src/read-mo.c  | 4 ++--
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/gettext-tools/src/message.c b/gettext-tools/src/message.c
index 586675f..51360b4 100644
--- a/gettext-tools/src/message.c
+++ b/gettext-tools/src/message.c
@@ -116,7 +116,7 @@ message_alloc (const char *msgctxt,
   mp = XMALLOC (message_ty);
   mp->msgctxt = msgctxt;
   mp->msgid = msgid;
-  mp->msgid_plural = (msgid_plural != NULL ? xstrdup (msgid_plural) : NULL);
+  mp->msgid_plural = msgid_plural;
   mp->msgstr = msgstr;
   mp->msgstr_len = msgstr_len;
   mp->pos = *pp;
@@ -217,7 +217,8 @@ message_copy (message_ty *mp)
   size_t j, i;
 
   result = message_alloc (mp->msgctxt != NULL ? xstrdup (mp->msgctxt) : NULL,
-                          xstrdup (mp->msgid), mp->msgid_plural,
+                          xstrdup (mp->msgid),
+                          mp->msgid_plural != NULL ? xstrdup 
(mp->msgid_plural) : NULL,
                           mp->msgstr, mp->msgstr_len, &mp->pos);
 
   if (mp->comment)
diff --git a/gettext-tools/src/msgmerge.c b/gettext-tools/src/msgmerge.c
index 3f96d3e..8cc3520 100644
--- a/gettext-tools/src/msgmerge.c
+++ b/gettext-tools/src/msgmerge.c
@@ -1244,7 +1244,8 @@ message_merge (message_ty *def, message_ty *ref, bool 
force_fuzzy,
     }
 
   result = message_alloc (ref->msgctxt != NULL ? xstrdup (ref->msgctxt) : NULL,
-                          xstrdup (ref->msgid), ref->msgid_plural,
+                          xstrdup (ref->msgid),
+                          ref->msgid_plural != NULL ? xstrdup 
(ref->msgid_plural) : NULL,
                           msgstr, msgstr_len, &def->pos);
 
   /* Take the comments from the definition file.  There will be none at
diff --git a/gettext-tools/src/read-mo.c b/gettext-tools/src/read-mo.c
index 9e0220c..946e91d 100644
--- a/gettext-tools/src/read-mo.c
+++ b/gettext-tools/src/read-mo.c
@@ -323,7 +323,7 @@ read_mo_file (message_list_ty *mlp, const char *filename)
           mp = message_alloc (msgctxt,
                               msgid,
                               (strlen (msgid) + 1 < msgid_len
-                               ? msgid + strlen (msgid) + 1
+                               ? xstrdup (msgid + strlen (msgid) + 1)
                                : NULL),
                               msgstr, msgstr_len,
                               &pos);
@@ -381,7 +381,7 @@ read_mo_file (message_list_ty *mlp, const char *filename)
               mp = message_alloc (msgctxt,
                                   msgid,
                                   (strlen (msgid) + 1 < msgid_len
-                                   ? msgid + strlen (msgid) + 1
+                                   ? xstrdup (msgid + strlen (msgid) + 1)
                                    : NULL),
                                   msgstr, msgstr_len,
                                   &pos);
-- 
1.8.1.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]