# HG changeset patch # User magedrifaat # Date 1660775142 -7200 # Node ID 8a4ef572077d322d435b244378f1d38d4c644ed5 # Parent ae78937e24d2f7bb17615690c9103abf2592e955 __tiff__.cc (get_scalar_field_data): replaced _TIFFMalloc with unique_ptr. diff -r ae78937e24d2 -r 8a4ef572077d libinterp/corefcn/__tiff__.cc --- a/libinterp/corefcn/__tiff__.cc Thu Aug 18 00:11:23 2022 +0200 +++ b/libinterp/corefcn/__tiff__.cc Thu Aug 18 00:25:42 2022 +0200 @@ -121,15 +121,11 @@ void - validate_tiff_get_field (bool status, void *p_to_free=NULL) + validate_tiff_get_field (bool status) { // Check if the return status of TIFFGetField is not 1 if (status != 1) - { - if (p_to_free != NULL) - _TIFFfree (p_to_free); - error ("Failed to read tag"); - } + error ("Failed to read tag"); } uint32_t get_rows_in_strip (uint32_t strip_no, uint32_t strip_count, @@ -937,11 +933,11 @@ typedef typename T::element_type P; T arr (arr_dims); - for (uint32_t i = 0; i < count; i++) + for (uint32_t i = 0; i < arr_dims.numel (); i++) { arr(i) = (reinterpret_cast

(data))[i]; } - retval = octave_value (arr); + return octave_value (arr); } octave_value @@ -1045,21 +1041,21 @@ int type_size = TIFFDataWidth (TIFFFieldDataType (fip)); - // TODO(maged): convert to unique_ptr - void *data = _TIFFmalloc (type_size); + std::unique_ptr data + = std::make_unique (type_size); + uint8_t *data_ptr = data.get (); if (tag_id == TIFFTAG_PLANARCONFIG) { // Workaround for a bug in LibTIFF where it incorrectly returns // zero as the default value for PlanaConfiguration - if (! TIFFGetField(tif, tag_id, data)) - *reinterpret_cast (data) = 1; + if (! TIFFGetField(tif, tag_id, data_ptr)) + *reinterpret_cast (data_ptr) = 1; } else - validate_tiff_get_field (TIFFGetFieldDefaulted (tif, tag_id, data), data); + validate_tiff_get_field (TIFFGetFieldDefaulted (tif, tag_id, data_ptr)); - octave_value tag_data_ov = interpret_tag_data (data, 1, + octave_value tag_data_ov = interpret_tag_data (data_ptr, 1, TIFFFieldDataType (fip)); - _TIFFfree (data); return tag_data_ov; }