@@ -138,8 +138,7 @@ cJSON* generateChangeRequest(cJSON* json, char* filePath, char* uuid, char* name
138138void index_file (char * path , char * filename , bool new ) {
139139 Log ("Indexing file: %s/%s\n" , path , filename );
140140
141- char * full_path ;
142- asprintf (& full_path , "%s/%s" , path , filename );
141+ char * full_path = asprintf_hd ("%s/%s" , path , filename );
143142
144143 // Generate UUID
145144 char uuid [37 ] = {0 };
@@ -174,8 +173,7 @@ void index_file(char *path, char* filename, bool new) {
174173 if (validIcon || header .useHooks ) {
175174 Log ("Valid icon OR uses hooks" );
176175 // Create sdr folder
177- char * sdr_path ;
178- asprintf (& sdr_path , "%s.sdr" , full_path );
176+ char * sdr_path = asprintf_hd ("%s.sdr" , full_path );
179177 mkdir (sdr_path , 0755 );
180178
181179 if (validIcon && strncmp (header .icon , "data:image" , strlen ("data:image" )) == 0 ) {
@@ -193,8 +191,7 @@ void index_file(char *path, char* filename, bool new) {
193191 strncpy (fileType , fileTypePointer , fileTypeEndPointer - fileTypePointer );
194192 fileType [fileTypeEndPointer - fileTypePointer ] = '\0' ;
195193
196- char * icon_sdr_path ;
197- asprintf (& icon_sdr_path , "%s/icon.%s" , sdr_path , fileType );
194+ char * icon_sdr_path = asprintf_hd ( "%s/icon.%s" , sdr_path , fileType );
198195
199196 // Parse the base64
200197 FILE * file = fopen (icon_sdr_path , "wb" );
@@ -263,8 +260,7 @@ void index_file(char *path, char* filename, bool new) {
263260 const int pid = fork ();
264261 if (pid == 0 ) {
265262 Log ("Hello from fork!" );
266- char * command ;
267- asprintf (& command , "source \"%s\"; on_install;" , escapedPath );
263+ char * command = asprintf_hd ("source \"%s\"; on_install;" , escapedPath );
268264 Log ("Executing command: %s" , command );
269265 execl ("/var/local/mkk/su" , "su" , "-c" , command , NULL );
270266 } else {
@@ -275,8 +271,7 @@ void index_file(char *path, char* filename, bool new) {
275271
276272 free (escapedPath );
277273
278- char * sdrFilePath ;
279- asprintf (& sdrFilePath , "%s/script.sh" , sdr_path );
274+ char * sdrFilePath = asprintf_hd ("%s/script.sh" , sdr_path );
280275 Log ("Writing script to %s\n" , sdrFilePath );
281276 FILE * scriptFile = fopen (full_path , "r" );
282277 FILE * sdrFile = fopen (sdrFilePath , "w" );
@@ -322,15 +317,12 @@ void index_file(char *path, char* filename, bool new) {
322317
323318void remove_file (const char * path , const char * filename , char * uuid ) {
324319 Log ("Removing file: %s/%s" , path , filename );
325- char * filePath ;
326- asprintf (& filePath , "%s/%s" , path , filename );
320+ char * filePath = asprintf_hd ("%s/%s" , path , filename );
327321
328- char * sdrPath ;
329- asprintf (& sdrPath , "%s.sdr" , filePath );
322+ char * sdrPath = asprintf_hd ("%s.sdr" , filePath );
330323 free (filePath );
331324
332- char * sdrScriptPath ;
333- asprintf (& sdrScriptPath , "%s/script.sh" , sdrPath );
325+ char * sdrScriptPath = asprintf_hd ("%s/script.sh" , sdrPath );
334326
335327 Log ("Loading file" );
336328 FILE * file = fopen (sdrScriptPath , "r" );
0 commit comments