| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -227,6 +227,14 @@ do { \ | |||
| 227 | 227 | return err; \ | |
| 228 | 228 | } \ | |
| 229 | 229 | } while (0) | |
| 230 | + #define CHECK_VALID_OR_RELEASE(err, buffer) \ | ||
| 231 | + do { \ | ||
| 232 | + if (self->map_handle == NULL) { \ | ||
| 233 | + PyErr_SetString(PyExc_ValueError, "mmap closed or invalid"); \ | ||
| 234 | + PyBuffer_Release(&(buffer)); \ | ||
| 235 | + return (err); \ | ||
| 236 | + } \ | ||
| 237 | + } while (0) | ||
| 230 | 238 | #endif /* MS_WINDOWS */ | |
| 231 | 239 | ||
| 232 | 240 | #ifdef UNIX | |
@@ -237,6 +245,14 @@ do { \ | |||
| 237 | 245 | return err; \ | |
| 238 | 246 | } \ | |
| 239 | 247 | } while (0) | |
| 248 | + #define CHECK_VALID_OR_RELEASE(err, buffer) \ | ||
| 249 | + do { \ | ||
| 250 | + if (self->data == NULL) { \ | ||
| 251 | + PyErr_SetString(PyExc_ValueError, "mmap closed or invalid"); \ | ||
| 252 | + PyBuffer_Release(&(buffer)); \ | ||
| 253 | + return (err); \ | ||
| 254 | + } \ | ||
| 255 | + } while (0) | ||
| 240 | 256 | #endif /* UNIX */ | |
| 241 | 257 | ||
| 242 | 258 | static PyObject * | |
@@ -326,7 +342,7 @@ mmap_gfind(mmap_object *self, | |||
| 326 | 342 | end = self->size; | |
| 327 | 343 | ||
| 328 | 344 | Py_ssize_t res; | |
| 329 | - CHECK_VALID(NULL); | ||
| 345 | + CHECK_VALID_OR_RELEASE(NULL, view); | ||
| 330 | 346 | if (reverse) { | |
| 331 | 347 | res = _PyBytes_ReverseFind( | |
| 332 | 348 | self->data + start, end - start, | |
@@ -403,7 +419,7 @@ mmap_write_method(mmap_object *self, | |||
| 403 | 419 | return NULL; | |
| 404 | 420 | } | |
| 405 | 421 | ||
| 406 | - CHECK_VALID(NULL); | ||
| 422 | + CHECK_VALID_OR_RELEASE(NULL, data); | ||
| 407 | 423 | memcpy(&self->data[self->pos], data.buf, data.len); | |
| 408 | 424 | self->pos += data.len; | |
| 409 | 425 | PyBuffer_Release(&data); | |
@@ -1087,7 +1103,7 @@ mmap_ass_subscript(mmap_object *self, PyObject *item, PyObject *value) | |||
| 1087 | 1103 | return -1; | |
| 1088 | 1104 | } | |
| 1089 | 1105 | ||
| 1090 | - CHECK_VALID(-1); | ||
| 1106 | + CHECK_VALID_OR_RELEASE(-1, vbuf); | ||
| 1091 | 1107 | if (slicelen == 0) { | |
| 1092 | 1108 | } | |
| 1093 | 1109 | else if (step == 1) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments