Armin Rigo avatar Armin Rigo committed 79fa6ad

(iko, rguillebert, arigo)

Fix interp_locale to call charp2str() before freeing some apparently
unrelated string, because the string may turn out to not be unrelated
after all.

Comments (0)

Files changed (2)

lib_pypy/_locale.py

 # ctypes implementation of _locale module by Victor Stinner, 2008-03-27
+
+# ------------------------------------------------------------
+#  Note that we also have our own interp-level implementation
+# ------------------------------------------------------------
+
 """
 Support for POSIX locales.
 """

pypy/module/_locale/interp_locale.py

             msg_c = rffi.str2charp(msg)
             try:
                 result = _dgettext(domain, msg_c)
+                # note that 'result' may be the same pointer as 'msg_c',
+                # so it must be converted to an RPython string *before*
+                # we free msg_c.
+                result = rffi.charp2str(result)
             finally:
                 rffi.free_charp(msg_c)
         else:
             msg_c = rffi.str2charp(msg)
             try:
                 result = _dgettext(domain_c, msg_c)
+                # note that 'result' may be the same pointer as 'msg_c',
+                # so it must be converted to an RPython string *before*
+                # we free msg_c.
+                result = rffi.charp2str(result)
             finally:
                 rffi.free_charp(domain_c)
                 rffi.free_charp(msg_c)
 
-        return space.wrap(rffi.charp2str(result))
+        return space.wrap(result)
 
     _dcgettext = rlocale.external('dcgettext', [rffi.CCHARP, rffi.CCHARP, rffi.INT],
                                                                 rffi.CCHARP)
             msg_c = rffi.str2charp(msg)
             try:
                 result = _dcgettext(domain, msg_c, rffi.cast(rffi.INT, category))
+                # note that 'result' may be the same pointer as 'msg_c',
+                # so it must be converted to an RPython string *before*
+                # we free msg_c.
+                result = rffi.charp2str(result)
             finally:
                 rffi.free_charp(msg_c)
         else:
             try:
                 result = _dcgettext(domain_c, msg_c,
                                     rffi.cast(rffi.INT, category))
+                # note that 'result' may be the same pointer as 'msg_c',
+                # so it must be converted to an RPython string *before*
+                # we free msg_c.
+                result = rffi.charp2str(result)
             finally:
                 rffi.free_charp(domain_c)
                 rffi.free_charp(msg_c)
 
-        return space.wrap(rffi.charp2str(result))
+        return space.wrap(result)
 
 
     _textdomain = rlocale.external('textdomain', [rffi.CCHARP], rffi.CCHARP)
         if space.is_w(w_domain, space.w_None):
             domain = None
             result = _textdomain(domain)
+            result = rffi.charp2str(result)
         else:
             domain = space.str_w(w_domain)
             domain_c = rffi.str2charp(domain)
             try:
                 result = _textdomain(domain_c)
+                # note that 'result' may be the same pointer as 'domain_c'
+                # (maybe?) so it must be converted to an RPython string
+                # *before* we free domain_c.
+                result = rffi.charp2str(result)
             finally:
                 rffi.free_charp(domain_c)
 
-        return space.wrap(rffi.charp2str(result))
+        return space.wrap(result)
 
     _bindtextdomain = rlocale.external('bindtextdomain', [rffi.CCHARP, rffi.CCHARP],
                                                                 rffi.CCHARP)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.