Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill "if" before free, and useless cast of free argument.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Fri, 28 Jan 2011 15:27:37 +0000 (16:27 +0100)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Wed, 9 Nov 2011 14:16:02 +0000 (15:16 +0100)
free(NULL) is a no-op, there is no need to test the given pointer
before call.
The same argument stands for xbt_free, xbt_dict_free, xbt_dynar_free,
and xbt_strbuff_free.

53 files changed:
examples/gras/replay/xbt_workload.c
examples/msg/actions/actions.c
include/xbt/sysdep.h
src/amok/PeerManagement/peermanagement.c
src/bindings/lua/lua_stub_generator.c
src/gras/DataDesc/cbps.c
src/gras/DataDesc/ddt_create.c
src/gras/Transport/transport_plugin_sg.c
src/gras/Transport/transport_plugin_tcp.c
src/gras/Virtu/process.c
src/gras/Virtu/sg_emul.c
src/gras/gras.c
src/include/surf/surf_resource.h
src/instr/jedule/jedule_platform.c
src/mc/memory_map.c
src/msg/msg_actions.c
src/rngstreams/RngStream.c
src/simdag/sd_global.c
src/simdag/sd_task.c
src/simix/smx_context_base.c
src/simix/smx_process.c
src/smpi/smpi_bench.c
src/surf/cpu.c
src/surf/cpu_im.c
src/surf/cpu_ti.c
src/surf/network.c
src/surf/network_gtnets.c
src/surf/network_im.c
src/surf/network_ns3.c
src/surf/surf.c
src/surf/surf_routing.c
src/surf/surf_routing_dijkstra.c
src/surf/surfxml_parse.c
src/surf/workstation_ptask_L07.c
src/xbt/backtrace_linux.c
src/xbt/dict_cursor.c
src/xbt/dynar.c
src/xbt/ex.c
src/xbt/graphxml_parse.c
src/xbt/lib.c
src/xbt/log.c
src/xbt/mmalloc/mm_legacy.c
src/xbt/xbt_os_thread.c
src/xbt/xbt_peer.c
src/xbt/xbt_replay_trace_reader.c
src/xbt/xbt_strbuff.c
tools/gras/stub_generator.c
tools/tesh/run_context.c
tools/tesh/tesh.c
win32_test_app/src/TBuffer.c
win32_test_app/src/TStream.c
win32_test_app/src/TTestCaseContext.c
win32_test_app/src/TThreadDynarray.c

index f3b3ddf..f16e41f 100644 (file)
@@ -71,12 +71,9 @@ void xbt_workload_elm_free(xbt_workload_elm_t cmd)
 {
   if (!cmd)
     return;
-  if (cmd->who)
-    free(cmd->who);
-  if (cmd->comment)
-    free(cmd->comment);
-  if (cmd->str_arg)
-    free(cmd->str_arg);
+  free(cmd->who);
+  free(cmd->comment);
+  free(cmd->str_arg);
   free(cmd);
 }
 
index ca75da4..85a00a0 100644 (file)
@@ -87,8 +87,7 @@ static void action_send(const char *const *action)
    
    XBT_VERB("%s %f", name, MSG_get_clock() - clock);
 
-  if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
-    free(name);
+  free(name);
 
 #ifdef HAVE_TRACING
   TRACE_smpi_ptp_out(rank, rank, dst_traced, "send");
@@ -145,8 +144,7 @@ static void action_recv(const char *const *action)
     MSG_task_destroy(task);
   }
 
-  if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
-    free(name);
+  free(name);
 #ifdef HAVE_TRACING
   TRACE_smpi_ptp_out(rank, src_traced, rank, "recv");
   TRACE_smpi_recv(rank, src_traced, rank);
@@ -219,8 +217,7 @@ static void action_wait(const char *const *action)
   MSG_task_destroy(task);
 
   XBT_VERB("%s %f", name, MSG_get_clock() - clock);
-  if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
-    free(name);
+  free(name);
 #ifdef HAVE_TRACING
   TRACE_smpi_ptp_out(rank, src_traced, rank, "wait");
   TRACE_smpi_recv(rank, src_traced, rank);
@@ -264,8 +261,7 @@ static void action_barrier(const char *const *action)
     mutex=NULL;
   }
 
