diff --git a/brush.c b/brush.c index 3af71d4f..503ee6b4 100644 --- a/brush.c +++ b/brush.c @@ -914,6 +914,7 @@ void Outline_brush(void) Brush_offset_Y=(Brush_height>>1); free(temp); // Libération de l'ancienne brosse + temp = NULL; // Réallocation d'un buffer de Smear free(Smear_brush); @@ -1026,6 +1027,7 @@ void Nibble_brush(void) Brush_offset_Y=(Brush_height>>1); free(temp); // Libération de l'ancienne brosse + temp = NULL; // Réallocation d'un buffer de Smear free(Smear_brush); @@ -1196,6 +1198,7 @@ void Stretch_brush(short x1, short y1, short x2, short y2) // Free some memory free(Smear_brush); + Smear_brush = NULL; if ((new_brush=((byte *)malloc(new_brush_width*new_brush_height)))) { @@ -1507,6 +1510,7 @@ void Distort_brush(short x1, short y1, short x2, short y2, short x3, short y3, s // Out of memory while allocating new brush Error(0); free(new_smear_brush); + new_smear_brush = NULL; return; } @@ -1767,6 +1771,8 @@ void Compute_quad_texture(int x1,int y1,int xt1,int yt1, free(ScanY_Yt[1]); free(ScanY_X[0]); free(ScanY_X[1]); + + ScanY_Xt[0] = ScanY_Xt[1] = ScanY_Yt[0] = ScanY_Yt[1] = ScanY_X[0] = ScanY_X[1] = NULL; } @@ -1807,6 +1813,7 @@ void Rotate_brush(float angle) new_brush_height=y_max+1-y_min; free(Smear_brush); // On libère un peu de mémoire + Smear_brush = NULL; if ((new_brush=((byte *)malloc(new_brush_width*new_brush_height)))) { @@ -1929,6 +1936,8 @@ void Draw_quad_texture_preview(int x1,int y1,int xt1,int yt1, free(ScanY_Yt[1]); free(ScanY_X[0]); free(ScanY_X[1]); + + ScanY_Xt[0] = ScanY_Xt[1] = ScanY_Yt[0] = ScanY_Yt[1] = ScanY_X[0] = ScanY_X[1] = NULL; } diff --git a/brush_ops.c b/brush_ops.c index 8178a573..c1227d55 100644 --- a/brush_ops.c +++ b/brush_ops.c @@ -507,6 +507,7 @@ void Polybrush_12_8(void) Capture_brush_with_lasso(Polyfill_number_of_points,Polyfill_table_of_points,click==RIGHT_SIDE); free(Polyfill_table_of_points); + Polyfill_table_of_points = NULL; // On raffiche l'écran pour effacer les traits en xor et pour raffraichir // l'écran si on a découpé une partie de l'image en prenant la brosse. diff --git a/engine.c b/engine.c index 955af5e1..ef958885 100644 --- a/engine.c +++ b/engine.c @@ -1988,6 +1988,7 @@ void Close_popup(void) else { free(Window_background[Windows_open-1]); + Window_background[Windows_open-1] = NULL; Windows_open--; Paintbrush_hidden=Paintbrush_hidden_before_window; diff --git a/fileformats.c b/fileformats.c index 62f8b5c6..2244b8e5 100644 --- a/fileformats.c +++ b/fileformats.c @@ -125,6 +125,7 @@ void Load_IMG(T_IO_Context * context) } free(buffer); + buffer = NULL; } else File_error=1; @@ -642,6 +643,7 @@ void Load_LBM(T_IO_Context * context) File_error=2; } free(LBM_buffer); + LBM_buffer = NULL; } else { // compressé @@ -684,6 +686,7 @@ void Load_LBM(T_IO_Context * context) } free(LBM_buffer); + LBM_buffer = NULL; /*Close_lecture();*/ } } @@ -703,6 +706,7 @@ void Load_LBM(T_IO_Context * context) File_error=2; } free(LBM_buffer); + LBM_buffer = NULL; } else { // compressé @@ -1200,6 +1204,7 @@ void Load_BMP(T_IO_Context * context) File_error=2; } free(buffer); + buffer = NULL; break; case 1 : // Compression RLE 8 bits @@ -1418,6 +1423,7 @@ void Load_BMP(T_IO_Context * context) } free(buffer); + buffer = NULL; fclose(file); } } @@ -2020,6 +2026,7 @@ void Load_GIF(T_IO_Context * context) free(alphabet_suffix); free(alphabet_prefix); free(alphabet_stack); + alphabet_suffix = alphabet_prefix = alphabet_stack = NULL; } // Le fichier contenait au moins la signature GIF87a ou GIF89a else File_error=1; @@ -2759,6 +2766,7 @@ void Load_PCX(T_IO_Context * context) } free(LBM_buffer); + LBM_buffer = NULL; } } } @@ -2834,6 +2842,7 @@ void Load_PCX(T_IO_Context * context) /*Close_lecture();*/ } free(buffer); + buffer = NULL; } } } @@ -3086,6 +3095,7 @@ void Load_SCx(T_IO_Context * context) } } free(LBM_buffer); + LBM_buffer = NULL; } else File_error=1; @@ -3376,6 +3386,7 @@ void Load_PNG(T_IO_Context * context) context->Palette[x].B=palette[x].blue; } free(palette); + palette = NULL; } if (color_type != PNG_COLOR_TYPE_RGB && color_type != PNG_COLOR_TYPE_RGB_ALPHA) @@ -3452,10 +3463,14 @@ void Load_PNG(T_IO_Context * context) /* cleanup heap allocation */ if (row_pointers_allocated) { - for (y=0; yHeight; y++) + for (y=0; yHeight; y++) { free(Row_pointers[y]); + Row_pointers[y] = NULL; + } + } free(Row_pointers); + Row_pointers = NULL; } else File_error=2; diff --git a/filesel.c b/filesel.c index c9346c6d..a3618636 100644 --- a/filesel.c +++ b/filesel.c @@ -138,6 +138,7 @@ void Free_fileselector_list(T_Fileselector *list) list->First=list->First->Next; // Et on efface l'ancien premier élément de la liste free(temp_item); + temp_item = NULL; } Recount_files(list); } @@ -325,6 +326,7 @@ void Read_list_of_files(T_Fileselector *list, byte selected_format) closedir(current_directory); free(current_path); + current_path = NULL; Recount_files(list); } @@ -1447,8 +1449,8 @@ byte Button_Load_or_Save(byte load, T_IO_Context *context) break; case 0: // Set - if (Config.Bookmark_directory[clicked_button-10]) - free(Config.Bookmark_directory[clicked_button-10]); + free(Config.Bookmark_directory[clicked_button-10]); + Config.Bookmark_directory[clicked_button-10] = NULL; Config.Bookmark_label[clicked_button-10][0]='\0'; temp=strlen(Main_current_directory); Config.Bookmark_directory[clicked_button-10]=malloc(temp+1); diff --git a/graph.c b/graph.c index eec2d93c..98d1bf47 100644 --- a/graph.c +++ b/graph.c @@ -2531,6 +2531,7 @@ void Polyfill_general(int vertices, short * points, int color) } free(initial_edge); + initial_edge = NULL; // On ne connait pas simplement les xmin et xmax ici, mais de toutes façon ce n'est pas utilisé en preview Update_part_of_screen(0,top,Main_image_width,bottom-top+1); diff --git a/init.c b/init.c index e574dbfc..6ae4456d 100644 --- a/init.c +++ b/init.c @@ -824,12 +824,14 @@ T_Gui_skin * Load_graphics(const char * skin_file) { sprintf(Gui_loading_error_message, "Unable to load the skin image (missing? not an image file?)\n"); free(gfx); + gfx = NULL; return NULL; } if (Parse_skin(gui, gfx)) { SDL_FreeSurface(gui); free(gfx); + gfx = NULL; return NULL; } SDL_FreeSurface(gui); diff --git a/loadsave.c b/loadsave.c index 4a0efa36..023e3be5 100644 --- a/loadsave.c +++ b/loadsave.c @@ -563,6 +563,7 @@ void End_write(FILE *file) if (! Write_bytes(file,Write_buffer,Write_buffer_index)) File_error=1; free(Write_buffer); + Write_buffer = NULL; } @@ -1001,14 +1002,8 @@ byte Get_pixel(T_IO_Context *context, short x, short y) /// Cleans up resources (currently: the 24bit buffer) void Destroy_context(T_IO_Context *context) { - if (context->Buffer_image_24b) - { - free(context->Buffer_image_24b); - } - if (context->Buffer_image) - { - free(context->Buffer_image); - } + free(context->Buffer_image_24b); + free(context->Buffer_image); memset(context, 0, sizeof(T_IO_Context)); } @@ -1243,6 +1238,7 @@ byte Process_backups(T_String_list **list) free(files_vector[i]); } free(files_vector); + files_vector = NULL; return nb_files; } diff --git a/main.c b/main.c index 058b916d..64fadc6b 100644 --- a/main.c +++ b/main.c @@ -373,6 +373,7 @@ int Analyze_command_line(int argc, char * argv[], char *main_filename, char *mai Extract_filename(spare_filename, buffer); } free(buffer); + buffer = NULL; } else { @@ -533,6 +534,7 @@ int Init_program(int argc,char * argv[]) icon_mask[(y*32+x)/8] |=0x80>>(x&7); SDL_WM_SetIcon(icon,icon_mask); free(icon_mask); + icon_mask = NULL; } SDL_FreeSurface(icon); @@ -835,23 +837,25 @@ void Program_shutdown(void) Delete_safety_backups(); // On libère le buffer de gestion de lignes - if(Horizontal_line_buffer) free(Horizontal_line_buffer); + free(Horizontal_line_buffer); + Horizontal_line_buffer = NULL; // On libère le pinceau spécial - if (Paintbrush_sprite) free(Paintbrush_sprite); + free(Paintbrush_sprite); + Paintbrush_sprite = NULL; // On libère les différents écrans virtuels et brosse: - if(Brush) free(Brush); + free(Brush); + Brush = NULL; Set_number_of_backups(0); - if(Spare_screen) free(Spare_screen); - if(Main_screen) free(Main_screen); + free(Spare_screen); + Spare_screen = NULL; + free(Main_screen); + Main_screen = NULL; // Free the skin (Gui graphics) data - if (Gfx) - { - free(Gfx); - Gfx=NULL; - } + free(Gfx); + Gfx=NULL; // On prend bien soin de passer dans le répertoire initial: if (chdir(Initial_directory)!=-1) diff --git a/miscfileformats.c b/miscfileformats.c index fa67154d..308f3cc7 100644 --- a/miscfileformats.c +++ b/miscfileformats.c @@ -1462,6 +1462,7 @@ void Load_PI1(T_IO_Context * context) else File_error=1; free(buffer); + buffer = NULL; } else File_error=1; @@ -1528,6 +1529,7 @@ void Save_PI1(T_IO_Context * context) } // Libération du buffer mémoire free(buffer); + buffer = NULL; } else { @@ -1790,12 +1792,14 @@ void Load_PC1(T_IO_Context * context) File_error=1; free(bufferdecomp); free(buffercomp); + buffercomp = bufferdecomp = NULL; } else { File_error=1; free(bufferdecomp); free(buffercomp); + buffercomp = bufferdecomp = NULL; } fclose(file); } @@ -1866,6 +1870,7 @@ void Save_PC1(T_IO_Context * context) // Libération des buffers mémoire free(bufferdecomp); free(buffercomp); + buffercomp = bufferdecomp = NULL; } else { @@ -1969,6 +1974,7 @@ void Load_NEO(T_IO_Context * context) else File_error=1; free(buffer); + buffer = NULL; } else File_error=1; @@ -2033,6 +2039,7 @@ void Save_NEO(T_IO_Context * context) } // Libération du buffer mémoire free(buffer); + buffer = NULL; } else { @@ -2667,6 +2674,7 @@ void Save_SCR(T_IO_Context * context) fclose(file); free (output); + output = NULL; File_error = 0; } diff --git a/op_c.c b/op_c.c index 28cb68e1..20b41ff3 100644 --- a/op_c.c +++ b/op_c.c @@ -223,6 +223,7 @@ void CT_delete(T_Conversion_table * t) { free(t->table); free(t); + t = NULL; } @@ -299,7 +300,7 @@ T_Occurrence_table * OT_new(int nbb_r,int nbb_g,int nbb_b) { // Not enough memory ! free(n); - n=0; + n=NULL; } } @@ -312,6 +313,7 @@ void OT_delete(T_Occurrence_table * t) { free(t->table); free(t); + t = NULL; } @@ -793,6 +795,7 @@ void CS_Delete(T_Cluster_set * cs) cs->clusters = nxt; } free(cs); + cs = NULL; } @@ -1019,7 +1022,7 @@ T_Gradient_set * GS_New(T_Cluster_set * cs) n=(T_Gradient_set *)malloc(sizeof(T_Gradient_set)); if (n!=NULL) { - // On recopie les paramŠtres demand‚s + // On recopie les paramètres demandés n->nb_max=cs->nb_max; // On tente d'allouer la table @@ -1029,9 +1032,9 @@ T_Gradient_set * GS_New(T_Cluster_set * cs) GS_Init(n,cs); else { - // Table impossible … allouer + // Table impossible à allouer free(n); - n=0; + n=NULL; } } diff --git a/operatio.c b/operatio.c index d528a2c1..6d8e1711 100644 --- a/operatio.c +++ b/operatio.c @@ -2226,6 +2226,7 @@ void Polyfill_12_9(void) Display_all_screen(); Polyfill(Polyfill_number_of_points,Polyfill_table_of_points,color); free(Polyfill_table_of_points); + Polyfill_table_of_points = NULL; End_of_modification(); if ( (Config.Coords_rel) && (Menu_is_visible) ) @@ -2556,6 +2557,7 @@ void Filled_polyform_12_8(void) Display_all_screen(); Polyfill(Polyfill_number_of_points,Polyfill_table_of_points,color); free(Polyfill_table_of_points); + Polyfill_table_of_points = NULL; Paintbrush_hidden=0; @@ -2640,6 +2642,7 @@ void Filled_contour_0_8(void) Display_all_screen(); Polyfill(Polyfill_number_of_points,Polyfill_table_of_points,color); free(Polyfill_table_of_points); + Polyfill_table_of_points = NULL; Paintbrush_hidden=0; diff --git a/pages.c b/pages.c index a55e77fb..8b732984 100644 --- a/pages.c +++ b/pages.c @@ -116,8 +116,9 @@ void Free_layer(T_Page * page, byte layer) ptr = (short *)(page->Image[layer]); if (-- (*(ptr-1))) // Users-- return; - else + else { free(ptr-1); + } // Stats Stats_pages_number--; @@ -486,6 +487,7 @@ void Free_last_page_of_list(T_List_of_pages * list) page->Prev->Next = page->Next; Clear_page(page); free(page); + page = NULL; list->List_size--; } } diff --git a/palette.c b/palette.c index 73a156b7..1ea2ccc7 100644 --- a/palette.c +++ b/palette.c @@ -2209,6 +2209,7 @@ void Button_Palette(void) free(backup_palette); free(temp_palette); free(working_palette); + backup_palette = temp_palette = working_palette = NULL; }