File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -685,7 +685,11 @@ PyObject_Malloc(size_t nbytes)
685685 * last chance to serve the request) or when the max memory limit
686686 * has been reached.
687687 */
688- return (void * )malloc (nbytes ? nbytes : 1 );
688+ #ifdef MALLOC_ZERO_RETURNS_NULL
689+ if (nbytes == 0 )
690+ nbytes = 1 ;
691+ #endif
692+ return (void * )malloc (nbytes );
689693}
690694
691695/* free */
@@ -803,7 +807,10 @@ PyObject_Realloc(void *p, size_t nbytes)
803807 }
804808 /* We're not managing this block. */
805809 if (nbytes <= SMALL_REQUEST_THRESHOLD ) {
806- /* Take over this block. */
810+ /* Take over this block -- ask for at least one byte so
811+ * we really do take it over (PyObject_Malloc(0) goes to
812+ * the system malloc).
813+ */
807814 bp = PyObject_Malloc (nbytes ? nbytes : 1 );
808815 if (bp != NULL ) {
809816 memcpy (bp , p , nbytes );
You can’t perform that action at this time.
0 commit comments