Skip to content

Commit

Permalink
Fix leak in _PyCode_Update (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
iritkatriel authored Jul 26, 2021
1 parent 2c31f5d commit 41cf743
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def _write_atomic(path, data, mode=0o666):
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
# in PC/launcher.c must also be updated.

MAGIC_NUMBER = (9994).to_bytes(2, 'little') + b'\r\n'
MAGIC_NUMBER = (9996).to_bytes(2, 'little') + b'\r\n'
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c

_PYCACHE = '__pycache__'
Expand Down
11 changes: 10 additions & 1 deletion Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ init_code(PyCodeObject *co, struct _PyCodeConstructor *con)
co->co_name = con->name;
Py_INCREF(con->qualname);
co->co_qualname = con->qualname;

co->co_flags = con->flags;

Py_XINCREF(con->code);
Expand Down Expand Up @@ -420,6 +421,10 @@ _PyCode_New(struct _PyCodeConstructor *con)
PyErr_NoMemory();
return NULL;
}
co->co_filename = NULL;
co->co_name = NULL;
co->co_qualname = NULL;

init_code(co, con);

return co;
Expand All @@ -442,7 +447,11 @@ _PyCode_Update(struct _PyCodeConstructor *con, PyCodeObject *code)
con->columntable = Py_None;
}

init_code(code, con); // TODO: This leaks!
Py_XDECREF(code->co_filename);
Py_XDECREF(code->co_name);
Py_XDECREF(code->co_qualname);

init_code(code, con);

return code;
}
Expand Down
2 changes: 1 addition & 1 deletion Python/importlib_external.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 41cf743

Please sign in to comment.