diff --git a/client/mysqltest.cc b/client/mysqltest.cc
index d0c948e67bb..0312a0a030b 100644
--- a/client/mysqltest.cc
+++ b/client/mysqltest.cc
@@ -87,7 +87,7 @@ enum {
   OPT_SKIP_SAFEMALLOC=OPT_MAX_CLIENT_OPTION,
   OPT_PS_PROTOCOL, OPT_SP_PROTOCOL, OPT_CURSOR_PROTOCOL, OPT_VIEW_PROTOCOL,
   OPT_MAX_CONNECT_RETRIES, OPT_MAX_CONNECTIONS, OPT_MARK_PROGRESS,
-  OPT_LOG_DIR, OPT_TAIL_LINES, OPT_RESULT_FORMAT_VERSION, 
+  OPT_LOG_DIR, OPT_TAIL_LINES, OPT_RESULT_FORMAT_VERSION
 };
 
 static int record= 0, opt_sleep= -1;
diff --git a/include/my_alloc.h b/include/my_alloc.h
index dbf104bda9a..4b1ffd3d444 100644
--- a/include/my_alloc.h
+++ b/include/my_alloc.h
@@ -23,7 +23,9 @@
 #define ALLOC_MAX_BLOCK_TO_DROP			4096
 #define ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP	10
 
-C_MODE_START
+#ifdef __cplusplus
+extern "C" {
+#endif
 
 typedef struct st_used_mem
 {				   /* struct for once_alloc (block) */
@@ -51,6 +53,8 @@ typedef struct st_mem_root
   void (*error_handler)(void);
 } MEM_ROOT;
 
-C_MODE_END
+#ifdef  __cplusplus
+}
+#endif
 
 #endif
diff --git a/include/mysql.h.pp b/include/mysql.h.pp
index 9c1d8adcd2f..4fef9e9ec0b 100644
--- a/include/mysql.h.pp
+++ b/include/mysql.h.pp
@@ -202,7 +202,6 @@ typedef unsigned int MYSQL_FIELD_OFFSET;
 typedef unsigned long long my_ulonglong;
 #include "typelib.h"
 #include "my_alloc.h"
-C_MODE_START
 typedef struct st_used_mem
 {
   struct st_used_mem *next;
@@ -220,7 +219,6 @@ typedef struct st_mem_root
   unsigned int first_block_usage;
   void (*error_handler)(void);
 } MEM_ROOT;
-C_MODE_END
 typedef struct st_typelib {
   unsigned int count;
   const char *name;
diff --git a/plugin/semisync/semisync_master.h b/plugin/semisync/semisync_master.h
index e1ad28cd9f6..1a562e8bb77 100644
--- a/plugin/semisync/semisync_master.h
+++ b/plugin/semisync/semisync_master.h
@@ -153,7 +153,7 @@ public:
   int free_nodes_before(TranxNode* node)
   {
     Block *block;
-    Block *prev_block;
+    Block *prev_block= NULL;
 
     block= first_block;
     while (block != current_block->next)
diff --git a/sql/debug_sync.cc b/sql/debug_sync.cc
index d16fa4b2468..dde6267331f 100644
--- a/sql/debug_sync.cc
+++ b/sql/debug_sync.cc
@@ -387,6 +387,13 @@ static st_debug_sync_globals debug_sync_global; /* All globals in one object */
 */
 extern "C" void (*debug_sync_C_callback_ptr)(const char *, size_t);
 
+/**
+  Callbacks from C files.
+*/
+C_MODE_START
+static void debug_sync_C_callback(const char *, size_t);
+static int debug_sync_qsort_cmp(const void *, const void *);
+C_MODE_END
 
 /**
   Callback for debug sync, to be used by C files. See thr_lock.c for example.
@@ -422,8 +429,8 @@ extern "C" void (*debug_sync_C_callback_ptr)(const char *, size_t);
 static void debug_sync_C_callback(const char *sync_point_name,
                                   size_t name_len)
 {
-  if (unlikely(opt_debug_sync_timeout))                            
-    debug_sync(current_thd, sync_point_name, name_len);   
+  if (unlikely(opt_debug_sync_timeout))
+    debug_sync(current_thd, sync_point_name, name_len);
 }
 
 #ifdef HAVE_PSI_INTERFACE