]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
change descriptor out of memory return null
authorBastian Dehn <hhaalo@arcor.de>
Sat, 11 Oct 2025 09:02:46 +0000 (11:02 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 11 Oct 2025 09:02:46 +0000 (11:02 +0200)
src/kds_s2000w_option_descriptors.c

index 86eac7e82fc0343731933e8bbc53b460534f09ec..545ef07205d17d48a8c25972f71814af76e3bf96 100644 (file)
@@ -39,6 +39,8 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_num_options()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_num_options");
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL)
+               return NULL;
 
        descriptor->name = SANE_NAME_NUM_OPTIONS;
        descriptor->title = SANE_TITLE_NUM_OPTIONS;
@@ -60,6 +62,8 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_standard_group()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_standard_group");
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL)
+               return NULL;
 
        descriptor->name = SANE_NAME_STANDARD;
        descriptor->title = SANE_TITLE_STANDARD;
@@ -78,12 +82,20 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_scan_source()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_scan_source");
 
        char** constraint = malloc(sizeof(SANE_String_Const*) * 4);
+       if (constraint == NULL)
+               return NULL;
+
        constraint[0] = "DocumentFeeder";
        constraint[1] = "Automatic";
        constraint[2] = "Flatbed";
        constraint[3] = NULL;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = SANE_NAME_SCAN_SOURCE;
        descriptor->title = SANE_TITLE_SCAN_SOURCE;
@@ -103,12 +115,20 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_color_mode()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_color_mode");
 
        char** constraint = malloc(sizeof(SANE_String_Const*) * 4);
+       if (constraint == NULL)
+               return NULL;
+
        constraint[0] = "Color";
        constraint[1] = "Gray";
        constraint[2] = "BW";
        constraint[3] = NULL;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = SANE_NAME_SCAN_MODE;
        descriptor->title = SANE_TITLE_SCAN_MODE;
@@ -128,6 +148,9 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_dpi()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_dpi");
 
        SANE_Word* constraint = malloc(sizeof(SANE_Word) * 6);
+       if (constraint == NULL)
+               return NULL;
+
        constraint[0] = 5;
        constraint[1] = 100;
        constraint[2] = 150;
@@ -136,6 +159,11 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_dpi()
        constraint[5] = 600;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = SANE_NAME_SCAN_RESOLUTION;
        descriptor->title = SANE_TITLE_SCAN_RESOLUTION;
@@ -155,11 +183,19 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_scanside()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_scanside");
 
        char** constraint = malloc(sizeof(SANE_String_Const*) * 3);
+       if (constraint == NULL)
+               return NULL;
+
        constraint[0] = "Simplex";
        constraint[1] = "Duplex";
        constraint[2] = NULL;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = "scanside";
        descriptor->title = "Duplex Mode";
@@ -182,6 +218,8 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_geometry_group()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_scan_area_group");
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL)
+               return NULL;
 
        descriptor->name = SANE_NAME_GEOMETRY;
        descriptor->title = SANE_TITLE_GEOMETRY;
@@ -200,6 +238,9 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_cropping_mode()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_cropping_mode");
 
        char** constraint = malloc(sizeof(SANE_String_Const*) * 5);
+       if (constraint == NULL)
+               return NULL;
+
        constraint[0] = "AutomaticStraighten";
        constraint[1] = "Automatic";
        constraint[2] = "Photograph";
@@ -207,6 +248,11 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_cropping_mode()
        constraint[4] = NULL;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = "cropping-mode";
        descriptor->title = "Cropping Mode";
@@ -226,11 +272,19 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_cropping_image()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_cropping_image");
 
        char** constraint = malloc(sizeof(SANE_String_Const*) * 3);
+       if (constraint == NULL)
+               return NULL;
+
        constraint[0] = "EntireDocument";
        constraint[1] = "PartialDocument";
        constraint[2] = NULL;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = "cropping-image";
        descriptor->title = "Cropping Image";
