diff options
author | Tom Tromey <tromey@adacore.com> | 2023-06-29 07:10:40 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2023-07-03 11:35:18 -0600 |
commit | 9dbbe5c948f5adcf7097339337db74d5548b63d0 (patch) | |
tree | 846fd10ca73ef1b2cc5796d9e07020217ec4026d /gdb/python | |
parent | 087969169836f802a09b1cd0502d2f22d7a8f7dc (diff) | |
download | gdb-9dbbe5c948f5adcf7097339337db74d5548b63d0.zip gdb-9dbbe5c948f5adcf7097339337db74d5548b63d0.tar.gz gdb-9dbbe5c948f5adcf7097339337db74d5548b63d0.tar.bz2 |
Fix two Python calls that don't check for errors
PyModule_AddObject steals a reference on success, but not on error,
which is why we have gdb_pymodule_addobject. I found one spot still
calling the former, which could in theory leak memory on failure.
This patch fixes this.
In the same function I found an unchecked call to
PyDict_SetItemString. This patch fixes this as well.
Approved-By: Andrew Burgess <aburgess@redhat.com>
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-disasm.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/gdb/python/py-disasm.c b/gdb/python/py-disasm.c index 0af089f..6f0fed1 100644 --- a/gdb/python/py-disasm.c +++ b/gdb/python/py-disasm.c @@ -1647,11 +1647,15 @@ gdbpy_initialize_disasm () gdb_disassembler_module = PyModule_Create (&python_disassembler_module_def); if (gdb_disassembler_module == nullptr) return -1; - PyModule_AddObject(gdb_module, "disassembler", gdb_disassembler_module); + if (gdb_pymodule_addobject (gdb_module, "disassembler", + gdb_disassembler_module) < 0) + return -1; /* This is needed so that 'import _gdb.disassembler' will work. */ PyObject *dict = PyImport_GetModuleDict (); - PyDict_SetItemString (dict, "_gdb.disassembler", gdb_disassembler_module); + if (PyDict_SetItemString (dict, "_gdb.disassembler", + gdb_disassembler_module) < 0) + return -1; for (int i = 0; i <= (int) dis_style_comment_start; ++i) { |