Skip to content

Commit 25e079a

Browse files
committed
lazy alloc
1 parent 266b8c4 commit 25e079a

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

Modules/_remote_debugging/binary_io_writer.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -522,13 +522,6 @@ writer_get_or_create_thread_entry(BinaryWriter *writer, uint64_t thread_id,
522522
return NULL;
523523
}
524524

525-
entry->pending_rle = PyMem_Malloc(MAX_RLE_BUF_SIZE);
526-
if (!entry->pending_rle) {
527-
PyMem_Free(entry->prev_stack);
528-
PyErr_NoMemory();
529-
return NULL;
530-
}
531-
532525
writer->thread_count++;
533526
if (is_new) {
534527
*is_new = 1;
@@ -994,6 +987,13 @@ process_thread_sample(BinaryWriter *writer, PyObject *thread_info,
994987
* STACK_REPEAT against an empty curr_stack (depth 0). Buffering
995988
* it here is correct; the RLE flush path emits it as a normal
996989
* STACK_REPEAT record. */
990+
if (entry->pending_rle == NULL) {
991+
entry->pending_rle = PyMem_Malloc(MAX_RLE_BUF_SIZE);
992+
if (!entry->pending_rle) {
993+
PyErr_NoMemory();
994+
return -1;
995+
}
996+
}
997997
if (entry->pending_rle_bytes + MAX_RLE_ENTRY_SIZE > MAX_RLE_BUF_SIZE
998998
&& flush_pending_rle(writer, entry) < 0) {
999999
return -1;

0 commit comments

Comments
 (0)