-  if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
-    free(name);
+  free(name);
 
 }
 
@@ -386,8 +382,7 @@ static void action_sleep(const char *const *action)
   MSG_process_sleep(parse_double(duration));
   XBT_VERB("%s %f ", name, MSG_get_clock() - clock);
 
-  if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
-    free(name);
+  free(name);
 }
 
 static void action_allReduce(const char *const *action) {
@@ -472,8 +467,7 @@ static void action_comm_size(const char *const *action)
     name = xbt_str_join_array(action, " ");
   communicator_size = parse_double(size);
   XBT_VERB("%s %f", name, MSG_get_clock() - clock);
-  if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
-    free(name);
+  free(name);
 }
 
 static void action_compute(const char *const *action)
@@ -489,8 +483,7 @@ static void action_compute(const char *const *action)
   MSG_task_execute(task);
   MSG_task_destroy(task);
   XBT_VERB("%s %f", name, MSG_get_clock() - clock);
-  if (XBT_LOG_ISENABLED(actions, xbt_log_priority_verbose))
-    free(name);
+  free(name);
 }
 
 static void action_init(const char *const *action)
index 90be945..696dd69 100644 (file)
@@ -128,9 +128,7 @@ void *xbt_realloc(void *p, size_t s)
       res = xbt_malloc(s);
     }
   } else {
-    if (p) {
-      free(p);
-    }
+    free(p);
   }
   return res;
 }
index 704b72e..a842c92 100644 (file)
@@ -283,8 +283,7 @@ static void _amok_pm_leave(void *p)
   /* moddata */
   amok_pm_moddata_t mod = (amok_pm_moddata_t) p;
 
-  if (mod->groups)
-    xbt_dict_free(&mod->groups);
+  xbt_dict_free(&mod->groups);
 
   /* callbacks */
   gras_cb_unregister("amok_pm_kill", &amok_pm_cb_kill);
index 87e2c8c..07911e8 100644 (file)
@@ -67,7 +67,9 @@ const char *SIM_MAIN_POSTEMBULE = "\n"
     "\n"
     "  /* cleanup the place */\n"
     "  gras_clean();\n"
-    "  if (gras_log)\n" "    free(gras_log);\n" "  return 0;\n" "}\n";
+    "  free(gras_log);\n"
+    "  return 0;\n"
+    "}\n";
 
 
 /***************************************
index b64eb2f..145560f 100644 (file)
@@ -282,8 +282,7 @@ void gras_cbps_block_end(gras_cbps_t ps)
       xbt_dynar_free_container(&varstack);      /*already empty, save a test ;) */
     }
 
-    if (var->data)
-      free(var->data);
+    free(var->data);
     free(var);
     free(name);
   }
index 05eb79e..ece97c0 100644 (file)
@@ -158,8 +158,7 @@ void gras_dd_cat_field_free(void *f)
   gras_dd_cat_field_t field = *(gras_dd_cat_field_t *) f;
   XBT_IN("");
   if (field) {
-    if (field->name)
-      free(field->name);
+    free(field->name);
     free(field);
   }
   XBT_OUT();
index 3f90e48..0ec86e3 100644 (file)
@@ -274,10 +274,8 @@ void gras_trp_sg_socket_close(gras_socket_t sock)
         ("socket_close called on the unknown incoming socket %p (port=%d)",
          sock, sockdata->server_port);
   }
-  if (sock->data) {
-    /* FIXME: kill the rdv point if receiver side */
-    free(sock->data);
-  }
+  /* FIXME: kill the rdv point if receiver side */
+  free(sock->data);
   XBT_OUT();
 }
 
@@ -373,8 +371,7 @@ int gras_trp_sg_chunk_recv(gras_socket_t sock,
   if (data)
     memcpy(data, msg_got->payl, size);
 
-  if (msg_got->payl)
-    xbt_free(msg_got->payl);
+  xbt_free(msg_got->payl);
 
   xbt_free(msg_got);
   SIMIX_req_mutex_unlock(remote_sock_data->mutex);
index ad90f80..adf691c 100644 (file)
@@ -303,8 +303,7 @@ static void gras_trp_sock_socket_close(gras_socket_t sock)
   if (!sock)
     return;                     /* close only once */
 
-  if (((gras_trp_tcp_sock_data_t)sock->data)->peer_name)
-    free(((gras_trp_tcp_sock_data_t)sock->data)->peer_name);
+  free(((gras_trp_tcp_sock_data_t)sock->data)->peer_name);
   free(sock->data);
 
   XBT_VERB("close tcp connection %d", sock->sd);
@@ -757,16 +756,14 @@ void gras_trp_buf_socket_close(gras_socket_t sock)
           data->in_buf.size - data->in_buf.pos,
           data->in_buf.size, data->in_buf.pos);
   }
