Fix memory leak mysql result not freed

Trace:

==4142== 7,100,544 (73,920 direct, 7,026,624 indirect) bytes in 440 blocks are definitely lost in loss record 12,026 of 12,026
==4142==    at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==4142==    by 0x27F2E5B3: my_malloc (in /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18.0.0)
==4142==    by 0x27F11964: mysql_store_result (in /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18.0.0)
==4142==    by 0x295CF221: select_without_fetch (in /usr/lib/x86_64-linux-gnu/libmapistore.so.2.2)
==4142==    by 0x295CD987: mysql_record_get_uri (in /usr/lib/x86_64-linux-gnu/libmapistore.so.2.2)
==4142==    by 0x3512DBB4: _i_MAPIStoreMapping__urlFromID_ (in /usr/lib/GNUstep/SOGo/SOGoBackend.MAPIStore/SOGoBackend)
==4142==    by 0x3513908D: _i_MAPIStoreContext__getRootFolder_withFID_ (in /usr/lib/GNUstep/SOGo/SOGoBackend.MAPIStore/SOGoBackend)
==4142==    by 0x2AA1B534: sogo_context_get_root_folder (in /usr/lib/x86_64-linux-gnu/mapistore_backends/libMAPIStoreSOGo.so.1.0.0)
==4142==    by 0x295C41E4: mapistore_backend_create_context (in /usr/lib/x86_64-linux-gnu/libmapistore.so.2.2)
==4142==    by 0x295BBE39: mapistore_add_context (in /usr/lib/x86_64-linux-gnu/libmapistore.so.2.2)
==4142==    by 0x2905922F: emsmdbp_object_open_folder (in /usr/lib/x86_64-linux-gnu/openchange/dcerpc_mapiproxy_server/exchange_emsmdb.so)
==4142==    by 0x2907295A: oxcfxics_push_folderChange (in /usr/lib/x86_64-linux-gnu/openchange/dcerpc_mapiproxy_server/exchange_emsmdb.so)
==4142==    by 0x29072C25: oxcfxics_prepare_synccontext_with_folderChange (in /usr/lib/x86_64-linux-gnu/openchange/dcerpc_mapiproxy_server/exchange_emsmdb.so)
==4142==    by 0x290737D5: oxcfxics_fill_synccontext_fasttransfer_response (in /usr/lib/x86_64-linux-gnu/openchange/dcerpc_mapiproxy_server/exchange_emsmdb.so)
==4142==    by 0x29073BF5: EcDoRpc_RopFastTransferSourceGetBuffer (in /usr/lib/x86_64-linux-gnu/openchange/dcerpc_mapiproxy_server/exchange_emsmdb.so)
==4142==    by 0x29053EC8: EcDoRpc_process_transaction (in /usr/lib/x86_64-linux-gnu/openchange/dcerpc_mapiproxy_server/exchange_emsmdb.so)
==4142==    by 0x290563C7: dcesrv_EcDoRpcExt2 (in /usr/lib/x86_64-linux-gnu/openchange/dcerpc_mapiproxy_server/exchange_emsmdb.so)
==4142==    by 0x2905689A: dcesrv_exchange_emsmdb_dispatch (in /usr/lib/x86_64-linux-gnu/openchange/dcerpc_mapiproxy_server/exchange_emsmdb.so)
==4142==    by 0x278C9E23: mapiproxy_server_dispatch (in /usr/lib/x86_64-linux-gnu/libmapiproxy.so.2.2)
==4142==    by 0x268D7213: mapiproxy_op_dispatch (in /usr/lib/x86_64-linux-gnu/samba/dcerpc_server/dcesrv_mapiproxy.so)
==4142==    by 0x16267BAF: dcesrv_process_ncacn_packet (in /usr/lib/x86_64-linux-gnu/libdcerpc-server.so.0.0.1)
==4142==    by 0x16268980: dcesrv_read_fragment_done (in /usr/lib/x86_64-linux-gnu/libdcerpc-server.so.0.0.1)
==4142==    by 0x809ECB6: dcerpc_read_ncacn_packet_done (in /usr/lib/x86_64-linux-gnu/libdcerpc-binding.so.0.0.1)
==4142==    by 0xB5137C8: tstream_readv_pdu_readv_done (in /usr/lib/x86_64-linux-gnu/samba/libsamba-sockets.so.0)
==4142==    by 0xB5126A5: tstream_readv_done (in /usr/lib/x86_64-linux-gnu/samba/libsamba-sockets.so.0)
==4142==    by 0x8B04E13: tevent_common_loop_immediate (in /usr/lib/x86_64-linux-gnu/libtevent.so.0.9.19)
==4142==    by 0x8B09436: epoll_event_loop_once (in /usr/lib/x86_64-linux-gnu/libtevent.so.0.9.19)
==4142==    by 0x8B07B26: std_event_loop_once (in /usr/lib/x86_64-linux-gnu/libtevent.so.0.9.19)
==4142==    by 0x8B045EC: _tevent_loop_once (in /usr/lib/x86_64-linux-gnu/libtevent.so.0.9.19)
==4142==    by 0x8B0478A: tevent_common_loop_wait (in /usr/lib/x86_64-linux-gnu/libtevent.so.0.9.19)
==4142==    by 0x8B07AC6: std_event_loop_wait (in /usr/lib/x86_64-linux-gnu/libtevent.so.0.9.19)
==4142==    by 0x11DF4685: standard_new_task (in /usr/lib/x86_64-linux-gnu/samba/process_model/standard.so)
==4142==    by 0x5D10EF9: task_server_startup (in /usr/lib/x86_64-linux-gnu/samba/libservice.so.0)
==4142==    by 0x5D0FBA2: server_service_startup (in /usr/lib/x86_64-linux-gnu/samba/libservice.so.0)
==4142==    by 0x111A54: binary_smbd_main.constprop.1 (in /usr/sbin/samba)
==4142==    by 0x8D2FEC4: (below main) (libc-start.c:287)
Fix memory leak in mapistore_backend_get_path

