PATCH: pyparted: Free c-strings on dealloc too
In a couple of places we store strdup-ed C-strings in our python objects, free
these when the python objects get destroyed. --- src/pydevice.c | 3 +++ src/pydisk.c | 1 + src/pyfilesys.c | 1 + src/pytimer.c | 20 ++++++++++++++++++++ 4 files changed, 25 insertions(+), 0 deletions(-) diff --git a/src/pydevice.c b/src/pydevice.c index f138271..e144096 100644 --- a/src/pydevice.c +++ b/src/pydevice.c @@ -68,6 +68,9 @@ PyObject *_ped_CHSGeometry_get(_ped_CHSGeometry *self, void *closure) { void _ped_Device_dealloc(_ped_Device *self) { PyObject_GC_UnTrack(self); + free(self->model); + free(self->path); + Py_CLEAR(self->hw_geom); self->hw_geom = NULL; diff --git a/src/pydisk.c b/src/pydisk.c index c1c3228..27b8d95 100644 --- a/src/pydisk.c +++ b/src/pydisk.c @@ -287,6 +287,7 @@ int _ped_Disk_init(_ped_Disk *self, PyObject *args, PyObject *kwds) { /* _ped.DiskType functions */ void _ped_DiskType_dealloc(_ped_DiskType *self) { PyObject_GC_UnTrack(self); + free(self->name); PyObject_GC_Del(self); } diff --git a/src/pyfilesys.c b/src/pyfilesys.c index 6923bd6..b184612 100644 --- a/src/pyfilesys.c +++ b/src/pyfilesys.c @@ -34,6 +34,7 @@ /* _ped.FileSystemType functions */ void _ped_FileSystemType_dealloc(_ped_FileSystemType *self) { PyObject_GC_UnTrack(self); + free(self->name); PyObject_GC_Del(self); } diff --git a/src/pytimer.c b/src/pytimer.c index 57fca34..2880a2a 100644 --- a/src/pytimer.c +++ b/src/pytimer.c @@ -31,6 +31,7 @@ /* _ped.Timer functions */ void _ped_Timer_dealloc(_ped_Timer *self) { PyObject_GC_UnTrack(self); + free(self->state_name); PyObject_GC_Del(self); } @@ -64,6 +65,16 @@ int _ped_Timer_init(_ped_Timer *self, PyObject *args, PyObject *kwds) { return -2; } + /* self->state_name now points to the internal buffer of a PyString object, + which may be freed when its refcount drops to zero, so strdup it. */ + if (self->state_name) { + self->state_name = strdup(self->state_name); + if (!self->state_name) { + PyErr_NoMemory(); + return -3; + } + } + return 0; } @@ -123,6 +134,15 @@ int _ped_Timer_set(_ped_Timer *self, PyObject *value, void *closure) { if (PyErr_Occurred()) { return -1; } + /* self->state_name now points to the internal buffer of a PyString obj + which may be freed when its refcount drops to zero, so strdup it. */ + if (self->state_name) { + self->state_name = strdup(self->state_name); + if (!self->state_name) { + PyErr_NoMemory(); + return -2; + } + } } else { PyErr_Format(PyExc_AttributeError, "_ped.Timer object has no attribute %s", member); return -1; -- 1.6.1.3 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@redhat.com https://www.redhat.com/mailman/listinfo/anaconda-devel-list |
PATCH: pyparted: Free c-strings on dealloc too
> In a couple of places we store strdup-ed C-strings in our python objects, free
> these when the python objects get destroyed. > --- > src/pydevice.c | 3 +++ > src/pydisk.c | 1 + > src/pyfilesys.c | 1 + > src/pytimer.c | 20 ++++++++++++++++++++ > 4 files changed, 25 insertions(+), 0 deletions(-) This looks fine, though I'd still rather kill pytimer.c than do anything to it. We've been waffling on keeping it or not, and I'm strongly on the side of not. I'll apply, push, etc. Thanks for the patch. - Chris _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@redhat.com https://www.redhat.com/mailman/listinfo/anaconda-devel-list |
| All times are GMT. The time now is 06:35 AM. |
VBulletin, Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.