-  if (data->in_buf.data)
-    free(data->in_buf.data);
+  free(data->in_buf.data);
 
   if (data->out_buf.size != data->out_buf.pos) {
     XBT_DEBUG("Flush the socket before closing (in=%d,out=%d)",
            data->in_buf.size, data->out_buf.size);
     gras_trp_bufiov_flush(sock);
   }
-  if (data->out_buf.data)
-    free(data->out_buf.data);
+  free(data->out_buf.data);
 
 #ifdef HAVE_READV
   if (data->in_buf_v) {
index c0cf02f..36949b3 100644 (file)
@@ -179,8 +179,7 @@ void gras_procdata_exit()
 const char *gras_os_hostport()
 {
   static char *res = NULL;
-  if (res)
-    free(res);                  /* my port may have changed */
+  free(res);                  /* my port may have changed */
   res = bprintf("%s:%d", gras_os_myname(), gras_os_myport());
   return (const char *) res;
 }
index 63d8b77..7892f4c 100644 (file)
@@ -48,8 +48,7 @@ void gras_emul_init(void)
 
 void gras_emul_exit(void)
 {
-  if (locbuf)
-    free(locbuf);
+  free(locbuf);
   xbt_dict_free(&benchmark_set);
   xbt_os_timer_free(timer);
 }
index 73615c5..c810ef1 100644 (file)
@@ -175,8 +175,7 @@ const char *hexa_str(unsigned char *data, int size, int downside)
   int begin, increment;
 
   if (buffsize < 5 * (size + 1)) {
-    if (buff)
-      free(buff);
+    free(buff);
     buffsize = 5 * (size + 1);
     buff = xbt_malloc(buffsize);
   }
index d0a14d5..dc66869 100644 (file)
@@ -24,10 +24,8 @@ static XBT_INLINE
 static XBT_INLINE void surf_resource_free(void *r)
 {
   surf_resource_t resource = r;
-  if (resource->name)
-    free(resource->name);
-  if (resource->properties)
-    xbt_dict_free(&resource->properties);
+  free(resource->name);
+  xbt_dict_free(&resource->properties);
   free(resource);
 }
 
index 6ffefda..ebcfa4b 100644 (file)
@@ -46,9 +46,7 @@ static int compare_ids(const void *num1, const void *num2) {
 static void jed_free_container(jed_simgrid_container_t container) {
 
        xbt_dict_free(&container->name2id);
-       if( container->resource_list != NULL ) {
-               xbt_dynar_free(&container->resource_list);
-       }
+       xbt_dynar_free(&container->resource_list);
 
        if( container->container_children != NULL ) {
                unsigned int iter;
index e5ea6c8..7496b50 100644 (file)
@@ -133,8 +133,7 @@ memory_map_t get_memory_map(void)
     ret->mapsize++;
   }
 
-  if (line)
-    free(line);
+  free(line);
 
   return ret;
 }
index 5ac10d1..5fbdd7a 100644 (file)
@@ -186,8 +186,7 @@ MSG_error_t MSG_action_trace_run(char *path)
     }
   }
 
-  if (action_line)
-    free(action_line);
+  free(action_line);
   if (path)
     fclose(action_fp);
   xbt_dict_free(&action_queues);
index de1416b..eb4f695 100644 (file)
@@ -339,8 +339,7 @@ void RngStream_DeleteStream (RngStream * p)
 {
    if (*p == NULL)
       return;
-   if ((*p)->name != NULL)
-      free ((*p)->name);
+   free((*p)->name);
    free (*p);
    *p = NULL;
 }
index a9065e3..7a1a385 100644 (file)
@@ -395,15 +395,10 @@ void SD_exit(void)
 
   xbt_mallocator_free(sd_global->task_mallocator);
 