Trace:

==26758== 23,518 bytes in 175 blocks are definitely lost in loss record 9,688 of 9,930
==26758==    at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==26758==    by 0x86EDE3D: talloc_strndup (talloc.c:613)
==26758==    by 0x34D2BB9E: _i_NSString_MAPIStoreDataTypes_asUnicodeInMemCtx_ (in /usr/lib/GNUstep/SOGo/SOGoBackend.MAPIStore/SOGoBackend)
==26758==    by 0x34CF1F12: _i_MAPIStoreContext__getPath_ofFMID_inMemCtx_ (in /usr/lib/GNUstep/SOGo/SOGoBackend.MAPIStore/SOGoBackend)
==26758==    by 0x2A5D4325: sogo_context_get_path (in /usr/lib/x86_64-linux-gnu/mapistore_backends/libMAPIStoreSOGo.so.1.0.0)
==26758==    by 0x2917D582: mapistore_backend_get_path (in /usr/lib/x86_64-linux-gnu/libmapistore.so.2.2)
==26758==    by 0x2917FECE: mapistore_indexing_record_add_fmid (in /usr/lib/x86_64-linux-gnu/libmapistore.so.2.2)
==26758==    by 0x29180297: mapistore_indexing_record_add_fid (in /usr/lib/x86_64-linux-gnu/libmapistore.so.2.2)
==26758==    by 0x28C12281: emsmdbp_object_open_folder (in /usr/lib/x86_64-linux-gnu/openchange/dcerpc_mapiproxy_server/exchange_emsmdb.so)
==26758==    by 0x28C2B95A: oxcfxics_push_folderChange (in /usr/lib/x86_64-linux-gnu/openchange/dcerpc_mapiproxy_server/exchange_emsmdb.so)
==26758==    by 0x28C2BC25: oxcfxics_prepare_synccontext_with_folderChange (in /usr/lib/x86_64-linux-gnu/openchange/dcerpc_mapiproxy_server/exchange_emsmdb.so)
==26758==    by 0x28C2C7D5: oxcfxics_fill_synccontext_fasttransfer_response (in /usr/lib/x86_64-linux-gnu/openchange/dcerpc_mapiproxy_server/exchange_emsmdb.so)
==26758==    by 0x28C2CBF5: EcDoRpc_RopFastTransferSourceGetBuffer (in /usr/lib/x86_64-linux-gnu/openchange/dcerpc_mapiproxy_server/exchange_emsmdb.so)
==26758==    by 0x28C0CEC8: EcDoRpc_process_transaction (in /usr/lib/x86_64-linux-gnu/openchange/dcerpc_mapiproxy_server/exchange_emsmdb.so)
==26758==    by 0x28C0F3C7: dcesrv_EcDoRpcExt2 (in /usr/lib/x86_64-linux-gnu/openchange/dcerpc_mapiproxy_server/exchange_emsmdb.so)
==26758==    by 0x28C0F89A: dcesrv_exchange_emsmdb_dispatch (in /usr/lib/x86_64-linux-gnu/openchange/dcerpc_mapiproxy_server/exchange_emsmdb.so)
==26758==    by 0x26BF8E23: mapiproxy_server_dispatch (in /usr/lib/x86_64-linux-gnu/libmapiproxy.so.2.2)
==26758==    by 0x268D7213: mapiproxy_op_dispatch (in /usr/lib/x86_64-linux-gnu/samba/dcerpc_server/dcesrv_mapiproxy.so)
==26758==    by 0x16267BAF: dcesrv_process_ncacn_packet (in /usr/lib/x86_64-linux-gnu/libdcerpc-server.so.0.0.1)
==26758==    by 0x16268980: dcesrv_read_fragment_done (in /usr/lib/x86_64-linux-gnu/libdcerpc-server.so.0.0.1)
==26758==    by 0x809ECB6: dcerpc_read_ncacn_packet_done (in /usr/lib/x86_64-linux-gnu/libdcerpc-binding.so.0.0.1)
==26758==    by 0xB5137C8: tstream_readv_pdu_readv_done (in /usr/lib/x86_64-linux-gnu/samba/libsamba-sockets.so.0)
==26758==    by 0xB5126A5: tstream_readv_done (in /usr/lib/x86_64-linux-gnu/samba/libsamba-sockets.so.0)
==26758==    by 0x8B04E13: tevent_common_loop_immediate (in /usr/lib/x86_64-linux-gnu/libtevent.so.0.9.19)
==26758==    by 0x8B09436: epoll_event_loop_once (in /usr/lib/x86_64-linux-gnu/libtevent.so.0.9.19)
==26758==    by 0x8B07B26: std_event_loop_once (in /usr/lib/x86_64-linux-gnu/libtevent.so.0.9.19)
==26758==    by 0x8B045EC: _tevent_loop_once (in /usr/lib/x86_64-linux-gnu/libtevent.so.0.9.19)
==26758==    by 0x8B0478A: tevent_common_loop_wait (in /usr/lib/x86_64-linux-gnu/libtevent.so.0.9.19)
==26758==    by 0x8B07AC6: std_event_loop_wait (in /usr/lib/x86_64-linux-gnu/libtevent.so.0.9.19)
==26758==    by 0x11DF4685: standard_new_task (in /usr/lib/x86_64-linux-gnu/samba/process_model/standard.so)
==26758==    by 0x5D10EF9: task_server_startup (in /usr/lib/x86_64-linux-gnu/samba/libservice.so.0)
==26758==    by 0x5D0FBA2: server_service_startup (in /usr/lib/x86_64-linux-gnu/samba/libservice.so.0)
==26758==    by 0x111A54: binary_smbd_main.constprop.1 (in /usr/sbin/samba)
==26758==    by 0x8D2FEC4: (below main) (libc-start.c:287)
Ensure mysql result pointer is valid only when returning MYSQL_SUCCESS
removed unnecessary null check conditions to free pointers
Fix memory leak in mapistore_indexing_record_add_fmid

leak when type was invalid parameter
talloc_named -> talloc_new
Merge pull request #140 from Zentyal/scabrero/fix-memory-leaks

Scabrero/fix memory leaks