@@ -72,26 +72,25 @@ void checkSchedule() {
7272 }
7373}
7474
75- void loadSchedule ()
76- {
77- if (!WLED_FS.exists (SCHEDULE_FILE)) return ;
75+ bool loadSchedule () {
76+ if (!WLED_FS.exists (SCHEDULE_FILE)) return false ;
7877
79- requestJSONBufferLock () ; // Prevent concurrent JSON access
78+ if (! requestJSONBufferLock (7 )) return false ; // 🔐 Acquire lock safely
8079
8180 File file = WLED_FS.open (SCHEDULE_FILE, " r" );
8281 if (!file) {
8382 releaseJSONBufferLock ();
84- return ;
83+ return false ;
8584 }
8685
8786 DynamicJsonDocument doc (4096 );
8887 DeserializationError error = deserializeJson (doc, file);
89- file.close (); // ✅ Close file before releasing lock
88+ file.close (); // ✅ Always close before releasing lock
9089
9190 if (error) {
9291 DEBUG_PRINTF_P (PSTR (" [Schedule] JSON parse failed: %s\n " ), error.c_str ());
9392 releaseJSONBufferLock ();
94- return ;
93+ return false ;
9594 }
9695
9796 numScheduleEvents = 0 ;
@@ -101,11 +100,12 @@ void loadSchedule()
101100 scheduleEvents[numScheduleEvents++] = {
102101 (uint8_t )e[" sm" ].as <int >(), (uint8_t )e[" sd" ].as <int >(), // start month, day
103102 (uint8_t )e[" em" ].as <int >(), (uint8_t )e[" ed" ].as <int >(), // end month, day
104- (uint8_t )e[" r" ].as <int >(), (uint8_t )e[" h" ].as <int >(), // repeat mask, hour
105- (uint8_t )e[" m" ].as <int >(), (uint8_t )e[" p" ].as <int >() // minute, preset
103+ (uint8_t )e[" r" ].as <int >(), (uint8_t )e[" h" ].as <int >(), // repeat mask, hour
104+ (uint8_t )e[" m" ].as <int >(), (uint8_t )e[" p" ].as <int >() // minute, preset
106105 };
107106 }
108107
109108 DEBUG_PRINTF_P (PSTR (" [Schedule] Loaded %u schedule entries from schedule.json\n " ), numScheduleEvents);
110- releaseJSONBufferLock (); // Done safely
109+ releaseJSONBufferLock (); // 🔓 Unlock before returning
110+ return true ;
111111}
0 commit comments