[patch] Add kvm_close in mib_hrsystemprocs function

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[patch] Add kvm_close in mib_hrsystemprocs function

Nan Xiao-2
Hi tech@,

Maybe kvm_close is needed if kvm_getprocs returns NULL here? Sorry if I
am wrong, thanks!

Index: mib.c
===================================================================
RCS file: /cvs/src/usr.sbin/snmpd/mib.c,v
retrieving revision 1.87
diff -u -p -r1.87 mib.c
--- mib.c 25 May 2018 08:23:15 -0000 1.87
+++ mib.c 30 May 2018 08:15:19 -0000
@@ -516,8 +516,10 @@ mib_hrsystemprocs(struct oid *oid, struc
  return (-1);

  if (kvm_getprocs(kd, KERN_PROC_ALL, 0,
-    sizeof(struct kinfo_proc), &val) == NULL)
+    sizeof(struct kinfo_proc), &val) == NULL) {
+ kvm_close(kd);
  return (-1);
+ }

  *elm = ber_add_integer(*elm, val);
  ber_set_header(*elm, BER_CLASS_APPLICATION, SNMP_T_GAUGE32);

--
Best Regards
Nan Xiao

Reply | Threaded
Open this post in threaded view
|

Re: [patch] Add kvm_close in mib_hrsystemprocs function

Gerhard Roth-2
On Wed, 30 May 2018 16:25:55 +0800 Nan Xiao <[hidden email]> wrote:

> Hi tech@,
>
> Maybe kvm_close is needed if kvm_getprocs returns NULL here? Sorry if I
> am wrong, thanks!
>
> Index: mib.c
> ===================================================================
> RCS file: /cvs/src/usr.sbin/snmpd/mib.c,v
> retrieving revision 1.87
> diff -u -p -r1.87 mib.c
> --- mib.c 25 May 2018 08:23:15 -0000 1.87
> +++ mib.c 30 May 2018 08:15:19 -0000
> @@ -516,8 +516,10 @@ mib_hrsystemprocs(struct oid *oid, struc
>   return (-1);
>
>   if (kvm_getprocs(kd, KERN_PROC_ALL, 0,
> -    sizeof(struct kinfo_proc), &val) == NULL)
> +    sizeof(struct kinfo_proc), &val) == NULL) {
> + kvm_close(kd);
>   return (-1);
> + }
>
>   *elm = ber_add_integer(*elm, val);
>   ber_set_header(*elm, BER_CLASS_APPLICATION, SNMP_T_GAUGE32);
>


Looks reasonable.

Reply | Threaded
Open this post in threaded view
|

Re: [patch] Add kvm_close in mib_hrsystemprocs function

Nan Xiao-2
Hi Gerhard,

Thanks for your reply!

Yes, if no "kvm_close(kd);", there will be resource (memory, file
descriptor) leak. So hope you can commit it, thanks!


On 5/30/2018 4:49 PM, Gerhard Roth wrote:

> On Wed, 30 May 2018 16:25:55 +0800 Nan Xiao <[hidden email]> wrote:
>> Hi tech@,
>>
>> Maybe kvm_close is needed if kvm_getprocs returns NULL here? Sorry if I
>> am wrong, thanks!
>>
>> Index: mib.c
>> ===================================================================
>> RCS file: /cvs/src/usr.sbin/snmpd/mib.c,v
>> retrieving revision 1.87
>> diff -u -p -r1.87 mib.c
>> --- mib.c 25 May 2018 08:23:15 -0000 1.87
>> +++ mib.c 30 May 2018 08:15:19 -0000
>> @@ -516,8 +516,10 @@ mib_hrsystemprocs(struct oid *oid, struc
>>   return (-1);
>>
>>   if (kvm_getprocs(kd, KERN_PROC_ALL, 0,
>> -    sizeof(struct kinfo_proc), &val) == NULL)
>> +    sizeof(struct kinfo_proc), &val) == NULL) {
>> + kvm_close(kd);
>>   return (-1);
>> + }
>>
>>   *elm = ber_add_integer(*elm, val);
>>   ber_set_header(*elm, BER_CLASS_APPLICATION, SNMP_T_GAUGE32);
>>
>
>
> Looks reasonable.
>

--
Best Regards
Nan Xiao

