summaryrefslogtreecommitdiff
path: root/legacy/efreet/src/lib/efreet_desktop_command.c
diff options
context:
space:
mode:
authorSebastian Dransfeld <sd@tango.flipp.net>2010-08-03 19:30:53 +0000
committerSebastian Dransfeld <sd@tango.flipp.net>2010-08-03 19:30:53 +0000
commit8554a0c23b2caeb17bfe8330afa6437f48913d1e (patch)
treeeba3d3fa1e5cc4a548c03164c47b7c0d65137986 /legacy/efreet/src/lib/efreet_desktop_command.c
parentda771758de5d34bd88b7fdb734f1758d64d9bdc9 (diff)
free data on realloc error
SVN revision: 50779
Diffstat (limited to 'legacy/efreet/src/lib/efreet_desktop_command.c')
-rw-r--r--legacy/efreet/src/lib/efreet_desktop_command.c42
1 files changed, 29 insertions, 13 deletions
diff --git a/legacy/efreet/src/lib/efreet_desktop_command.c b/legacy/efreet/src/lib/efreet_desktop_command.c
index ce0af26..dac3618 100644
--- a/legacy/efreet/src/lib/efreet_desktop_command.c
+++ b/legacy/efreet/src/lib/efreet_desktop_command.c
@@ -376,9 +376,12 @@ efreet_desktop_command_build(Efreet_Desktop_Command *command)
376 { 376 {
377 if (len >= size - 1) 377 if (len >= size - 1)
378 { 378 {
379 char *tmp;
380
379 size = len + 1024; 381 size = len + 1024;
380 exec = realloc(exec, size); 382 tmp = realloc(exec, size);
381 if (!exec) goto error; 383 if (!tmp) goto error;
384 exec = tmp;
382 } 385 }
383 386
384 /* XXX handle fields inside quotes? */ 387 /* XXX handle fields inside quotes? */
@@ -457,9 +460,11 @@ efreet_desktop_command_build(Efreet_Desktop_Command *command)
457 command->desktop->orig_path, command->desktop->exec); 460 command->desktop->orig_path, command->desktop->exec);
458 if (len >= size - 1) 461 if (len >= size - 1)
459 { 462 {
463 char *tmp;
460 size = len + 1024; 464 size = len + 1024;
461 exec = realloc(exec, size); 465 tmp = realloc(exec, size);
462 if (!exec) goto error; 466 if (!tmp) goto error;
467 exec = tmp;
463 } 468 }
464 exec[len++] = ' '; 469 exec[len++] = ' ';
465 exec = efreet_desktop_command_append_multiple(exec, &size, 470 exec = efreet_desktop_command_append_multiple(exec, &size,
@@ -470,6 +475,7 @@ efreet_desktop_command_build(Efreet_Desktop_Command *command)
470 exec[len++] = '\0'; 475 exec[len++] = '\0';
471 476
472 execs = eina_list_append(execs, exec); 477 execs = eina_list_append(execs, exec);
478 exec = NULL;
473 479
474 /* If no file was added, then the Exec field doesn't contain any file 480 /* If no file was added, then the Exec field doesn't contain any file
475 * fields (fFuUdDnN). We only want to run the app once in this case. */ 481 * fields (fFuUdDnN). We only want to run the app once in this case. */
@@ -479,11 +485,9 @@ efreet_desktop_command_build(Efreet_Desktop_Command *command)
479 485
480 return execs; 486 return execs;
481error: 487error:
482 if (execs) 488 IF_FREE(exec);
483 { 489 EINA_LIST_FREE(execs, exec)
484 EINA_LIST_FREE(execs, exec) 490 free(exec);
485 free(exec);
486 }
487 return NULL; 491 return NULL;
488} 492}
489 493
@@ -840,12 +844,18 @@ efreet_string_append(char *dest, int *size, int *len, const char *src)
840 844
841 while (l > *size - *len) 845 while (l > *size - *len)
842 { 846 {
847 char *tmp;
843 /* we successfully appended this much */ 848 /* we successfully appended this much */
844 off += *size - *len - 1; 849 off += *size - *len - 1;
845 *len = *size - 1; 850 *len = *size - 1;
846 *size += 1024; 851 *size += 1024;
847 dest = realloc(dest, *size); 852 tmp = realloc(dest, *size);
848 if (!dest) return NULL; 853 if (!tmp)
854 {
855 free(dest);
856 return NULL;
857 }
858 dest = tmp;
849 *(dest + *len) = '\0'; 859 *(dest + *len) = '\0';
850 860
851 l = eina_strlcpy(dest + *len, src + off, *size - *len); 861 l = eina_strlcpy(dest + *len, src + off, *size - *len);
@@ -860,9 +870,15 @@ efreet_string_append_char(char *dest, int *size, int *len, char c)
860{ 870{
861 if (*len >= *size - 1) 871 if (*len >= *size - 1)
862 { 872 {
873 char *tmp;
863 *size += 1024; 874 *size += 1024;
864 dest = realloc(dest, *size); 875 tmp = realloc(dest, *size);
865 if (!dest) return NULL; 876 if (!tmp)
877 {
878 free(dest);
879 return NULL;
880 }
881 dest = tmp;
866 } 882 }
867 883
868 dest[(*len)++] = c; 884 dest[(*len)++] = c;