8000 Fix some memory issues · python/cpython@65542c4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 65542c4

Browse files
committed
Fix some memory issues
1 parent 9ac9101 commit 65542c4

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

Modules/_zstd/compressor.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ _zstd_ZstdCompressor_new(PyTypeObject *type, PyObject *Py_UNUSED(args), PyObject
304304
goto error;
305305
}
306306

307+
self->inited = 0;
308+
self->dict = NULL;
309+
self->use_multithread = 0;
310+
307311

308312
/* Compression context */
309313
self->cctx = ZSTD_createCCtx();
@@ -322,7 +326,9 @@ _zstd_ZstdCompressor_new(PyTypeObject *type, PyObject *Py_UNUSED(args), PyObject
322326
return (PyObject*)self;
323327

324328
error:
325-
PyObject_GC_UnTrack(self);
329+
if (self != NULL) {
330+
PyObject_GC_Del(self);
331+
}
326332
return NULL;
327333
}
328334

Modules/_zstd/decompressor.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,15 @@ _zstd_ZstdDecompressor_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
622622
goto error;
623623
}
624624

625+
self->inited = 0;
626+
self->dict = NULL;
627+
self->input_buffer = NULL;
628+
self->input_buffer_size = 0;
629+
self->in_begin = -1;
630+
self->in_end = -1;
631+
self->unused_data = NULL;
632+
self->eof = 0;
633+
625634
/* needs_input flag */
626635
self->needs_input = 1;
627636

@@ -642,7 +651,9 @@ _zstd_ZstdDecompressor_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
642651
return (PyObject*)self;
643652

644653
error:
645-
PyObject_GC_UnTrack(self);
654+
if (self != NULL) {
655+
PyObject_GC_Del(self);
656+
}
646657
return NULL;
647658
}
648659

Modules/_zstd/zdict.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@ static PyObject *
2525
_zstd_ZstdDict_new(PyTypeObject *type, PyObject *Py_UNUSED(args), PyObject *Py_UNUSED(kwargs))
2626
{
2727
ZstdDict *self;
28-
self = (ZstdDict*)type->tp_alloc(type, 0);
28+
self = PyObject_GC_New(ZstdDict, type);
2929
if (self == NULL) {
3030
goto error;
3131
}
3232

33+
self->dict_content = NULL;
34+
self->inited = 0;
35+
self->d_dict = NULL;
36+
3337
/* ZSTD_CDict dict */
3438
self->c_dicts = PyDict_New();
3539
if (self->c_dicts == NULL) {
@@ -39,7 +43,9 @@ _zstd_ZstdDict_new(PyTypeObject *type, PyObject *Py_UNUSED(args), PyObject *Py_U
3943
return (PyObject*)self;
4044

4145
error:
42-
PyObject_GC_UnTrack(self);
46+
if (self != NULL) {
47+
PyObject_GC_Del(self);
48+
}
4349
return NULL;
4450
}
4551

0 commit comments

Comments
 (0)
0