Reply | Threaded
Open this post in threaded view
|

Re: [patch] Add kvm_close in mib_hrsystemprocs function

Gerhard Roth-2
On Thu, 31 May 2018 17:40:36 +0800 Nan Xiao <[hidden email]> wrote:

> Hi Gerhard,
>
> Thanks for your reply!
>
> Yes, if no "kvm_close(kd);", there will be resource (memory, file
> descriptor) leak. So hope you can commit it, thanks!
>
>
> On 5/30/2018 4:49 PM, Gerhard Roth wrote:
> > On Wed, 30 May 2018 16:25:55 +0800 Nan Xiao <[hidden email]> wrote:  
> >> Hi tech@,
> >>
> >> Maybe kvm_close is needed if kvm_getprocs returns NULL here? Sorry if I
> >> am wrong, thanks!
> >>
> >> Index: mib.c
> >> ===================================================================
> >> RCS file: /cvs/src/usr.sbin/snmpd/mib.c,v
> >> retrieving revision 1.87
> >> diff -u -p -r1.87 mib.c
> >> --- mib.c 25 May 2018 08:23:15 -0000 1.87
> >> +++ mib.c 30 May 2018 08:15:19 -0000
> >> @@ -516,8 +516,10 @@ mib_hrsystemprocs(struct oid *oid, struc
> >>   return (-1);
> >>
> >>   if (kvm_getprocs(kd, KERN_PROC_ALL, 0,
> >> -    sizeof(struct kinfo_proc), &val) == NULL)
> >> +    sizeof(struct kinfo_proc), &val) == NULL) {
> >> + kvm_close(kd);
> >>   return (-1);
> >> + }
> >>
> >>   *elm = ber_add_integer(*elm, val);
> >>   ber_set_header(*elm, BER_CLASS_APPLICATION, SNMP_T_GAUGE32);
> >>  
> >
> >
> > Looks reasonable.
> >  
>


Reluctant to commit code with my own ok. Anybody else willing to
give an ok?

Gerhard

Reply | Threaded
Open this post in threaded view
|

Re: [patch] Add kvm_close in mib_hrsystemprocs function

Jeremie Courreges-Anglas-2
On Mon, Jun 04 2018, Gerhard Roth <[hidden email]> wrote:

> On Thu, 31 May 2018 17:40:36 +0800 Nan Xiao <[hidden email]> wrote:
>> Hi Gerhard,
>>
>> Thanks for your reply!
>>
>> Yes, if no "kvm_close(kd);", there will be resource (memory, file
>> descriptor) leak. So hope you can commit it, thanks!
>>
>>
>> On 5/30/2018 4:49 PM, Gerhard Roth wrote:
>> > On Wed, 30 May 2018 16:25:55 +0800 Nan Xiao <[hidden email]> wrote:  
>> >> Hi tech@,
>> >>
>> >> Maybe kvm_close is needed if kvm_getprocs returns NULL here? Sorry if I
>> >> am wrong, thanks!
>> >>
>> >> Index: mib.c
>> >> ===================================================================
>> >> RCS file: /cvs/src/usr.sbin/snmpd/mib.c,v
>> >> retrieving revision 1.87
>> >> diff -u -p -r1.87 mib.c
>> >> --- mib.c 25 May 2018 08:23:15 -0000 1.87
>> >> +++ mib.c 30 May 2018 08:15:19 -0000
>> >> @@ -516,8 +516,10 @@ mib_hrsystemprocs(struct oid *oid, struc
>> >>   return (-1);
>> >>
>> >>   if (kvm_getprocs(kd, KERN_PROC_ALL, 0,
>> >> -    sizeof(struct kinfo_proc), &val) == NULL)
>> >> +    sizeof(struct kinfo_proc), &val) == NULL) {
>> >> + kvm_close(kd);
>> >>   return (-1);
>> >> + }
>> >>
>> >>   *elm = ber_add_integer(*elm, val);
>> >>   ber_set_header(*elm, BER_CLASS_APPLICATION, SNMP_T_GAUGE32);
>> >>  
>> >
>> >
>> > Looks reasonable.
>> >  
>>
>
>
> Reluctant to commit code with my own ok. Anybody else willing to
> give an ok?

ok jca@

--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE