@@ -368,6 +368,9 @@ SoftimageInput::read_pixels_pure_run_length(
368368 size_t pixelChannelSize = curPacket.size / 8 ;
369369 // We're going to need to use the channels more than once
370370 std::vector<int > channels = curPacket.channels ();
371+ // Allocate space for a pixel to read into
372+ size_t pixelSize = pixelChannelSize * channels.size ();
373+ uint8_t * pixelData = OIIO_ALLOCA (uint8_t , pixelSize);
371374 // Read the pixels until we've read them all
372375 while (linePixelCount < m_pic_header.width ) {
373376 // Read the repeats for the run length - return false if read fails
@@ -386,8 +389,6 @@ SoftimageInput::read_pixels_pure_run_length(
386389
387390 if (data) {
388391 // data pointer is set so we're supposed to write data there
389- size_t pixelSize = pixelChannelSize * channels.size ();
390- uint8_t * pixelData = new uint8_t [pixelSize];
391392 if (fread (pixelData, 1 , pixelSize, m_fd) != pixelSize)
392393 return false ;
393394
@@ -412,7 +413,6 @@ SoftimageInput::read_pixels_pure_run_length(
412413 }
413414 }
414415 }
415- delete[] pixelData;
416416 } else {
417417 // data pointer is null so we should just seek to the next scanline
418418 // If the seek fails return false
@@ -440,6 +440,9 @@ SoftimageInput::read_pixels_mixed_run_length(
440440 size_t pixelChannelSize = curPacket.size / 8 ;
441441 // We're going to need to use the channels more than once
442442 std::vector<int > channels = curPacket.channels ();
443+ // Allocate space for a pixel to read into
444+ size_t pixelSize = pixelChannelSize * channels.size ();
445+ uint8_t * pixelData = OIIO_ALLOCA (uint8_t , pixelSize);
443446 // Read the pixels until we've read them all
444447 while (linePixelCount < m_pic_header.width ) {
445448 // Read the repeats for the run length - return false if read fails
@@ -520,8 +523,6 @@ SoftimageInput::read_pixels_mixed_run_length(
520523
521524 if (data) {
522525 // data pointer is set so we're supposed to write data there
523- size_t pixelSize = pixelChannelSize * channels.size ();
524- uint8_t * pixelData = new uint8_t [pixelSize];
525526 if (fread (pixelData, 1 , pixelSize, m_fd) != pixelSize)
526527 return false ;
527528
@@ -550,7 +551,6 @@ SoftimageInput::read_pixels_mixed_run_length(
550551 }
551552 }
552553 }
553- delete[] pixelData;
554554 } else {
555555 // data pointer is null so we should just seek to the
556556 // next scanline. If the seek fails return false.
0 commit comments