Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[3.14] gh-132983: Call Py_XDECREF rather than PyObject_GC_Del in failed __new__ (GH-133962)#134305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-132983: Call Py_XDECREF rather than PyObject_GC_Del in failed __ne…
…w__ (GH-133962)Call Py_XDECREF rather than PyObject_GC_Del in failed __new__This will call tp_dealloc and clear all members.(cherry picked from commite575190)Co-authored-by: Petr Viktorin <encukou@gmail.com>
  • Loading branch information
@encukou@miss-islington
encukou authored andmiss-islington committedMay 20, 2025
commit821665055fbdf15c94021601a2ba94a08bc7afb3
10 changes: 5 additions & 5 deletionsModules/_zstd/compressor.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -338,6 +338,7 @@ _zstd_ZstdCompressor_new_impl(PyTypeObject *type, PyObject *level,
}

self->use_multithread = 0;
self->dict = NULL;

/* Compression context */
self->cctx = ZSTD_createCCtx();
Expand DownExpand Up@@ -372,7 +373,6 @@ _zstd_ZstdCompressor_new_impl(PyTypeObject *type, PyObject *level,
}

/* Load Zstandard dictionary to compression context */
self->dict = NULL;
if (zstd_dict != Py_None) {
if (_zstd_load_c_dict(self, zstd_dict) < 0) {
goto error;
Expand All@@ -387,9 +387,7 @@ _zstd_ZstdCompressor_new_impl(PyTypeObject *type, PyObject *level,
return (PyObject*)self;

error:
if (self != NULL) {
PyObject_GC_Del(self);
}
Py_XDECREF(self);
return NULL;
}

Expand All@@ -401,7 +399,9 @@ ZstdCompressor_dealloc(PyObject *ob)
PyObject_GC_UnTrack(self);

/* Free compression context */
ZSTD_freeCCtx(self->cctx);
if (self->cctx) {
ZSTD_freeCCtx(self->cctx);
}

/* Py_XDECREF the dict after free the compression context */
Py_CLEAR(self->dict);
Expand Down
10 changes: 5 additions & 5 deletionsModules/_zstd/decompressor.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -554,6 +554,7 @@ _zstd_ZstdDecompressor_new_impl(PyTypeObject *type, PyObject *zstd_dict,
self->in_end = -1;
self->unused_data = NULL;
self->eof = 0;
self->dict = NULL;

/* needs_input flag */
self->needs_input = 1;
Expand All@@ -570,7 +571,6 @@ _zstd_ZstdDecompressor_new_impl(PyTypeObject *type, PyObject *zstd_dict,
}

/* Load Zstandard dictionary to decompression context */
self->dict = NULL;
if (zstd_dict != Py_None) {
if (_zstd_load_d_dict(self, zstd_dict) < 0) {
goto error;
Expand All@@ -592,9 +592,7 @@ _zstd_ZstdDecompressor_new_impl(PyTypeObject *type, PyObject *zstd_dict,
return (PyObject*)self;

error:
if (self != NULL) {
PyObject_GC_Del(self);
}
Py_XDECREF(self);
return NULL;
}

Expand All@@ -606,7 +604,9 @@ ZstdDecompressor_dealloc(PyObject *ob)
PyObject_GC_UnTrack(self);

/* Free decompression context */
ZSTD_freeDCtx(self->dctx);
if (self->dctx) {
ZSTD_freeDCtx(self->dctx);
}

/* Py_CLEAR the dict after free decompression context */
Py_CLEAR(self->dict);
Expand Down
9 changes: 5 additions & 4 deletionsModules/_zstd/zstddict.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -52,6 +52,7 @@ _zstd_ZstdDict_new_impl(PyTypeObject *type, PyObject *dict_content,

self->dict_content = NULL;
self->d_dict = NULL;
self->dict_id = 0;

/* ZSTD_CDict dict */
self->c_dicts = PyDict_New();
Expand DownExpand Up@@ -92,9 +93,7 @@ _zstd_ZstdDict_new_impl(PyTypeObject *type, PyObject *dict_content,
return (PyObject*)self;

error:
if (self != NULL) {
PyObject_GC_Del(self);
}
Py_XDECREF(self);
return NULL;
}

Expand All@@ -106,7 +105,9 @@ ZstdDict_dealloc(PyObject *ob)
PyObject_GC_UnTrack(self);

/* Free ZSTD_DDict instance */
ZSTD_freeDDict(self->d_dict);
if (self->d_dict) {
ZSTD_freeDDict(self->d_dict);
}

/* Release dict_content after Free ZSTD_CDict/ZSTD_DDict instances */
Py_CLEAR(self->dict_content);
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp