ref: 2269c807384bc6a79b23162896246f661c738400
parent: d5e2fd9028687dfc18c0ac1b249ccec38ab075f6
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Fri Jun 23 21:25:22 EDT 2023
snoopy: fix error handling for convM2DNS()
--- a/sys/src/cmd/ip/snoopy/dns.c
+++ b/sys/src/cmd/ip/snoopy/dns.c
@@ -181,6 +181,7 @@
static Proto dnsqd, dnsan, dnsns, dnsar;
static void donext(Msg*);
+static void dolast(Msg*);
static DNSmsg dm;
static int
@@ -190,6 +191,8 @@
if((e = convM2DNS(m->ps, m->pe-m->ps, &dm, nil)) != nil){
m->p = seprint(m->p, m->e, "error: %s", e);
+ free(e);
+ dolast(m);
return 0;
}
m->p = seprint(m->p, m->e, "id=%d flags=%#ux", dm.id, dm.flags);
@@ -208,11 +211,16 @@
m->pr = &dnsns;
else if(dm.ar)
m->pr = &dnsar;
- else{
- freealldn();
- memset(&dm, 0, sizeof dm);
- m->pr = nil;
- }
+ else
+ dolast(m);
+}
+
+static void
+dolast(Msg *m)
+{
+ freealldn();
+ memset(&dm, 0, sizeof dm);
+ m->pr = nil;
}
static int