Line data Source code
1 : /* 2 : * Unix SMB/CIFS implementation. 3 : * 4 : * This program is free software; you can redistribute it and/or modify 5 : * it under the terms of the GNU General Public License as published by 6 : * the Free Software Foundation; either version 3 of the License, or 7 : * (at your option) any later version. 8 : * 9 : * This program is distributed in the hope that it will be useful, 10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 : * GNU General Public License for more details. 13 : * 14 : * You should have received a copy of the GNU General Public License 15 : * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 : */ 17 : 18 : #include "replace.h" 19 : #include <assert.h> 20 : #include "source3/lib/background.h" 21 : #include "source3/include/messages.h" 22 : #include "lib/util/talloc_stack.h" 23 : #include "source3/param/loadparm.h" 24 : #include "dynconfig/dynconfig.h" 25 : 26 0 : static int bg_trigger(void *private_data) 27 : { 28 0 : return 1; 29 : } 30 : 31 1 : static void test_background_send(void) 32 : { 33 1 : TALLOC_CTX *frame = talloc_stackframe(); 34 1 : struct tevent_context *ev = NULL; 35 1 : struct messaging_context *msg_ctx = NULL; 36 1 : struct tevent_req *req = NULL; 37 1 : uint32_t ping_msg = MSG_PING; 38 : 39 1 : ev = tevent_context_init(frame); 40 1 : assert(ev != NULL); 41 : 42 1 : msg_ctx = messaging_init(frame, ev); 43 1 : assert(msg_ctx != NULL); 44 : 45 1 : req = background_job_send( 46 : frame, ev, msg_ctx, &ping_msg, 1, 0, bg_trigger, NULL); 47 1 : assert(req != NULL); 48 : 49 : /* 50 : * Here's the core of this test: TALLOC_FREE msg_ctx before 51 : * req. This happens if you use background_job_send() smbd and 52 : * don't manually TALLOC_FREE req before exit_server() 53 : */ 54 1 : TALLOC_FREE(msg_ctx); 55 1 : TALLOC_FREE(req); 56 : 57 1 : TALLOC_FREE(frame); 58 1 : } 59 : 60 1 : int main(int argc, const char *argv[]) 61 : { 62 1 : const char testname[] = "test_background_send"; 63 1 : bool ok; 64 : 65 1 : if (argc != 2) { 66 0 : fprintf(stderr, "usage: %s <configfile>\n", argv[0]); 67 0 : return 1; 68 : } 69 : 70 1 : printf("test: %s\n", testname); 71 : 72 1 : ok = lp_load_initial_only(argv[1]); 73 1 : if (!ok) { 74 0 : fprintf(stderr, "lp_load_initial_only(%s) failed\n", argv[1]); 75 0 : return 1; 76 : } 77 : 78 1 : test_background_send(); /* crashes on failure */ 79 : 80 1 : printf("success: %s\n", testname); 81 1 : return 0; 82 : }