-  XBT_DEBUG("Destroying workstation and link arrays if necessary...");
-  if (sd_global->workstation_list != NULL)
-    xbt_free(sd_global->workstation_list);
-
-  if (sd_global->link_list != NULL)
-    xbt_free(sd_global->link_list);
-
-  if (sd_global->recyclable_route != NULL)
-    xbt_free(sd_global->recyclable_route);
+  XBT_DEBUG("Destroying workstation and link arrays...");
+  xbt_free(sd_global->workstation_list);
+  xbt_free(sd_global->link_list);
+  xbt_free(sd_global->recyclable_route);
 
   XBT_DEBUG("Destroying the swags...");
   xbt_swag_free(sd_global->not_scheduled_task_set);
index 7546cc4..fc15666 100644 (file)
@@ -413,8 +413,7 @@ void SD_task_dotty(SD_task_t task, void *out)
  */
 static void __SD_task_dependency_destroy(void *dependency)
 {
-  if (((SD_dependency_t) dependency)->name != NULL)
-    xbt_free(((SD_dependency_t) dependency)->name);
+  xbt_free(((SD_dependency_t)dependency)->name);
   xbt_free(dependency);
 }
 
index 810ef6c..1a5d140 100644 (file)
@@ -72,8 +72,7 @@ void smx_ctx_base_free(smx_context_t context)
     /* free argv */
     if (context->argv) {
       for (i = 0; i < context->argc; i++)
-        if (context->argv[i])
-          free(context->argv[i]);
+        free(context->argv[i]);
 
       free(context->argv);
     }
index f2f550c..ed3c756 100644 (file)
@@ -100,15 +100,12 @@ void SIMIX_process_empty_trash(void)
     SIMIX_context_free(process->context);
 
     /* Free the exception allocated at creation time */
-    if (process->running_ctx)
-      free(process->running_ctx);
-    if (process->properties)
-      xbt_dict_free(&process->properties);
+    free(process->running_ctx);
+    xbt_dict_free(&process->properties);
 
     xbt_fifo_free(process->comms);
 
     free(process->name);
-    process->name = NULL;
     free(process);
   }
 }
index 5a0e491..80c1896 100644 (file)
@@ -36,15 +36,9 @@ typedef struct {
 
 void smpi_bench_destroy(void)
 {
-  if (allocs) {
-    xbt_dict_free(&allocs);
-  }
-  if (samples) {
-    xbt_dict_free(&samples);
-  }
-  if(calls) {
-    xbt_dict_free(&calls);
-  }
+  xbt_dict_free(&allocs);
+  xbt_dict_free(&samples);
+  xbt_dict_free(&calls);
 }
 
 static void smpi_execute_flops(double flops)
index f7ba2ce..b0d69b5 100644 (file)
@@ -144,8 +144,7 @@ static int cpu_action_unref(surf_action_t action)
       lmm_variable_free(cpu_maxmin_system,
                         ((surf_action_cpu_Cas01_t) action)->variable);
 #ifdef HAVE_TRACING
-    if (action->category)
-      xbt_free(action->category);
+    xbt_free(action->category);
 #endif
     surf_action_free(&action);
     return 1;
index eec52e0..0c29222 100644 (file)
@@ -162,8 +162,7 @@ static int cpu_im_action_unref(surf_action_t action)
                     ((cpu_Cas01_im_t) ACTION_GET_CPU(action))->action_set);
     xbt_swag_insert(ACTION_GET_CPU(action), cpu_im_modified_cpu);
 #ifdef HAVE_TRACING
-    if (action->category)
-      xbt_free(action->category);
+    xbt_free(action->category);
 #endif
     surf_action_free(&action);
     return 1;
