| 1 |
commit 98e07c497c9d866c0342696918a020b3f0303405 |
| 2 |
Author: Samuel Thibault <[email protected]> |
| 3 |
Date: Sun Jul 14 18:14:35 2024 +0200 |
| 4 |
|
| 5 |
server: Fix bogus port deallocation on server error |
| 6 |
|
| 7 |
For inlined port arrays, WriteExtractArg compacts them from a |
| 8 |
mach_port_name_inlined_t array to a mach_port_t array, reusing the |
| 9 |
memory area. But when the server returns an error, the caller will |
| 10 |
destroy the message, and thus expects the original inlined port arrays |
| 11 |
available. |
| 12 |
|
| 13 |
diff --git a/server.c b/server.c |
| 14 |
index 81147b5..e02e1e7 100644 |
| 15 |
--- a/server.c |
| 16 |
+++ b/server.c |
| 17 |
@@ -788,6 +788,27 @@ WriteExtractArg(FILE *file, const argument_t *arg) |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
+static void |
| 22 |
+WriteRestoreArg(FILE *file, const argument_t *arg) |
| 23 |
+{ |
| 24 |
+ if (akCheckAll(arg->argKind, akbSendRcv|akbPointer)) { |
| 25 |
+ if (akCheck(arg->argKind, akbIndefinite)) { |
| 26 |
+ fprintf(file, "\tif (OutP->%s != KERN_SUCCESS && In%dP->%s%s.msgt_inline) {\n", |
| 27 |
+ arg->argRoutine->rtRetCode->argMsgField, |
| 28 |
+ arg->argRequestPos, arg->argTTName, arg->argLongForm ? ".msgtl_header" : ""); |
| 29 |
+ fprintf(file, "\t\tmach_msg_type_number_t i;\n"); |
| 30 |
+ fprintf(file, "\t\t/* Restore the mach_port_name_inlined_t input array for message destruction. */\n"); |
| 31 |
+ fprintf(file, "\t\tfor (i = In%dP->%s.msgt%s_number; i > 1; i--) {\n", |
| 32 |
+ arg->argRequestPos, arg->argTTName, arg->argLongForm ? "l" : ""); |
| 33 |
+ fprintf(file, "\t\t\t%s[i-1].name = %sP[i-1];\n", InArgMsgField(arg), arg->argVarName); |
| 34 |
+ fprintf(file, "\t\t}\n"); |
| 35 |
+ fprintf(file, "\t}\n"); |
| 36 |
+ } |
| 37 |
+ else |
| 38 |
+ assert(false); |
| 39 |
+ } |
| 40 |
+} |
| 41 |
+ |
| 42 |
static void |
| 43 |
WriteServerCallArg(FILE *file, const argument_t *arg) |
| 44 |
{ |
| 45 |
@@ -1435,6 +1456,8 @@ WriteRoutine(FILE *file, const routine_t *rt) |
| 46 |
WriteServerCall(file, rt); |
| 47 |
WriteGetReturnValue(file, rt); |
| 48 |
|
| 49 |
+ WriteReverseList(file, rt->rtArgs, WriteRestoreArg, akbNone, "", ""); |
| 50 |
+ |
| 51 |
WriteReverseList(file, rt->rtArgs, WriteDestroyArg, akbDestroy, "", ""); |
| 52 |
|
| 53 |
/* |