@@ -250,11 +304,19 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_image_offset_x()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_image_offset_x");
 
        SANE_Range* constraint = malloc(sizeof(SANE_Range));
+       if (constraint == NULL)
+               return NULL;
+
        constraint->min = 0;
        constraint->max = 2250;
        constraint->quant = 30;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = SANE_NAME_SCAN_TL_X;
        descriptor->title = SANE_TITLE_SCAN_TL_X;
@@ -274,11 +336,19 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_image_offset_y()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_image_offset_y");
 
        SANE_Range* constraint = malloc(sizeof(SANE_Range));
+       if (constraint == NULL)
+               return NULL;
+
        constraint->min = 0;
        constraint->max = 3900;
        constraint->quant = 30;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = SANE_NAME_SCAN_TL_Y;
        descriptor->title = SANE_TITLE_SCAN_TL_Y;
@@ -298,11 +368,19 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_image_width()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_image_width");
 
        SANE_Range* constraint = malloc(sizeof(SANE_Range));
+       if (constraint == NULL)
+               return NULL;
+
        constraint->min = 300;
        constraint->max = 2550;
        constraint->quant = 30;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = SANE_NAME_SCAN_BR_X;
        descriptor->title = SANE_TITLE_SCAN_BR_X;
@@ -322,11 +400,19 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_image_height()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_image_height");
 
        SANE_Range* constraint = malloc(sizeof(SANE_Range));
+       if (constraint == NULL)
+               return NULL;
+
        constraint->min = 300;
        constraint->max = 4200;
        constraint->quant = 30;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = SANE_NAME_SCAN_BR_Y;
        descriptor->title = SANE_TITLE_SCAN_BR_Y;
@@ -349,6 +435,8 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_boldness_smoothing_group()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_advanced_group");
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL)
+               return NULL;
 
        descriptor->name = "boldness-smoothing";
        descriptor->title = "Boldness / Smoothing Options";
@@ -367,12 +455,20 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_foreground_boldness_mode()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_foreground_boldness_mode");
 
        char** constraint = malloc(sizeof(SANE_String_Const*) * 4);
+       if (constraint == NULL)
+               return NULL;
+
        constraint[0] = "None";
        constraint[1] = "AutomaticAdvanced";
        constraint[2] = "Automatic";
        constraint[3] = NULL;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = "foreground-boldness-mode";
        descriptor->title = "Foreground Boldness Mode";
@@ -392,11 +488,19 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_foreground_boldness_aggres
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_foreground_boldness_aggressiveness");
 
        SANE_Range* constraint = malloc(sizeof(SANE_Range));
+       if (constraint == NULL)
+               return NULL;
+
        constraint->min = -10;
        constraint->max = 10;
        constraint->quant = 1;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = "foreground-boldness-aggressiveness";
        descriptor->title = "Foreground Boldness Aggressiveness";
@@ -416,12 +520,20 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_background_smoothing_mode(
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_background_smoothing_mode");
 
        char** constraint = malloc(sizeof(SANE_String_Const*) * 4);
+       if (constraint == NULL)
+               return NULL;
+
        constraint[0] = "None";
        constraint[1] = "AutomaticAdvanced";
        constraint[2] = "Automatic";
        constraint[3] = NULL;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = "background-smoothing-mode";
        descriptor->title = "Background Smoothing Mode";
@@ -441,11 +553,19 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_background_smoothing_aggre
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_background_smoothing_aggressiveness");
 
        SANE_Range* constraint = malloc(sizeof(SANE_Range));
+       if (constraint == NULL)
+               return NULL;
+
        constraint->min = -10;
        constraint->max = 10;
        constraint->quant = 1;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = "background-smoothing-aggressiveness";
        descriptor->title = "Background Smoothing Aggressiveness";
@@ -468,6 +588,8 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_boldness_color_group()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_boldness_color_group");
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL)
+               return NULL;
 
        descriptor->name = "color-options";
        descriptor->title = "Color Options";