index 38834c5..ab3bad8 100644 (file)
@@ -50,10 +50,8 @@ static int surf_cpu_ti_binary_search(double *array, double a, int low,
 
 static void surf_cpu_ti_free_trace(surf_cpu_ti_trace_t trace)
 {
-  if (trace->time_points)
-    xbt_free(trace->time_points);
-  if (trace->integral)
-    xbt_free(trace->integral);
+  xbt_free(trace->time_points);
+  xbt_free(trace->integral);
   xbt_free(trace);
 }
 
index 634c897..57dc544 100644 (file)
@@ -318,8 +318,7 @@ static int net_action_unref(surf_action_t action)
 #ifdef HAVE_TRACING
     xbt_free(((surf_action_network_CM02_t) action)->src_name);
     xbt_free(((surf_action_network_CM02_t) action)->dst_name);
-    if (action->category)
-      xbt_free(action->category);
+    xbt_free(action->category);
 #endif
     surf_action_free(&action);
     return 1;
index 3667fb8..035c80a 100644 (file)
@@ -170,8 +170,7 @@ static int action_unref(surf_action_t action)
   if (!action->refcount) {
     xbt_swag_remove(action, action->state_set);
 #ifdef HAVE_TRACING
-    if (action->category)
-      xbt_free(action->category);
+    xbt_free(action->category);
 #endif
     surf_action_free(&action);
     return 1;
index fc12e42..84c2825 100644 (file)
@@ -295,8 +295,7 @@ static int im_net_action_unref(surf_action_t action)
 #ifdef HAVE_TRACING
     xbt_free(((surf_action_network_CM02_im_t) action)->src_name);
     xbt_free(((surf_action_network_CM02_im_t) action)->dst_name);
-    if (action->category)
-      xbt_free(action->category);
+    xbt_free(action->category);
 #endif
     surf_action_free(&action);
     return 1;
index 31b26d5..c1ede45 100644 (file)
@@ -79,8 +79,7 @@ void parse_ns3_add_host(void)
 }
 
 static void ns3_free_dynar(void * elmts){
-       if(elmts)
-               free(elmts);
+       free(elmts);
        return;
 }
 
@@ -548,8 +547,7 @@ static int action_unref(surf_action_t action)
 #ifdef HAVE_TRACING
     xbt_free(((surf_action_network_ns3_t)action)->src_name);
     xbt_free(((surf_action_network_ns3_t)action)->dst_name);
-    if (action->category)
-      xbt_free(action->category);
+    xbt_free(action->category);
 #endif
     XBT_DEBUG ("Removing action %p", action);
     surf_action_free(&action);
index 9a57398..dfdafbd 100644 (file)
@@ -387,8 +387,7 @@ void surf_exit(void)
   }
   surf_action_exit();
 
-  if (surf_path)
-    xbt_dynar_free(&surf_path);
+  xbt_dynar_free(&surf_path);
 
   xbt_lib_free(&host_lib);
   xbt_lib_free(&link_lib);
index aa8daea..b5a2578 100644 (file)
@@ -1197,10 +1197,8 @@ void generic_free_extended_route(route_extended_t e_route)
 {
   if (e_route) {
     xbt_dynar_free(&(e_route->generic_route.link_list));
-    if (e_route->src_gateway)
-      xbt_free(e_route->src_gateway);
-    if (e_route->dst_gateway)
-      xbt_free(e_route->dst_gateway);
+    xbt_free(e_route->src_gateway);
+    xbt_free(e_route->dst_gateway);
     xbt_free(e_route);
   }
 }
@@ -1437,8 +1435,7 @@ static void routing_parse_cluster(void)
         bprintf("%s%s_router%s", struct_cluster->prefix, struct_cluster->id,
                 struct_cluster->suffix);
   sg_platf_new_router(&router);
-  if (newid)
-    free(newid);
+  free(newid);
 
   //Make the backbone
   if ((struct_cluster->bb_bw != 0) && (struct_cluster->bb_lat != 0)) {
index cced813..a27f9aa 100644 (file)
@@ -50,9 +50,7 @@ static void route_cache_elem_free(void *e)
 static void graph_node_map_elem_free(void *e)
 {
   graph_node_map_element_t elm = (graph_node_map_element_t) e;
-  if (elm) {
-    xbt_free(elm);
-  }
+  xbt_free(elm);
 }
 
 static void graph_edge_data_free(void *e)
@@ -60,10 +58,8 @@ static void graph_edge_data_free(void *e)
   route_extended_t e_route = (route_extended_t) e;
   if (e_route) {
     xbt_dynar_free(&(e_route->generic_route.link_list));
-    if (e_route->src_gateway)
-      xbt_free(e_route->src_gateway);
-    if (e_route->dst_gateway)
-      xbt_free(e_route->dst_gateway);
+    xbt_free(e_route->src_gateway);
+    xbt_free(e_route->dst_gateway);
     xbt_free(e_route);
   }
 }
index 3ee3d56..0723683 100644 (file)
@@ -495,10 +495,8 @@ void surf_parse_open(const char *file)
 
 void surf_parse_close(void)
 {
-  if (surf_input_buffer_stack)
-    xbt_dynar_free(&surf_input_buffer_stack);
-  if (surf_file_to_parse_stack)
-    xbt_dynar_free(&surf_file_to_parse_stack);
+  xbt_dynar_free(&surf_input_buffer_stack);
+  xbt_dynar_free(&surf_file_to_parse_stack);
 
   if (surf_file_to_parse) {
     surf_parse__delete_buffer(surf_input_buffer);
index 0752e88..e642573 100644 (file)
@@ -404,8 +404,7 @@ static void ptask_update_resource_state(void *id,
 
 static void ptask_finalize(void)
 {
-  if (ptask_parallel_task_link_set != NULL)
-    xbt_dict_free(&ptask_parallel_task_link_set);
+  xbt_dict_free(&ptask_parallel_task_link_set);
 
   surf_model_exit(surf_workstation_model);
   surf_workstation_model = NULL;
index e4eda28..966070a 100644 (file)
@@ -92,8 +92,7 @@ void xbt_ex_setup_backtrace(xbt_ex_t * e)
         char *data;
 
         xbt_dynar_foreach(path, cpt, data) {
-          if (binary_name)
-            free(binary_name);
+          free(binary_name);
           binary_name = bprintf("%s/%s", data, xbt_binary_name);
           if (!stat(binary_name, &stat_buf)) {
             /* Found. */
index 44f9f56..6d7f277 100644 (file)
@@ -51,10 +51,8 @@ XBT_INLINE xbt_dict_cursor_t xbt_dict_cursor_new(const xbt_dict_t dict)
  */
 XBT_INLINE void xbt_dict_cursor_free(xbt_dict_cursor_t * cursor)
 {
-  if (*cursor) {
-    xbt_free(*cursor);
-    *cursor = NULL;
-  }
+  xbt_free(*cursor);
+  *cursor = NULL;
 }
 
 /*
index 87d4aa8..3df1edf 100644 (file)
@@ -259,7 +259,6 @@ XBT_INLINE void xbt_dynar_reset(xbt_dynar_t const dynar)
     _dynar_map(dynar, dynar->free_f);
   }
   /*
-     if (dynar->data)
      free(dynar->data);
 
      dynar->size = 0;
index 7f46a21..26d7d3d 100644 (file)
@@ -187,8 +187,7 @@ void xbt_ex_free(xbt_ex_t e)
 {
   int i;
 
-  if (e.msg)
-    free(e.msg);
+  free(e.msg);
   if (e.remote) {
     free(e.procname);
     free(e.file);
@@ -198,8 +197,8 @@ void xbt_ex_free(xbt_ex_t e)
 
   if (e.bt_strings) {
     for (i = 0; i < e.used; i++)
-      free((char *) e.bt_strings[i]);
-    free((char **) e.bt_strings);
+      free(e.bt_strings[i]);
+    free(e.bt_strings);
   }
   /* memset(e,0,sizeof(xbt_ex_t)); */
 }
@@ -393,12 +392,9 @@ static void bad_example(void)
     strcpy(cp2, "bar");
   }
   TRY_CLEANUP {
-    if (cp3 != NULL)
-      free(cp3);
-    if (cp2 != NULL)
-      free(cp2);
-    if (cp1 != NULL)
-      free(cp1);
+    free(cp3);
+    free(cp2);
+    free(cp1);
   }
   CATCH_ANONYMOUS {
     printf("cp3=%s", cp3);
@@ -431,10 +427,8 @@ static void good_example(void)
     }
     TRY_CLEANUP {               /*04 */
       printf("cp3=%s", cp3 == NULL /*02 */ ? "" : cp3);
-      if (cp3 != NULL)
-        free(cp3);
-      if (cp2 != NULL)
-        free(cp2);
+      free(cp3);
+      free(cp2);
       /*05 cp1 was given away */
     }
     CATCH_ANONYMOUS {
index e5700e4..89582e7 100644 (file)
@@ -103,10 +103,8 @@ void xbt_graph_parse_open(const char *file)
 
 void xbt_graph_parse_close(void)
 {
-  if (xbt_graph_input_buffer_stack)
-    xbt_dynar_free(&xbt_graph_input_buffer_stack);
-  if (xbt_graph_file_to_parse_stack)
-    xbt_dynar_free(&xbt_graph_file_to_parse_stack);
+  xbt_dynar_free(&xbt_graph_input_buffer_stack);
+  xbt_dynar_free(&xbt_graph_file_to_parse_stack);
 
   if (xbt_graph_file_to_parse) {
     xbt_graph_parse__delete_buffer(xbt_graph_input_buffer);
index 66dc889..189da87 100644 (file)
@@ -445,10 +445,8 @@ int xbt_lib_cursor_get_or_free(xbt_lib_cursor_t * cursor,
 
 static void xbt_lib_cursor_free(xbt_lib_cursor_t * cursor)
 {
-  if (*cursor) {
-    xbt_free(*cursor);
-    *cursor = NULL;
-  }
+  xbt_free(*cursor);
+  *cursor = NULL;
 }
 
 void xbt_lib_cursor_step(xbt_lib_cursor_t cursor)
index 172a082..1a29248 100644 (file)
@@ -486,8 +486,7 @@ static void _free_setting(void *s)
   xbt_log_setting_t set = *(xbt_log_setting_t *) s;
   if (set) {
     free(set->catname);
-    if (set->fmt)
-      free(set->fmt);
+    free(set->fmt);
     free(set);
   }
 }
index 2bced98..a780f13 100644 (file)
@@ -71,8 +71,7 @@ void *realloc(void *p, size_t s)
     else
       ret = mmalloc(mdp, s);
   } else {
-    if (p)
-      mfree(mdp, p);
+    mfree(mdp, p);
   }
   UNLOCK(mdp);
 
index b2be4c7..c79d8f8 100644 (file)
@@ -729,8 +729,7 @@ void xbt_os_thread_join(xbt_os_thread_t thread, void **thread_return)
 
   CloseHandle(thread->handle);
 
-  if (thread->name)
-    free(thread->name);
+  free(thread->name);
 
   free(thread);
 }
index 23d7ca4..80dae08 100644 (file)
@@ -48,8 +48,7 @@ xbt_peer_t xbt_peer_from_string(const char *peerport)
 void xbt_peer_free(xbt_peer_t peer)
 {
   if (peer) {
-    if (peer->name)
-      free(peer->name);
+    free(peer->name);
     free(peer);
   }
 }
index 0c02352..70f2af8 100644 (file)
@@ -34,8 +34,7 @@ xbt_replay_trace_reader_t xbt_replay_trace_reader_new(const char *filename)
 
 const char *xbt_replay_trace_reader_position(xbt_replay_trace_reader_t reader)
 {
-  if (reader->position)
-    free(reader->position);
+  free(reader->position);
   reader->position = bprintf("%s:%d",reader->filename,reader->linenum);
   return reader->position;
 }
@@ -67,8 +66,7 @@ const char **xbt_replay_trace_reader_get(xbt_replay_trace_reader_t reader)
 void xbt_replay_trace_reader_free(xbt_replay_trace_reader_t *reader)
 {
   free((*reader)->filename);
-  if ((*reader)->position)
-    free((*reader)->position);
+  free((*reader)->position);
   fclose((*reader)->fp);
   free((*reader)->line);
   free(*reader);
index 4af8992..16835fd 100644 (file)
@@ -60,8 +60,7 @@ XBT_INLINE void xbt_strbuff_free_container(xbt_strbuff_t b)
 XBT_INLINE void xbt_strbuff_free(xbt_strbuff_t b)
 {
   if (b) {
-    if (b->data)
-      free(b->data);
+    free(b->data);
     free(b);
   }
 }
@@ -272,8 +271,7 @@ void xbt_strbuff_varsubst(xbt_strbuff_t b, xbt_dict_t patterns)
         }
         free(value);
 
-        if (default_value)
-          free(default_value);
+        free(default_value);
 
         end--;                  /* compensate the next end++ */
       }
index dfe760c..5de317a 100644 (file)
@@ -169,8 +169,7 @@ int main(int argc, char *argv[])
   generate_simulation_dsp_file(project_name);
   generate_real_live_dsp_file(project_name);
 
-  if (__gras_path)
-    xbt_free(__gras_path);
+  xbt_free(__gras_path);
 #endif
 
   free(warning);
index f734a41..e06b9f6 100644 (file)
@@ -189,14 +189,12 @@ void rctx_empty(rctx_t rc)
   char **env_it;
   void *filepos;
 
-  if (rc->cmd)
-    free(rc->cmd);
+  free(rc->cmd);
   rc->cmd = NULL;
   /* avoid race with rctx_armageddon log messages */
   filepos = rc->filepos;
   rc->filepos = NULL;
-  if (filepos)
-    free(filepos);
+  free(filepos);
   for (i = 0, env_it = environ; *env_it; i++, env_it++);
   if (rc->env) {
     for (env_it = rctx->env + i; *env_it; env_it++)
@@ -241,10 +239,8 @@ void rctx_free(rctx_t rctx)
   if (!rctx)
     return;
 
-  if (rctx->cmd)
-    free(rctx->cmd);
-  if (rctx->filepos)
-    free(rctx->filepos);
+  free(rctx->cmd);
+  free(rctx->filepos);
   if (rctx->env) {
     int i;
     char **env_it;
@@ -526,8 +522,7 @@ static void start_command(rctx_t rctx)
         xbt_dynar_t path = xbt_str_split(environ[i] + 5, ":");
 
         xbt_dynar_foreach(path, it, str) {
-          if (binary_name)
-            free(binary_name);
+          free(binary_name);
           binary_name = bprintf("%s/%s", str, args[0]);
           if (!stat(binary_name, &stat_buf)) {
             /* Found. */
@@ -811,10 +806,8 @@ void *rctx_wait(void *r)
     }
     rctx->expected_return = 0;
 
-    if (rctx->expected_signal) {
-      free(rctx->expected_signal);
-      rctx->expected_signal = NULL;
-    }
+    free(rctx->expected_signal);
+    rctx->expected_signal = NULL;
   }
 
   if ((errcode && errcode != 1) || rctx->interrupted) {
index b4659fc..f23c3be 100644 (file)
@@ -172,8 +172,7 @@ static void handle_suite(const char *filename, FILE * IN)
   rctx_free(rctx);
 
   /* Clear buffers */
-  if (line)
-    free(line);
+  free(line);
   xbt_strbuff_free(buff);
 
 }
index 787b3f9..cd41e18 100644 (file)
@@ -100,11 +100,9 @@ void Buffer_free(Buffer_t buffer)
   if (NULL == buffer)
     return;
 
-  if (NULL != buffer->data)
-    free(buffer->data);
+  free(buffer->data);
 
-  if (NULL != buffer)
-    free(buffer);
+  free(buffer);
 }
 
 /* 
index d2517ff..da18135 100644 (file)
@@ -209,8 +209,7 @@ void Stream_free(Stream_t ptr)
   if ((NULL != ptr->file) && (stdin != ptr->file))
     fclose(ptr->file);
 
-  if (NULL != ptr->line)
-    free(ptr->line);
+  free(ptr->line);
 
   DeleteCriticalSection(&cs);
 
@@ -483,8 +482,7 @@ void Stream_printLine(Stream_t stream, line_type_t line_type)
      */
   }
 
-  if (__date)
-    free(__date);
+  free(__date);
 
   Stream_unlock(stream);
 }
index 1682238..ed14c54 100644 (file)
@@ -253,9 +253,7 @@ void TestCaseContext_setName(TestCaseContext_t context, char *name)
 {
   size_t size;
 
-  if (NULL != context->name) {
-    free(context->name);
-  }
+  free(context->name);
 
   context->name = strdup(name);
   size = strlen(name);
index 73f7543..0691116 100644 (file)
@@ -241,10 +241,8 @@ void ThreadDynarray_clear(ThreadDynarray_t ptr)
 {
   ThreadDynarray_lock(ptr);
 
-  if (ptr->threads) {
-    free(ptr->threads);
-    ptr->threads = NULL;
-  }
+  free(ptr->threads);
+  ptr->threads = NULL;
 
   ptr->count = 0;
   ptr->capacity = 0;