@@ -486,6 +608,9 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_color_drop()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_color_drop");
 
        char** constraint = malloc(sizeof(SANE_String_Const*) * 9);
+       if (constraint == NULL)
+               return NULL;
+
        constraint[0] = "None";
        constraint[1] = "Red";
        constraint[2] = "Green";
@@ -497,6 +622,11 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_color_drop()
        constraint[8] = NULL;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = "color-drop-out";
        descriptor->title = "Color Drop Out";
@@ -516,11 +646,19 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_color_drop_out_aggressiven
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_color_drop_out_aggressiveness");
 
        SANE_Range* constraint = malloc(sizeof(SANE_Range));
+       if (constraint == NULL)
+               return NULL;
+
        constraint->min = -10;
        constraint->max = 10;
        constraint->quant = 1;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = "color-drop-out-aggressiveness";
        descriptor->title = "Color Drop Out Aggressiveness";
@@ -540,12 +678,20 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_color_auto_brightness_mode
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_color_auto_brightness_mode");
 
        char** constraint = malloc(sizeof(SANE_String_Const*) * 4);
+       if (constraint == NULL)
+               return NULL;
+
        constraint[0] = "None";
        constraint[1] = "Manual";
        constraint[2] = "Automatic";
        constraint[3] = NULL;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = "color-auto-brightness-mode";
        descriptor->title = "Color Auto Brightness Mode";
@@ -565,11 +711,19 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_color_brightness()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_color_brightness");
 
        SANE_Range* constraint = malloc(sizeof(SANE_Range));
+       if (constraint == NULL)
+               return NULL;
+
        constraint->min = -50;
        constraint->max = 50;
        constraint->quant = 1;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = "color-brightness";
        descriptor->title = "Color Brightness";
@@ -589,11 +743,19 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_color_contrast()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_color_contrast");
 
        SANE_Range* constraint = malloc(sizeof(SANE_Range));
+       if (constraint == NULL)
+               return NULL;
+
        constraint->min = -50;
        constraint->max = 50;
        constraint->quant = 1;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = "color-contrast";
        descriptor->title = "Color Contrast";
@@ -613,6 +775,9 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_color_balance_mode()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_color_balance_mode");
 
        char** constraint = malloc(sizeof(SANE_String_Const*) * 5);
+       if (constraint == NULL)
+               return NULL;
+
        constraint[0] = "None";
        constraint[1] = "Manual";
        constraint[2] = "Automatic";
@@ -620,6 +785,11 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_color_balance_mode()
        constraint[4] = NULL;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = "color-balance-mode";
        descriptor->title = "Color Balance Mode";
@@ -639,11 +809,19 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_color_balance_agressivenes
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_color_balancea_agressiveness");
 
        SANE_Range* constraint = malloc(sizeof(SANE_Range));
+       if (constraint == NULL)
+               return NULL;
+
        constraint->min = -2;
        constraint->max = 2;
        constraint->quant = 1;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = "color-balance-aggressiveness";
        descriptor->title = "Color Balance Aggressiveness";
@@ -663,11 +841,19 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_color_balance_red()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_color_balance_red");
 
        SANE_Range* constraint = malloc(sizeof(SANE_Range));
+       if (constraint == NULL)
+               return NULL;
+
        constraint->min = -50;
        constraint->max = 50;
        constraint->quant = 1;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = "color-balance-red";
        descriptor->title = "Color Balance Red";
@@ -687,11 +873,19 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_color_balance_green()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_color_balance_green");
 
        SANE_Range* constraint = malloc(sizeof(SANE_Range));
+       if (constraint == NULL)
+               return NULL;
+
        constraint->min = -50;
        constraint->max = 50;
        constraint->quant = 1;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = "color-balance-green";
        descriptor->title = "Color Balance Green";
@@ -711,11 +905,19 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_color_balance_blue()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_color_balance_blue");
 
        SANE_Range* constraint = malloc(sizeof(SANE_Range));
+       if (constraint == NULL)
+               return NULL;
+
        constraint->min = -50;
        constraint->max = 50;
        constraint->quant = 1;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = "color-balance-blue";
        descriptor->title = "Color Balance Blue";
@@ -735,6 +937,9 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_color_sharpen()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_color_sharpen");
 
        char** constraint = malloc(sizeof(SANE_String_Const*) * 5);
+       if (constraint == NULL)
+               return NULL;
+
        constraint[0] = "None";
        constraint[1] = "Normal";
        constraint[2] = "High";
@@ -742,6 +947,11 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_color_sharpen()
        constraint[4] = NULL;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = "color-sharpen";
        descriptor->title = "Color Sharpen";
@@ -761,11 +971,19 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_binarization_contrast()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_binarization_contrast");
 
        SANE_Range* constraint = malloc(sizeof(SANE_Range));
+       if (constraint == NULL)
+               return NULL;
+
        constraint->min = -50;
        constraint->max = 50;
        constraint->quant = 1;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = "binarization-contrast";
        descriptor->title = "Binarization Contrast";
@@ -785,6 +1003,8 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_config_reset()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_config_reset");
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL)
+               return NULL;
 
        descriptor->name = "config-reset";
        descriptor->title = "Reset Config";
@@ -806,6 +1026,8 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_image_processing_group()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_image_processing_group");
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL)
+               return NULL;
 
        descriptor->name = "image-processing-options";
        descriptor->title = "Image Processing Options";
@@ -824,6 +1046,8 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_skip_blank_pages()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_skip_blank_pages");
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL)
+               return NULL;
 
        descriptor->name = "skip-blank-pages";
        descriptor->title = "Blank Blank Pages";
@@ -842,11 +1066,19 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_skip_blank_page_content()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_skip_blank_page_content");
 
        SANE_Range* constraint = malloc(sizeof(SANE_Range));
+       if (constraint == NULL)
+               return NULL;
+
        constraint->min = 0;
        constraint->max = 100;
        constraint->quant = 1;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = "skip-blank-page-content";
        descriptor->title = "Skip Blank Page Content";
@@ -866,6 +1098,8 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_hole_fill()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_hole_fill");
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL)
+               return NULL;
 
        descriptor->name = "hole-fill";
        descriptor->title = "Hole Fill";
@@ -884,6 +1118,9 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_post_scan_rotation()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_post_scan_rotation");
 
        char** constraint = malloc(sizeof(SANE_String_Const*) * 6);
+       if (constraint == NULL)
+               return NULL;
+
        constraint[0] = "None";
        constraint[1] = "Automatic";
        constraint[2] = "Automatic90";
@@ -892,6 +1129,11 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_post_scan_rotation()
        constraint[5] = NULL;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = "post-scan-rotation";
        descriptor->title = "Post Scan Rotation";
@@ -911,12 +1153,20 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_edge_fill()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_edge_fill");
 
        char** constraint = malloc(sizeof(SANE_String_Const*) * 4);
+       if (constraint == NULL)
+               return NULL;
+
        constraint[0] = "None";
        constraint[1] = "Automatic";
        constraint[2] = "AutomaticIncludeTears";
        constraint[3] = NULL;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = "edge-fill";
        descriptor->title = "Edge Fill";
@@ -936,12 +1186,20 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_image_border()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_image_border");
 
        char** constraint = malloc(sizeof(SANE_String_Const*) * 4);
+       if (constraint == NULL)
+               return NULL;
+
        constraint[0] = "None";
        constraint[1] = "Add";
        constraint[2] = "Remove";
        constraint[3] = NULL;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       }
 
        descriptor->name = "image-border";
        descriptor->title = "Image Border";
@@ -961,6 +1219,9 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_jpeg_quality()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_jpeg_quality");
 
        char** constraint = malloc(sizeof(SANE_String_Const*) * 6);
+       if (constraint == NULL)
+               return NULL;
+
        constraint[0] = "Draft";
        constraint[1] = "Good";
        constraint[2] = "Better";
@@ -969,6 +1230,11 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_jpeg_quality()
        constraint[5] = NULL;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       };
 
        descriptor->name = "jpeg-quality";
        descriptor->title = "Jpeg Quality";
@@ -991,6 +1257,8 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_feeder_group()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_feeder_group");
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL)
+               return NULL;
 
        descriptor->name = "feeder-options";
        descriptor->title = "Feeder Options";
@@ -1009,6 +1277,8 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_autostart()
        kds_s2000w_debug_printf(ALL, "_kds_s2000w_option_descriptor_autostart");
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL)
+               return NULL;
 
        descriptor->name = "autostart";
        descriptor->title = "Autostart";
@@ -1027,11 +1297,19 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_max_document_length()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_max_document_length");
 
        SANE_Range* constraint = malloc(sizeof(SANE_Range));
+       if (constraint == NULL)
+               return NULL;
+
        constraint->min = 25;
        constraint->max = 400;
        constraint->quant = 1;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       };
 
        descriptor->name = "max-document-length";
        descriptor->title = "Max Document Length";
@@ -1051,6 +1329,9 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_transport_handling()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_transport_handling");
 
        char** constraint = malloc(sizeof(SANE_String_Const*) * 5);
+       if (constraint == NULL)
+               return NULL;
+
        constraint[0] = "Normal";
        constraint[1] = "ImprovedStacking";
        constraint[2] = "BestStacking";
@@ -1058,6 +1339,11 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_transport_handling()
        constraint[4] = NULL;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       };
 
        descriptor->name = "transport-handling";
        descriptor->title = "Transport Handling";
@@ -1077,6 +1363,9 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_multifeed_sensitivity()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_multifeed_sensitivity");
 
        char** constraint = malloc(sizeof(SANE_String_Const*) * 5);
+       if (constraint == NULL)
+               return NULL;
+
        constraint[0] = "None";
        constraint[1] = "Low";
        constraint[2] = "Medium";
@@ -1084,6 +1373,11 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_multifeed_sensitivity()
        constraint[4] = NULL;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       };
 
        descriptor->name = "multifeed-sensitivity";
        descriptor->title = "Multifeed Sensitivity";
@@ -1103,11 +1397,19 @@ SANE_Option_Descriptor *_kds_s2000w_option_descriptor_multifeed_response()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_multifeed_response");
 
        char** constraint = malloc(sizeof(SANE_String_Const*) * 5);
+       if (constraint == NULL)
+               return NULL;
+
        constraint[0] = "Stop";
        constraint[1] = "StopAndGenerateImage";
        constraint[2] = NULL;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       };
 
        descriptor->name = "multifeed-response";
        descriptor->title = "Multifeed Response";
@@ -1127,11 +1429,19 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_document_feeder_timeout()
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_document_feeder_timeout");
 
        SANE_Range* constraint = malloc(sizeof(SANE_Range));
+       if (constraint == NULL)
+               return NULL;
+
        constraint->min = 0;
        constraint->max = 120;
        constraint->quant = 1;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       };
 
        descriptor->name = "document-feeder-timeout";
        descriptor->title = "Document Feeder Timeout";
@@ -1151,12 +1461,20 @@ SANE_Option_Descriptor* _kds_s2000w_option_descriptor_document_feeder_timeout_re
        kds_s2000w_debug_printf(ALL, "kds_s2000w_option_descriptor_document_feeder_timeout_response");
 
        char** constraint = malloc(sizeof(SANE_String_Const*) * 4);
+       if (constraint == NULL)
+               return NULL;
+
        constraint[0] = "Stop";
        constraint[1] = "Pause";
        constraint[2] = "PauseAndWait";
        constraint[3] = NULL;
 
        SANE_Option_Descriptor* descriptor = malloc(sizeof(SANE_Option_Descriptor));
+       if (descriptor == NULL) {
+               free(constraint);
+               constraint = NULL;
+               return NULL;
+       };
 
        descriptor->name = "document-feeder-timeout-response";
        descriptor->title = "Document Feeder Timeout Response";